From 602017f9dac19ff03fa0a3750aa939b8c68481f1 Mon Sep 17 00:00:00 2001 From: Alex Guteniev Date: Sat, 8 Aug 2020 19:50:45 +0300 Subject: [PATCH 01/11] Resolves #1120 --- tests/std/test.lst | 1 + .../GH_001103_countl_zero_correctness/env.lst | 4 ++ .../test.cpp | 44 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 tests/std/tests/GH_001103_countl_zero_correctness/env.lst create mode 100644 tests/std/tests/GH_001103_countl_zero_correctness/test.cpp diff --git a/tests/std/test.lst b/tests/std/test.lst index 70f23e250c2..4ff7b5dc2e9 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -164,6 +164,7 @@ tests\GH_000890_pow_template tests\GH_000940_missing_valarray_copy tests\GH_001010_filesystem_error_encoding tests\GH_001017_discrete_distribution_out_of_range +tests\GH_001103_countl_zero_correctness tests\LWG2597_complex_branch_cut tests\LWG3018_shared_ptr_function tests\P0024R2_parallel_algorithms_adjacent_difference 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..1609d372582 --- /dev/null +++ b/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp @@ -0,0 +1,44 @@ +// 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 private hepler, +// which is different from the usual branch. + +// Since the fallback intrinsic is available on ARM too, don't need to exclude ARM + +// Currently need to test not only in C++20 mode, +// May update to loder C++ if the helper is used internally too, for example in + +using namespace std; + +int main() { + 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)) == 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'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); + + return 0; +} From 54676243e551687ba7553095a56836635e7a0f91 Mon Sep 17 00:00:00 2001 From: Alex Guteniev Date: Sat, 8 Aug 2020 19:52:44 +0300 Subject: [PATCH 02/11] spell --- tests/std/tests/GH_001103_countl_zero_correctness/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp b/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp index 1609d372582..5193ce474af 100644 --- a/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp +++ b/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp @@ -10,7 +10,7 @@ // Since the fallback intrinsic is available on ARM too, don't need to exclude ARM // Currently need to test not only in C++20 mode, -// May update to loder C++ if the helper is used internally too, for example in +// May update to older C++ if the helper is used internally too, for example in using namespace std; From 84020e65a63767bf7c050ac55550e4ebbec14c95 Mon Sep 17 00:00:00 2001 From: Alex Guteniev Date: Sat, 8 Aug 2020 19:56:10 +0300 Subject: [PATCH 03/11] clang format --- tests/std/tests/GH_001103_countl_zero_correctness/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp b/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp index 5193ce474af..d0a2bda0324 100644 --- a/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp +++ b/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#include #include +#include // Indirectly test countl_zero on old x86/x64 processors by testing private hepler, // which is different from the usual branch. From 6c302169e5cb0aa3eef69bb9e7aaed5a771ce4a2 Mon Sep 17 00:00:00 2001 From: Alex Guteniev Date: Sun, 9 Aug 2020 08:46:59 +0300 Subject: [PATCH 04/11] -dups +char --- .../tests/GH_001103_countl_zero_correctness/test.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp b/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp index d0a2bda0324..5893c8733f2 100644 --- a/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp +++ b/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp @@ -15,6 +15,13 @@ using namespace std; int main() { +#ifdef _CHAR_UNSIGNED + 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); +#endif + assert(_Countl_zero_bsr(static_cast(0x00)) == 8); assert(_Countl_zero_bsr(static_cast(0x13)) == 3); assert(_Countl_zero_bsr(static_cast(0x83)) == 0); @@ -25,11 +32,6 @@ int main() { assert(_Countl_zero_bsr(static_cast(0x8003)) == 0); assert(_Countl_zero_bsr(static_cast(0xF008)) == 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); From 3b6ee6d81590c6d6979f190922c387c638163572 Mon Sep 17 00:00:00 2001 From: Alex Guteniev Date: Sun, 9 Aug 2020 08:47:56 +0300 Subject: [PATCH 05/11] +int --- tests/std/tests/GH_001103_countl_zero_correctness/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp b/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp index 5893c8733f2..61cd7a4a315 100644 --- a/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp +++ b/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp @@ -32,6 +32,11 @@ int main() { 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); From 430dfc3c475b40cc2b0a02def2207530a2a461bc Mon Sep 17 00:00:00 2001 From: Alex Guteniev Date: Sun, 9 Aug 2020 08:59:09 +0300 Subject: [PATCH 06/11] "not only just everyone" --- tests/std/tests/GH_001103_countl_zero_correctness/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp b/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp index 61cd7a4a315..2ade4e74994 100644 --- a/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp +++ b/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp @@ -9,7 +9,7 @@ // Since the fallback intrinsic is available on ARM too, don't need to exclude ARM -// Currently need to test not only in C++20 mode, +// 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; From 71173c1621e964e5e547b2bc8d993d6545084959 Mon Sep 17 00:00:00 2001 From: Alex Guteniev Date: Sat, 15 Aug 2020 14:47:10 +0300 Subject: [PATCH 07/11] Apply suggestions from code review STL suggestions Co-authored-by: Stephan T. Lavavej --- .../GH_001103_countl_zero_correctness/test.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp b/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp index 2ade4e74994..613f267fb17 100644 --- a/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp +++ b/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp @@ -4,13 +4,13 @@ #include #include -// Indirectly test countl_zero on old x86/x64 processors by testing private hepler, +// Indirectly test countl_zero on old x86/x64 processors by testing a private helper, // which is different from the usual branch. // Since the fallback intrinsic is available on ARM too, don't need to exclude ARM -// Currently need this test only in C++20 mode, -// May update to older C++ if the helper is used internally too, for example in +// 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; @@ -32,10 +32,10 @@ int main() { 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)) == 32); assert(_Countl_zero_bsr(static_cast(0x0000'0013)) == 27); From c540f8e41a67f169bb660a21ac073cb21da9c374 Mon Sep 17 00:00:00 2001 From: Alex Guteniev Date: Sat, 15 Aug 2020 14:52:53 +0300 Subject: [PATCH 08/11] char is not unsigned integer, ARM is not x86 --- .../GH_001103_countl_zero_correctness/test.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp b/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp index 613f267fb17..c0ebed18cc6 100644 --- a/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp +++ b/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp @@ -7,21 +7,14 @@ // Indirectly test countl_zero on old x86/x64 processors by testing a private helper, // which is different from the usual branch. -// Since the fallback intrinsic is available on ARM too, don't need to exclude ARM - // 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() { -#ifdef _CHAR_UNSIGNED - 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); -#endif - + // This test is applicatble only to x86 and x64 platforms +#if defined(_MIX86) || 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); @@ -46,6 +39,5 @@ int main() { 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); - - return 0; +#endif // ^^^ defined(_MIX86) || defined(_M_X64) ^^^ } From 1efcf96faf1db8d5288bb6fe40b4afa7d76d13a8 Mon Sep 17 00:00:00 2001 From: Alex Guteniev Date: Sat, 15 Aug 2020 14:54:43 +0300 Subject: [PATCH 09/11] _M_IX86 --- tests/std/tests/GH_001103_countl_zero_correctness/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp b/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp index c0ebed18cc6..a6ef700d982 100644 --- a/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp +++ b/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp @@ -14,7 +14,7 @@ using namespace std; int main() { // This test is applicatble only to x86 and x64 platforms -#if defined(_MIX86) || defined(_M_X64) +#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); From d5651bc1394b1adeea02787dc1a96a3c4341d346 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Sat, 15 Aug 2020 06:48:10 -0700 Subject: [PATCH 10/11] tpyo --- tests/std/tests/GH_001103_countl_zero_correctness/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp b/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp index a6ef700d982..74bb8e53d1a 100644 --- a/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp +++ b/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp @@ -13,7 +13,7 @@ using namespace std; int main() { - // This test is applicatble only to x86 and x64 platforms + // 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); From 8142bcb074216f729c071650d1aaf709a819059e Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Sat, 15 Aug 2020 22:42:37 -0700 Subject: [PATCH 11/11] Update tests/std/tests/GH_001103_countl_zero_correctness/test.cpp --- tests/std/tests/GH_001103_countl_zero_correctness/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp b/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp index 74bb8e53d1a..e7d2d923609 100644 --- a/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp +++ b/tests/std/tests/GH_001103_countl_zero_correctness/test.cpp @@ -39,5 +39,5 @@ int main() { 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(_MIX86) || defined(_M_X64) ^^^ +#endif // ^^^ defined(_M_IX86) || defined(_M_X64) ^^^ }