From 602017f9dac19ff03fa0a3750aa939b8c68481f1 Mon Sep 17 00:00:00 2001 From: Alex Guteniev Date: Sat, 8 Aug 2020 19:50:45 +0300 Subject: [PATCH] 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 70f23e250c..4ff7b5dc2e 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 0000000000..642f530ffa --- /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 0000000000..1609d37258 --- /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; +}