1 // RUN: %clang_builtins %s %librt -o %t && %run %t
9 #if defined(CRT_HAS_TF_MODE)
11 int test__compiler_rt_logbl(fp_t x
) {
13 if (fpclassify(x
) == FP_SUBNORMAL
)
16 fp_t crt_value
= __compiler_rt_logbl(x
);
17 fp_t libm_value
= logbl(x
);
18 // Compare the values, considering all NaNs equivalent, as the spec doesn't
19 // specify the NaN signedness/payload.
20 if (crt_value
!= libm_value
&&
21 !(crt_isnan(crt_value
) && crt_isnan(libm_value
))) {
22 // Split expected values into two for printf
23 twords x_t
, crt_value_t
, libm_value_t
;
25 crt_value_t
.all
= toRep(crt_value
);
26 libm_value_t
.all
= toRep(libm_value
);
27 printf("error: in __compiler_rt_logbl([%llX %llX]) = [%llX %llX] != "
29 x_t
.s
.high
, x_t
.s
.low
, crt_value_t
.s
.high
, crt_value_t
.s
.low
,
30 libm_value_t
.s
.high
, libm_value_t
.s
.low
);
37 1.e
-6, -1.e
-6, NAN
, -NAN
, INFINITY
, -INFINITY
, -1,
38 -0.0, 0.0, 1, -2, 2, -0.5, 0.5,
42 const unsigned N
= sizeof(cases
) / sizeof(cases
[0]);
43 for (unsigned i
= 0; i
< N
; ++i
) {
44 if (test__compiler_rt_logbl(cases
[i
]))
48 // Test a moving 1 bit, especially to handle denormal values.
49 // Test the negation as well.
50 // Since we are comparing the compiler-rt IEEE implementation against libc's
51 // long double implementation, this test can only succeed if long double
52 // is an IEEE 128-bit floating point number (otherwise we will see mismatches
53 // once we reach numbers that cannot be precisely represented in long double
55 # if defined(CRT_LDBL_IEEE_F128)
59 if (test__compiler_rt_logbl(fromRep(x
)))
61 if (test__compiler_rt_logbl(fromRep(signBit
^ x
)))
64 printf("l1: %d\n", i
++);
66 // Also try a couple moving ones
67 x
= signBit
| (signBit
>> 1) | (signBit
>> 2);
69 if (test__compiler_rt_logbl(fromRep(x
)))
71 if (test__compiler_rt_logbl(fromRep(signBit
^ x
)))
74 printf("l1: %d\n", i
++);