[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / addtf3_test.c
blobdcd4efe9c90150b0fa7db15fcb1a82d747f5bacf
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_addtf3
3 //===--------------- addtf3_test.c - Test __addtf3 ------------------------===//
4 //
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
8 //
9 //===----------------------------------------------------------------------===//
11 // This file tests __addtf3 for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
15 #include <fenv.h>
16 #include <stdio.h>
18 #if __LDBL_MANT_DIG__ == 113
20 #include "int_lib.h"
21 #include "fp_test.h"
23 // Returns: a + b
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);
32 if (ret){
33 printf("error in test__addtf3(%.20Lf, %.20Lf) = %.20Lf, "
34 "expected %.20Lf\n", a, b, x,
35 fromRep128(expectedHi, expectedLo));
38 return ret;
41 char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
43 #endif
45 int main()
47 #if __LDBL_MANT_DIG__ == 113
48 // qNaN + any = qNaN
49 if (test__addtf3(makeQNaN128(),
50 0x1.23456789abcdefp+5L,
51 UINT64_C(0x7fff800000000000),
52 UINT64_C(0x0)))
53 return 1;
54 // NaN + any = NaN
55 if (test__addtf3(makeNaN128(UINT64_C(0x800030000000)),
56 0x1.23456789abcdefp+5L,
57 UINT64_C(0x7fff800000000000),
58 UINT64_C(0x0)))
59 return 1;
60 // inf + inf = inf
61 if (test__addtf3(makeInf128(),
62 makeInf128(),
63 UINT64_C(0x7fff000000000000),
64 UINT64_C(0x0)))
65 return 1;
66 // inf + any = inf
67 if (test__addtf3(makeInf128(),
68 0x1.2335653452436234723489432abcdefp+5L,
69 UINT64_C(0x7fff000000000000),
70 UINT64_C(0x0)))
71 return 1;
72 // any + any
73 if (test__addtf3(0x1.23456734245345543849abcdefp+5L,
74 0x1.edcba52449872455634654321fp-1L,
75 UINT64_C(0x40042afc95c8b579),
76 UINT64_C(0x61e58dd6c51eb77c)))
77 return 1;
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)))
88 return 1;
90 fesetround(FE_DOWNWARD);
91 if (test__addtf3(m, n,
92 UINT64_C(0x40093480a3d70a3d),
93 UINT64_C(0x70a3d70a3d70a3d7)))
94 return 1;
97 fesetround(FE_TOWARDZERO);
98 if (test__addtf3(m, n,
99 UINT64_C(0x40093480a3d70a3d),
100 UINT64_C(0x70a3d70a3d70a3d7)))
101 return 1;
103 fesetround(FE_TONEAREST);
104 if (test__addtf3(m, n,
105 UINT64_C(0x40093480a3d70a3d),
106 UINT64_C(0x70a3d70a3d70a3d7)))
107 return 1;
108 #endif
110 #else
111 printf("skipped\n");
113 #endif
114 return 0;