1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_addtf3
7 // The testcase currently assumes IEEE TF format, once that has been
8 // fixed the defined(CRT_HAS_IEEE_TF) guard can be removed to enable it for
9 // IBM 128 floats as well.
10 #if defined(CRT_HAS_IEEE_TF)
16 COMPILER_RT_ABI tf_float
__addtf3(tf_float a
, tf_float b
);
18 int test__addtf3(tf_float a
, tf_float b
, uint64_t expectedHi
,
19 uint64_t expectedLo
) {
20 tf_float x
= __addtf3(a
, b
);
21 int ret
= compareResultF128(x
, expectedHi
, expectedLo
);
24 printf("error in test__addtf3(%.20Lf, %.20Lf) = %.20Lf, "
26 a
, b
, x
, fromRep128(expectedHi
, expectedLo
));
32 char assumption_1
[sizeof(tf_float
) * CHAR_BIT
== 128] = {0};
37 #if defined(CRT_HAS_IEEE_TF)
39 if (test__addtf3(makeQNaN128(), 0x1.23456789abcdefp
+5L,
40 UINT64_C(0x7fff800000000000), UINT64_C(0x0)))
43 if (test__addtf3(makeNaN128(UINT64_C(0x800030000000)),
44 TF_C(0x1.23456789abcdefp
+5), UINT64_C(0x7fff800000000000),
48 if (test__addtf3(makeInf128(), makeInf128(), UINT64_C(0x7fff000000000000),
52 if (test__addtf3(makeInf128(), TF_C(0x1.2335653452436234723489432abcdefp
+5),
53 UINT64_C(0x7fff000000000000), UINT64_C(0x0)))
56 if (test__addtf3(TF_C(0x1.23456734245345543849abcdefp
+5),
57 TF_C(0x1.edcba52449872455634654321fp
-1),
58 UINT64_C(0x40042afc95c8b579), UINT64_C(0x61e58dd6c51eb77c)))
61 # if (defined(__arm__) || defined(__aarch64__)) && defined(__ARM_FP) || \
62 defined(i386) || defined(__x86_64__) || \
63 (defined(__loongarch__) && __loongarch_frlen != 0)
64 // Rounding mode tests on supported architectures
65 const tf_float m
= 1234.0L, n
= 0.01L;
67 fesetround(FE_UPWARD
);
68 if (test__addtf3(m
, n
, UINT64_C(0x40093480a3d70a3d),
69 UINT64_C(0x70a3d70a3d70a3d8)))
72 fesetround(FE_DOWNWARD
);
73 if (test__addtf3(m
, n
, UINT64_C(0x40093480a3d70a3d),
74 UINT64_C(0x70a3d70a3d70a3d7)))
77 fesetround(FE_TOWARDZERO
);
78 if (test__addtf3(m
, n
, UINT64_C(0x40093480a3d70a3d),
79 UINT64_C(0x70a3d70a3d70a3d7)))
82 fesetround(FE_TONEAREST
);
83 if (test__addtf3(m
, n
, UINT64_C(0x40093480a3d70a3d),
84 UINT64_C(0x70a3d70a3d70a3d7)))