1 // RUN: %clang_builtins %s %librt -o %t && %run %t
4 // XFAIL: sparcv9-target-arch
6 //===-- compiler_rt_logbl_test.c - Test __compiler_rt_logbl ---------------===//
8 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
9 // See https://llvm.org/LICENSE.txt for license information.
10 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
12 //===----------------------------------------------------------------------===//
14 // This file checks __compiler_rt_logbl from the compiler_rt library for
15 // conformance against libm.
17 //===----------------------------------------------------------------------===//
19 #define QUAD_PRECISION
25 #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
27 int test__compiler_rt_logbl(fp_t x
) {
28 fp_t crt_value
= __compiler_rt_logbl(x
);
29 fp_t libm_value
= logbl(x
);
30 // Compare actual rep, e.g. to avoid NaN != the same NaN
31 if (toRep(crt_value
) != toRep(libm_value
)) {
32 // Split expected values into two for printf
33 twords x_t
, crt_value_t
, libm_value_t
;
35 crt_value_t
.all
= toRep(crt_value
);
36 libm_value_t
.all
= toRep(libm_value
);
38 "error: in __compiler_rt_logb(%a [%llX %llX]) = %a [%llX %llX] != %a "
40 x
, x_t
.s
.high
, x_t
.s
.low
, crt_value
, crt_value_t
.s
.high
,
41 crt_value_t
.s
.low
, libm_value
, libm_value_t
.s
.high
, libm_value_t
.s
.low
);
48 1.e
-6, -1.e
-6, NAN
, -NAN
, INFINITY
, -INFINITY
, -1,
49 -0.0, 0.0, 1, -2, 2, -0.5, 0.5,
55 #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
56 const unsigned N
= sizeof(cases
) / sizeof(cases
[0]);
58 for (i
= 0; i
< N
; ++i
) {
59 if (test__compiler_rt_logbl(cases
[i
])) return 1;
62 // Test a moving 1 bit, especially to handle denormal values.
63 // Test the negation as well.
66 if (test__compiler_rt_logbl(fromRep(x
))) return 1;
67 if (test__compiler_rt_logbl(fromRep(signBit
^ x
))) return 1;
70 // Also try a couple moving ones
71 x
= signBit
| (signBit
>> 1) | (signBit
>> 2);
73 if (test__compiler_rt_logbl(fromRep(x
))) return 1;
74 if (test__compiler_rt_logbl(fromRep(signBit
^ x
))) return 1;