1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_addtf3
3 //===--------------- addtf3_test.c - Test __addtf3 ------------------------===//
5 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 // See https://llvm.org/LICENSE.txt for license information.
7 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 //===----------------------------------------------------------------------===//
11 // This file tests __addtf3 for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
18 #if __LDBL_MANT_DIG__ == 113
24 COMPILER_RT_ABI
long double __addtf3(long double a
, long double b
);
26 int test__addtf3(long double a
, long double b
,
27 uint64_t expectedHi
, uint64_t expectedLo
)
29 long double x
= __addtf3(a
, b
);
30 int ret
= compareResultLD(x
, expectedHi
, expectedLo
);
33 printf("error in test__addtf3(%.20Lf, %.20Lf) = %.20Lf, "
34 "expected %.20Lf\n", a
, b
, x
,
35 fromRep128(expectedHi
, expectedLo
));
41 char assumption_1
[sizeof(long double) * CHAR_BIT
== 128] = {0};
47 #if __LDBL_MANT_DIG__ == 113
49 if (test__addtf3(makeQNaN128(),
50 0x1.23456789abcdefp
+5L,
51 UINT64_C(0x7fff800000000000),
55 if (test__addtf3(makeNaN128(UINT64_C(0x800030000000)),
56 0x1.23456789abcdefp
+5L,
57 UINT64_C(0x7fff800000000000),
61 if (test__addtf3(makeInf128(),
63 UINT64_C(0x7fff000000000000),
67 if (test__addtf3(makeInf128(),
68 0x1.2335653452436234723489432abcdefp
+5L,
69 UINT64_C(0x7fff000000000000),
73 if (test__addtf3(0x1.23456734245345543849abcdefp
+5L,
74 0x1.edcba52449872455634654321fp
-1L,
75 UINT64_C(0x40042afc95c8b579),
76 UINT64_C(0x61e58dd6c51eb77c)))
79 #if (defined(__arm__) || defined(__aarch64__)) && defined(__ARM_FP) || \
80 defined(i386) || defined(__x86_64__)
81 // Rounding mode tests on supported architectures
82 const long double m
= 1234.0L, n
= 0.01L;
84 fesetround(FE_UPWARD
);
85 if (test__addtf3(m
, n
,
86 UINT64_C(0x40093480a3d70a3d),
87 UINT64_C(0x70a3d70a3d70a3d8)))
90 fesetround(FE_DOWNWARD
);
91 if (test__addtf3(m
, n
,
92 UINT64_C(0x40093480a3d70a3d),
93 UINT64_C(0x70a3d70a3d70a3d7)))
97 fesetround(FE_TOWARDZERO
);
98 if (test__addtf3(m
, n
,
99 UINT64_C(0x40093480a3d70a3d),
100 UINT64_C(0x70a3d70a3d70a3d7)))
103 fesetround(FE_TONEAREST
);
104 if (test__addtf3(m
, n
,
105 UINT64_C(0x40093480a3d70a3d),
106 UINT64_C(0x70a3d70a3d70a3d7)))