[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / subtf3_test.c
blob265ab642ecf0cd2e955f94a673e7a39de22ba39c
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_subtf3
3 //===--------------- subtf3_test.c - Test __subtf3 ------------------------===//
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 __subtf3 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 __subtf3(long double a, long double b);
26 int test__subtf3(long double a, long double b,
27 uint64_t expectedHi, uint64_t expectedLo)
29 long double x = __subtf3(a, b);
30 int ret = compareResultLD(x, expectedHi, expectedLo);
32 if (ret){
33 printf("error in test__subtf3(%.20Lf, %.20Lf) = %.20Lf, "
34 "expected %.20Lf\n", a, b, x,
35 fromRep128(expectedHi, expectedLo));
37 return ret;
40 char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
42 #endif
44 int main()
46 #if __LDBL_MANT_DIG__ == 113
47 // qNaN - any = qNaN
48 if (test__subtf3(makeQNaN128(),
49 0x1.23456789abcdefp+5L,
50 UINT64_C(0x7fff800000000000),
51 UINT64_C(0x0)))
52 return 1;
53 // NaN - any = NaN
54 if (test__subtf3(makeNaN128(UINT64_C(0x800030000000)),
55 0x1.23456789abcdefp+5L,
56 UINT64_C(0x7fff800000000000),
57 UINT64_C(0x0)))
58 return 1;
59 // inf - any = inf
60 if (test__subtf3(makeInf128(),
61 0x1.23456789abcdefp+5L,
62 UINT64_C(0x7fff000000000000),
63 UINT64_C(0x0)))
64 return 1;
65 // any - any
66 if (test__subtf3(0x1.234567829a3bcdef5678ade36734p+5L,
67 0x1.ee9d7c52354a6936ab8d7654321fp-1L,
68 UINT64_C(0x40041b8af1915166),
69 UINT64_C(0xa44a7bca780a166c)))
70 return 1;
72 #if (defined(__arm__) || defined(__aarch64__)) && defined(__ARM_FP) || \
73 defined(i386) || defined(__x86_64__)
74 // Rounding mode tests on supported architectures
75 const long double m = 1234.02L, n = 0.01L;
77 fesetround(FE_UPWARD);
78 if (test__subtf3(m, n,
79 UINT64_C(0x40093480a3d70a3d),
80 UINT64_C(0x70a3d70a3d70a3d7)))
81 return 1;
83 fesetround(FE_DOWNWARD);
84 if (test__subtf3(m, n,
85 UINT64_C(0x40093480a3d70a3d),
86 UINT64_C(0x70a3d70a3d70a3d6)))
87 return 1;
89 fesetround(FE_TOWARDZERO);
90 if (test__subtf3(m, n,
91 UINT64_C(0x40093480a3d70a3d),
92 UINT64_C(0x70a3d70a3d70a3d6)))
93 return 1;
95 fesetround(FE_TONEAREST);
96 if (test__subtf3(m, n,
97 UINT64_C(0x40093480a3d70a3d),
98 UINT64_C(0x70a3d70a3d70a3d7)))
99 return 1;
100 #endif
102 #else
103 printf("skipped\n");
105 #endif
106 return 0;