1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_fixunsxfdi
3 //===-- fixunsxfdi_test.c - Test __fixunsxfdi -----------------------------===//
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
9 //===----------------------------------------------------------------------===//
11 // This file tests __fixunsxfdi for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
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
);
38 printf("error in __fixunsxfdi(%LA) = %llX, expected %llX\n",
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};
50 #if HAS_80_BIT_LONG_DOUBLE
51 if (test__fixunsxfdi(0.0, 0))
54 if (test__fixunsxfdi(0.5, 0))
56 if (test__fixunsxfdi(0.99, 0))
58 if (test__fixunsxfdi(1.0, 1))
60 if (test__fixunsxfdi(1.5, 1))
62 if (test__fixunsxfdi(1.99, 1))
64 if (test__fixunsxfdi(2.0, 2))
66 if (test__fixunsxfdi(2.01, 2))
68 if (test__fixunsxfdi(-0.5, 0))
70 if (test__fixunsxfdi(-0.99, 0))
72 if (test__fixunsxfdi(-1.0, 0))
74 if (test__fixunsxfdi(-1.5, 0))
76 if (test__fixunsxfdi(-1.99, 0))
78 if (test__fixunsxfdi(-2.0, 0))
80 if (test__fixunsxfdi(-2.01, 0))
83 if (test__fixunsxfdi(0x1.FFFFFEp
+62, 0x7FFFFF8000000000LL
))
85 if (test__fixunsxfdi(0x1.FFFFFCp
+62, 0x7FFFFF0000000000LL
))
88 if (test__fixunsxfdi(-0x1.FFFFFEp
+62, 0))
90 if (test__fixunsxfdi(-0x1.FFFFFCp
+62, 0))
93 if (test__fixunsxfdi(0x1.FFFFFFFFFFFFFp
+62, 0x7FFFFFFFFFFFFC00LL
))
95 if (test__fixunsxfdi(0x1.FFFFFFFFFFFFEp
+62, 0x7FFFFFFFFFFFF800LL
))
98 if (test__fixunsxfdi(-0x1.FFFFFFFFFFFFFp
+62, 0))
100 if (test__fixunsxfdi(-0x1.FFFFFFFFFFFFEp
+62, 0))
103 if (test__fixunsxfdi(0x1.FFFFFFFFFFFFFFFEp
+63L, 0xFFFFFFFFFFFFFFFFLL
))
105 if (test__fixunsxfdi(0x1.0000000000000002p
+63L, 0x8000000000000001LL
))
107 if (test__fixunsxfdi(0x1.0000000000000000p
+63L, 0x8000000000000000LL
))
109 if (test__fixunsxfdi(0x1.FFFFFFFFFFFFFFFCp
+62L, 0x7FFFFFFFFFFFFFFFLL
))
111 if (test__fixunsxfdi(0x1.FFFFFFFFFFFFFFF8p
+62L, 0x7FFFFFFFFFFFFFFELL
))
114 if (test__fixunsxfdi(-0x1.0000000000000000p
+63L, 0))
116 if (test__fixunsxfdi(-0x1.FFFFFFFFFFFFFFFCp
+62L, 0))
118 if (test__fixunsxfdi(-0x1.FFFFFFFFFFFFFFF8p
+62L, 0))