diff --git a/tests/std/test.lst b/tests/std/test.lst index 35f241e3686..0e60c21053b 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -165,6 +165,7 @@ tests\GH_000940_missing_valarray_copy tests\GH_001010_filesystem_error_encoding tests\GH_001017_discrete_distribution_out_of_range tests\GH_001086_partial_sort_copy +tests\GH_001103_countl_zero_correctness tests\LWG2597_complex_branch_cut tests\LWG3018_shared_ptr_function tests\P0019R8_atomic_ref diff --git a/tests/std/tests/GH_001103_countl_zero_correctness/env.lst b/tests/std/tests/GH_001103_countl_zero_correctness/env.lst new file mode 100644 index 00000000000..642f530ffad --- /dev/null +++ b/tests/std/tests/GH_001103_countl_zero_correctness/env.lst @@ -0,0 +1,4 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +RUNALL_INCLUDE ..\usual_latest_matrix.lst diff --git a/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp b/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp new file mode 100644 index 00000000000..e7d2d923609 --- /dev/null +++ b/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include +#include + +// Indirectly test countl_zero on old x86/x64 processors by testing a private helper, +// which is different from the usual branch. + +// Currently need this test only in C++20 mode; +// may update to older C++ if the helper is used internally too, for example in . + +using namespace std; + +int main() { + // This test is applicable only to x86 and x64 platforms +#if defined(_M_IX86) || defined(_M_X64) + assert(_Countl_zero_bsr(static_cast(0x00)) == 8); + assert(_Countl_zero_bsr(static_cast(0x13)) == 3); + assert(_Countl_zero_bsr(static_cast(0x83)) == 0); + assert(_Countl_zero_bsr(static_cast(0xF8)) == 0); + + assert(_Countl_zero_bsr(static_cast(0x0000)) == 16); + assert(_Countl_zero_bsr(static_cast(0x0013)) == 11); + assert(_Countl_zero_bsr(static_cast(0x8003)) == 0); + assert(_Countl_zero_bsr(static_cast(0xF008)) == 0); + + assert(_Countl_zero_bsr(static_cast(0x0000'0000)) == 32); + assert(_Countl_zero_bsr(static_cast(0x0000'0013)) == 27); + assert(_Countl_zero_bsr(static_cast(0x8000'0003)) == 0); + assert(_Countl_zero_bsr(static_cast(0xF000'0008)) == 0); + + assert(_Countl_zero_bsr(static_cast(0x0000'0000)) == 32); + assert(_Countl_zero_bsr(static_cast(0x0000'0013)) == 27); + assert(_Countl_zero_bsr(static_cast(0x8000'0003)) == 0); + assert(_Countl_zero_bsr(static_cast(0xF000'0008)) == 0); + + assert(_Countl_zero_bsr(static_cast(0x0000'0000'0000'0000)) == 64); + assert(_Countl_zero_bsr(static_cast(0x0000'0000'0000'0013)) == 59); + assert(_Countl_zero_bsr(static_cast(0x8000'0000'0000'0003)) == 0); + assert(_Countl_zero_bsr(static_cast(0xF000'0000'0000'0008)) == 0); +#endif // ^^^ defined(_M_IX86) || defined(_M_X64) ^^^ +}