xref: /aosp_15_r20/external/compiler-rt/test/builtins/Unit/addtf3_test.c (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot //===--------------- addtf3_test.c - Test __addtf3 ------------------------===//
2*7c3d14c8STreehugger Robot //
3*7c3d14c8STreehugger Robot //                     The LLVM Compiler Infrastructure
4*7c3d14c8STreehugger Robot //
5*7c3d14c8STreehugger Robot // This file is dual licensed under the MIT and the University of Illinois Open
6*7c3d14c8STreehugger Robot // Source Licenses. See LICENSE.TXT for details.
7*7c3d14c8STreehugger Robot //
8*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
9*7c3d14c8STreehugger Robot //
10*7c3d14c8STreehugger Robot // This file tests __addtf3 for the compiler_rt library.
11*7c3d14c8STreehugger Robot //
12*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
13*7c3d14c8STreehugger Robot 
14*7c3d14c8STreehugger Robot #include "int_lib.h"
15*7c3d14c8STreehugger Robot #include <stdio.h>
16*7c3d14c8STreehugger Robot 
17*7c3d14c8STreehugger Robot #if __LDBL_MANT_DIG__ == 113
18*7c3d14c8STreehugger Robot 
19*7c3d14c8STreehugger Robot #include "fp_test.h"
20*7c3d14c8STreehugger Robot 
21*7c3d14c8STreehugger Robot // Returns: a + b
22*7c3d14c8STreehugger Robot COMPILER_RT_ABI long double __addtf3(long double a, long double b);
23*7c3d14c8STreehugger Robot 
test__addtf3(long double a,long double b,uint64_t expectedHi,uint64_t expectedLo)24*7c3d14c8STreehugger Robot int test__addtf3(long double a, long double b,
25*7c3d14c8STreehugger Robot                  uint64_t expectedHi, uint64_t expectedLo)
26*7c3d14c8STreehugger Robot {
27*7c3d14c8STreehugger Robot     long double x = __addtf3(a, b);
28*7c3d14c8STreehugger Robot     int ret = compareResultLD(x, expectedHi, expectedLo);
29*7c3d14c8STreehugger Robot 
30*7c3d14c8STreehugger Robot     if (ret){
31*7c3d14c8STreehugger Robot         printf("error in test__addtf3(%.20Lf, %.20Lf) = %.20Lf, "
32*7c3d14c8STreehugger Robot                "expected %.20Lf\n", a, b, x,
33*7c3d14c8STreehugger Robot                fromRep128(expectedHi, expectedLo));
34*7c3d14c8STreehugger Robot     }
35*7c3d14c8STreehugger Robot 
36*7c3d14c8STreehugger Robot     return ret;
37*7c3d14c8STreehugger Robot }
38*7c3d14c8STreehugger Robot 
39*7c3d14c8STreehugger Robot char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
40*7c3d14c8STreehugger Robot 
41*7c3d14c8STreehugger Robot #endif
42*7c3d14c8STreehugger Robot 
main()43*7c3d14c8STreehugger Robot int main()
44*7c3d14c8STreehugger Robot {
45*7c3d14c8STreehugger Robot #if __LDBL_MANT_DIG__ == 113
46*7c3d14c8STreehugger Robot     // qNaN + any = qNaN
47*7c3d14c8STreehugger Robot     if (test__addtf3(makeQNaN128(),
48*7c3d14c8STreehugger Robot                      0x1.23456789abcdefp+5L,
49*7c3d14c8STreehugger Robot                      UINT64_C(0x7fff800000000000),
50*7c3d14c8STreehugger Robot                      UINT64_C(0x0)))
51*7c3d14c8STreehugger Robot         return 1;
52*7c3d14c8STreehugger Robot     // NaN + any = NaN
53*7c3d14c8STreehugger Robot     if (test__addtf3(makeNaN128(UINT64_C(0x800030000000)),
54*7c3d14c8STreehugger Robot                      0x1.23456789abcdefp+5L,
55*7c3d14c8STreehugger Robot                      UINT64_C(0x7fff800000000000),
56*7c3d14c8STreehugger Robot                      UINT64_C(0x0)))
57*7c3d14c8STreehugger Robot         return 1;
58*7c3d14c8STreehugger Robot     // inf + inf = inf
59*7c3d14c8STreehugger Robot     if (test__addtf3(makeInf128(),
60*7c3d14c8STreehugger Robot                      makeInf128(),
61*7c3d14c8STreehugger Robot                      UINT64_C(0x7fff000000000000),
62*7c3d14c8STreehugger Robot                      UINT64_C(0x0)))
63*7c3d14c8STreehugger Robot         return 1;
64*7c3d14c8STreehugger Robot     // inf + any = inf
65*7c3d14c8STreehugger Robot     if (test__addtf3(makeInf128(),
66*7c3d14c8STreehugger Robot                      0x1.2335653452436234723489432abcdefp+5L,
67*7c3d14c8STreehugger Robot                      UINT64_C(0x7fff000000000000),
68*7c3d14c8STreehugger Robot                      UINT64_C(0x0)))
69*7c3d14c8STreehugger Robot         return 1;
70*7c3d14c8STreehugger Robot     // any + any
71*7c3d14c8STreehugger Robot     if (test__addtf3(0x1.23456734245345543849abcdefp+5L,
72*7c3d14c8STreehugger Robot                      0x1.edcba52449872455634654321fp-1L,
73*7c3d14c8STreehugger Robot                      UINT64_C(0x40042afc95c8b579),
74*7c3d14c8STreehugger Robot                      UINT64_C(0x61e58dd6c51eb77c)))
75*7c3d14c8STreehugger Robot         return 1;
76*7c3d14c8STreehugger Robot 
77*7c3d14c8STreehugger Robot #else
78*7c3d14c8STreehugger Robot     printf("skipped\n");
79*7c3d14c8STreehugger Robot 
80*7c3d14c8STreehugger Robot #endif
81*7c3d14c8STreehugger Robot     return 0;
82*7c3d14c8STreehugger Robot }
83