[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / fixunsxfdi_test.c
blob50c04654617149a112a78b80d094ce25cc05eab0
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_fixunsxfdi
3 //===-- fixunsxfdi_test.c - Test __fixunsxfdi -----------------------------===//
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 __fixunsxfdi for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
15 #include "int_lib.h"
16 #include <stdio.h>
17 #include <limits.h>
20 #if HAS_80_BIT_LONG_DOUBLE
21 // Returns: convert a to a unsigned long long, rounding toward zero.
22 // Negative values all become zero.
24 // Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
25 // du_int is a 64 bit integral type
26 // value in long double is representable in du_int or is negative
27 // (no range checking performed)
29 // gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
30 // 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
32 COMPILER_RT_ABI du_int __fixunsxfdi(long double a);
34 int test__fixunsxfdi(long double a, du_int expected)
36 du_int x = __fixunsxfdi(a);
37 if (x != expected)
38 printf("error in __fixunsxfdi(%LA) = %llX, expected %llX\n",
39 a, x, expected);
40 return x != expected;
43 char assumption_1[sizeof(du_int) == 2*sizeof(su_int)] = {0};
44 char assumption_2[sizeof(du_int)*CHAR_BIT == 64] = {0};
45 char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
46 #endif
48 int main()
50 #if HAS_80_BIT_LONG_DOUBLE
51 if (test__fixunsxfdi(0.0, 0))
52 return 1;
54 if (test__fixunsxfdi(0.5, 0))
55 return 1;
56 if (test__fixunsxfdi(0.99, 0))
57 return 1;
58 if (test__fixunsxfdi(1.0, 1))
59 return 1;
60 if (test__fixunsxfdi(1.5, 1))
61 return 1;
62 if (test__fixunsxfdi(1.99, 1))
63 return 1;
64 if (test__fixunsxfdi(2.0, 2))
65 return 1;
66 if (test__fixunsxfdi(2.01, 2))
67 return 1;
68 if (test__fixunsxfdi(-0.5, 0))
69 return 1;
70 if (test__fixunsxfdi(-0.99, 0))
71 return 1;
72 if (test__fixunsxfdi(-1.0, 0))
73 return 1;
74 if (test__fixunsxfdi(-1.5, 0))
75 return 1;
76 if (test__fixunsxfdi(-1.99, 0))
77 return 1;
78 if (test__fixunsxfdi(-2.0, 0))
79 return 1;
80 if (test__fixunsxfdi(-2.01, 0))
81 return 1;
83 if (test__fixunsxfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000LL))
84 return 1;
85 if (test__fixunsxfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000LL))
86 return 1;
88 if (test__fixunsxfdi(-0x1.FFFFFEp+62, 0))
89 return 1;
90 if (test__fixunsxfdi(-0x1.FFFFFCp+62, 0))
91 return 1;
93 if (test__fixunsxfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00LL))
94 return 1;
95 if (test__fixunsxfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL))
96 return 1;
98 if (test__fixunsxfdi(-0x1.FFFFFFFFFFFFFp+62, 0))
99 return 1;
100 if (test__fixunsxfdi(-0x1.FFFFFFFFFFFFEp+62, 0))
101 return 1;
103 if (test__fixunsxfdi(0x1.FFFFFFFFFFFFFFFEp+63L, 0xFFFFFFFFFFFFFFFFLL))
104 return 1;
105 if (test__fixunsxfdi(0x1.0000000000000002p+63L, 0x8000000000000001LL))
106 return 1;
107 if (test__fixunsxfdi(0x1.0000000000000000p+63L, 0x8000000000000000LL))
108 return 1;
109 if (test__fixunsxfdi(0x1.FFFFFFFFFFFFFFFCp+62L, 0x7FFFFFFFFFFFFFFFLL))
110 return 1;
111 if (test__fixunsxfdi(0x1.FFFFFFFFFFFFFFF8p+62L, 0x7FFFFFFFFFFFFFFELL))
112 return 1;
114 if (test__fixunsxfdi(-0x1.0000000000000000p+63L, 0))
115 return 1;
116 if (test__fixunsxfdi(-0x1.FFFFFFFFFFFFFFFCp+62L, 0))
117 return 1;
118 if (test__fixunsxfdi(-0x1.FFFFFFFFFFFFFFF8p+62L, 0))
119 return 1;
121 #else
122 printf("skipped\n");
123 #endif
124 return 0;