1// RUN: %clang_builtins %s %librt -o %t && %run %t
2
3#define QUAD_PRECISION
4#include <fenv.h>
5#include <math.h>
6#include <stdio.h>
7#include "fp_lib.h"
8
9#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
10
11int test__compiler_rt_fmaxl(fp_t x, fp_t y) {
12 fp_t crt_value = __compiler_rt_fmaxl(x, y);
13 fp_t libm_value = fmaxl(x, y);
14 // Consider +0 and -0 equal, and also disregard the sign/payload of two NaNs.
15 if (crt_value != libm_value &&
16 !(crt_isnan(crt_value) && crt_isnan(libm_value))) {
17 // Split expected values into two for printf
18 twords x_t, y_t, crt_value_t, libm_value_t;
19 x_t.all = toRep(x);
20 y_t.all = toRep(y);
21 crt_value_t.all = toRep(crt_value);
22 libm_value_t.all = toRep(libm_value);
23 printf(
24 "error: in __compiler_rt_fmaxl([%llX %llX], [%llX %llX]) = "
25 "[%llX %llX] != [%llX %llX]\n",
26 (unsigned long long)x_t.s.high, (unsigned long long)x_t.s.low,
27 (unsigned long long)y_t.s.high, (unsigned long long)y_t.s.low,
28 (unsigned long long)crt_value_t.s.high,
29 (unsigned long long)crt_value_t.s.low,
30 (unsigned long long)libm_value_t.s.high,
31 (unsigned long long)libm_value_t.s.low);
32 return 1;
33 }
34 return 0;
35}
36
37fp_t cases[] = {
38 -NAN, NAN, -INFINITY, INFINITY, -0.0, 0.0, -1, 1, -2, 2,
39 -0x1.0p-16383L, 0x1.0p-16383L, -0x1.0p-16384L, 0x1.0p-16384L, // subnormals
40 -1.001, 1.001, -1.002, 1.002,
41};
42
43#endif
44
45int main() {
46#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
47 const unsigned N = sizeof(cases) / sizeof(cases[0]);
48 unsigned i, j;
49 for (i = 0; i < N; ++i) {
50 for (j = 0; j < N; ++j) {
51 if (test__compiler_rt_fmaxl(cases[i], cases[j])) return 1;
52 }
53 }
54#else
55 printf("skipped\n");
56#endif
57 return 0;
58}
59