1// RUN: %clang_builtins %s %librt -o %t && %run %t
2
3#define QUAD_PRECISION
4#include <math.h>
5#include <stdio.h>
6#include "fp_lib.h"
7#include "int_lib.h"
8
9#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
10
11int test__compiler_rt_logbl(fp_t x) {
12 fp_t crt_value = __compiler_rt_logbl(x);
13 fp_t libm_value = logbl(x);
14 // Compare the values, considering all NaNs equivalent, as the spec doesn't
15 // specify the NaN signedness/payload.
16 if (crt_value != libm_value &&
17 !(crt_isnan(crt_value) && crt_isnan(libm_value))) {
18 // Split expected values into two for printf
19 twords x_t, crt_value_t, libm_value_t;
20 x_t.all = toRep(x);
21 crt_value_t.all = toRep(crt_value);
22 libm_value_t.all = toRep(libm_value);
23 printf(
24 "error: in __compiler_rt_logbl([%llX %llX]) = [%llX %llX] != "
25 "[%llX %llX]\n",
26 x_t.s.high, x_t.s.low, crt_value_t.s.high, crt_value_t.s.low,
27 libm_value_t.s.high, libm_value_t.s.low);
28 return 1;
29 }
30 return 0;
31}
32
33double cases[] = {
34 1.e-6, -1.e-6, NAN, -NAN, INFINITY, -INFINITY, -1,
35 -0.0, 0.0, 1, -2, 2, -0.5, 0.5,
36};
37
38#endif
39
40int main() {
41#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
42 const unsigned N = sizeof(cases) / sizeof(cases[0]);
43 unsigned i;
44 for (i = 0; i < N; ++i) {
45 if (test__compiler_rt_logbl(cases[i])) return 1;
46 }
47
48 // Test a moving 1 bit, especially to handle denormal values.
49 // Test the negation as well.
50 rep_t x = signBit;
51 while (x) {
52 if (test__compiler_rt_logbl(fromRep(x))) return 1;
53 if (test__compiler_rt_logbl(fromRep(signBit ^ x))) return 1;
54 x >>= 1;
55 }
56 // Also try a couple moving ones
57 x = signBit | (signBit >> 1) | (signBit >> 2);
58 while (x) {
59 if (test__compiler_rt_logbl(fromRep(x))) return 1;
60 if (test__compiler_rt_logbl(fromRep(signBit ^ x))) return 1;
61 x >>= 1;
62 }
63#else
64 printf("skipped\n");
65#endif
66
67 return 0;
68}
69