1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_addtf3
3
4 #include <fenv.h>
5 #include <stdio.h>
6
7 #if __LDBL_MANT_DIG__ == 113
8
9 #include "int_lib.h"
10 #include "fp_test.h"
11
12 // Returns: a + b
13 COMPILER_RT_ABI long double __addtf3(long double a, long double b);
14
test__addtf3(long double a,long double b,uint64_t expectedHi,uint64_t expectedLo)15 int test__addtf3(long double a, long double b,
16 uint64_t expectedHi, uint64_t expectedLo)
17 {
18 long double x = __addtf3(a, b);
19 int ret = compareResultLD(x, expectedHi, expectedLo);
20
21 if (ret){
22 printf("error in test__addtf3(%.20Lf, %.20Lf) = %.20Lf, "
23 "expected %.20Lf\n", a, b, x,
24 fromRep128(expectedHi, expectedLo));
25 }
26
27 return ret;
28 }
29
30 char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
31
32 #endif
33
main()34 int main()
35 {
36 #if __LDBL_MANT_DIG__ == 113
37 // qNaN + any = qNaN
38 if (test__addtf3(makeQNaN128(),
39 0x1.23456789abcdefp+5L,
40 UINT64_C(0x7fff800000000000),
41 UINT64_C(0x0)))
42 return 1;
43 // NaN + any = NaN
44 if (test__addtf3(makeNaN128(UINT64_C(0x800030000000)),
45 0x1.23456789abcdefp+5L,
46 UINT64_C(0x7fff800000000000),
47 UINT64_C(0x0)))
48 return 1;
49 // inf + inf = inf
50 if (test__addtf3(makeInf128(),
51 makeInf128(),
52 UINT64_C(0x7fff000000000000),
53 UINT64_C(0x0)))
54 return 1;
55 // inf + any = inf
56 if (test__addtf3(makeInf128(),
57 0x1.2335653452436234723489432abcdefp+5L,
58 UINT64_C(0x7fff000000000000),
59 UINT64_C(0x0)))
60 return 1;
61 // any + any
62 if (test__addtf3(0x1.23456734245345543849abcdefp+5L,
63 0x1.edcba52449872455634654321fp-1L,
64 UINT64_C(0x40042afc95c8b579),
65 UINT64_C(0x61e58dd6c51eb77c)))
66 return 1;
67
68 #if (defined(__arm__) || defined(__aarch64__)) && defined(__ARM_FP) || \
69 defined(i386) || defined(__x86_64__)
70 // Rounding mode tests on supported architectures
71 const long double m = 1234.0L, n = 0.01L;
72
73 fesetround(FE_UPWARD);
74 if (test__addtf3(m, n,
75 UINT64_C(0x40093480a3d70a3d),
76 UINT64_C(0x70a3d70a3d70a3d8)))
77 return 1;
78
79 fesetround(FE_DOWNWARD);
80 if (test__addtf3(m, n,
81 UINT64_C(0x40093480a3d70a3d),
82 UINT64_C(0x70a3d70a3d70a3d7)))
83 return 1;
84
85
86 fesetround(FE_TOWARDZERO);
87 if (test__addtf3(m, n,
88 UINT64_C(0x40093480a3d70a3d),
89 UINT64_C(0x70a3d70a3d70a3d7)))
90 return 1;
91
92 fesetround(FE_TONEAREST);
93 if (test__addtf3(m, n,
94 UINT64_C(0x40093480a3d70a3d),
95 UINT64_C(0x70a3d70a3d70a3d7)))
96 return 1;
97 #endif
98
99 #else
100 printf("skipped\n");
101
102 #endif
103 return 0;
104 }
105