From 689f1e85ba68db7440451a6834095a52d1526b00 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lu=C3=ADs=20Marques?= Date: Thu, 20 Feb 2020 10:12:31 +0000 Subject: [PATCH] [compiler-rt] [builtins] Fix logb / logbl tests Like was done before in D67999 for `logbf`, this patch fixes the tests for the internal compiler-rt implementations of `logb` and `logbl` to consider all NaNs equivalent. Not doing so was resulting in test failures for riscv64, since the the NaNs had different signs, but the spec doesn't specify the NaN signedness or payload. Fixes bug 44244. Reviewers: rupprecht, delcypher Reviewed By: rupprecht, delcypher Differential Revision: https://reviews.llvm.org/D74826 --- compiler-rt/test/builtins/Unit/compiler_rt_logb_test.c | 6 ++++-- compiler-rt/test/builtins/Unit/compiler_rt_logbl_test.c | 12 +++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/compiler-rt/test/builtins/Unit/compiler_rt_logb_test.c b/compiler-rt/test/builtins/Unit/compiler_rt_logb_test.c index c36b19c..de6ca17 100644 --- a/compiler-rt/test/builtins/Unit/compiler_rt_logb_test.c +++ b/compiler-rt/test/builtins/Unit/compiler_rt_logb_test.c @@ -20,8 +20,10 @@ int test__compiler_rt_logb(fp_t x) { fp_t crt_value = __compiler_rt_logb(x); fp_t libm_value = logb(x); - // Compare actual rep, e.g. to avoid NaN != the same NaN - if (toRep(crt_value) != toRep(libm_value)) { + // Compare the values, considering all NaNs equivalent, as the spec doesn't + // specify the NaN signedness/payload. + if (crt_value != libm_value && + !(crt_isnan(crt_value) && crt_isnan(libm_value))) { printf("error: in __compiler_rt_logb(%a [%lX]) = %a [%lX] != %a [%lX]\n", x, toRep(x), crt_value, toRep(crt_value), libm_value, toRep(libm_value)); diff --git a/compiler-rt/test/builtins/Unit/compiler_rt_logbl_test.c b/compiler-rt/test/builtins/Unit/compiler_rt_logbl_test.c index 2a60d5b..5b72f3d 100644 --- a/compiler-rt/test/builtins/Unit/compiler_rt_logbl_test.c +++ b/compiler-rt/test/builtins/Unit/compiler_rt_logbl_test.c @@ -27,18 +27,20 @@ int test__compiler_rt_logbl(fp_t x) { fp_t crt_value = __compiler_rt_logbl(x); fp_t libm_value = logbl(x); - // Compare actual rep, e.g. to avoid NaN != the same NaN - if (toRep(crt_value) != toRep(libm_value)) { + // Compare the values, considering all NaNs equivalent, as the spec doesn't + // specify the NaN signedness/payload. + if (crt_value != libm_value && + !(crt_isnan(crt_value) && crt_isnan(libm_value))) { // Split expected values into two for printf twords x_t, crt_value_t, libm_value_t; x_t.all = toRep(x); crt_value_t.all = toRep(crt_value); libm_value_t.all = toRep(libm_value); printf( - "error: in __compiler_rt_logb(%a [%llX %llX]) = %a [%llX %llX] != %a " + "error: in __compiler_rt_logbl([%llX %llX]) = [%llX %llX] != " "[%llX %llX]\n", - x, x_t.s.high, x_t.s.low, crt_value, crt_value_t.s.high, - crt_value_t.s.low, libm_value, libm_value_t.s.high, libm_value_t.s.low); + x_t.s.high, x_t.s.low, crt_value_t.s.high, crt_value_t.s.low, + libm_value_t.s.high, libm_value_t.s.low); return 1; } return 0; -- 2.7.4