1 // RUN: %clang_builtins %s %librt -o %t && %run %t
11 #if defined(CRT_HAS_TF_MODE)
13 int test__compiler_rt_scalbnl(const char *mode
, fp_t x
, int y
) {
15 if (fpclassify(x
) == FP_SUBNORMAL
)
18 fp_t crt_value
= __compiler_rt_scalbnl(x
, y
);
19 fp_t libm_value
= scalbnl(x
, y
);
20 // Consider +/-0 unequal, but disregard the sign/payload of NaN.
21 if (toRep(crt_value
) != toRep(libm_value
) &&
22 !(crt_isnan(crt_value
) && crt_isnan(libm_value
))) {
23 // Split expected values into two for printf
24 twords x_t
, crt_value_t
, libm_value_t
;
26 crt_value_t
.all
= toRep(crt_value
);
27 libm_value_t
.all
= toRep(libm_value
);
29 "error: [%s] in __compiler_rt_scalbnl([%llX %llX], %d) = "
30 "[%llX %llX] != [%llX %llX]\n",
31 mode
, (unsigned long long)x_t
.s
.high
, (unsigned long long)x_t
.s
.low
, y
,
32 (unsigned long long)crt_value_t
.s
.high
,
33 (unsigned long long)crt_value_t
.s
.low
,
34 (unsigned long long)libm_value_t
.s
.high
,
35 (unsigned long long)libm_value_t
.s
.low
);
52 // Since we are comparing the compiler-rt IEEE implementation against libc's
53 // long double implementation, this test can only succeed if long double
54 // is an IEEE 128-bit floating point number.
55 # if defined(CRT_LDBL_IEEE_F128)
68 TF_C(0x1.0p
-16383), // subnormal
69 TF_C(0x1.0p
-16384), // subnormal
72 int iterate_cases(const char *mode
) {
73 const unsigned N
= sizeof(cases
) / sizeof(cases
[0]);
75 for (i
= 0; i
< N
; ++i
) {
77 for (j
= -5; j
<= 5; ++j
) {
78 printf("%d, %d\n", i
, j
);
79 if (test__compiler_rt_scalbnl(mode
, cases
[i
], j
))
82 if (test__compiler_rt_scalbnl(mode
, cases
[i
], -100000))
84 if (test__compiler_rt_scalbnl(mode
, cases
[i
], 100000))
86 if (test__compiler_rt_scalbnl(mode
, cases
[i
], INT_MIN
))
88 if (test__compiler_rt_scalbnl(mode
, cases
[i
], INT_MAX
))
95 if (iterate_cases("default"))
98 // Skip rounding mode tests (fesetround) because compiler-rt's quad-precision
99 // multiply also ignores the current rounding mode.