1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_fixunsxfdi
9 #if HAS_80_BIT_LONG_DOUBLE
10 // Returns: convert a to a unsigned long long, rounding toward zero.
11 // Negative values all become zero.
13 // Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
14 // du_int is a 64 bit integral type
15 // value in long double is representable in du_int or is negative
16 // (no range checking performed)
18 // gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
19 // 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
21 COMPILER_RT_ABI du_int
__fixunsxfdi(long double a
);
23 int test__fixunsxfdi(long double a
, du_int expected
)
25 du_int x
= __fixunsxfdi(a
);
27 printf("error in __fixunsxfdi(%LA) = %llX, expected %llX\n",
32 char assumption_1
[sizeof(du_int
) == 2*sizeof(su_int
)] = {0};
33 char assumption_2
[sizeof(du_int
)*CHAR_BIT
== 64] = {0};
34 char assumption_3
[sizeof(long double)*CHAR_BIT
== 128] = {0};
39 #if HAS_80_BIT_LONG_DOUBLE
40 if (test__fixunsxfdi(0.0, 0))
43 if (test__fixunsxfdi(0.5, 0))
45 if (test__fixunsxfdi(0.99, 0))
47 if (test__fixunsxfdi(1.0, 1))
49 if (test__fixunsxfdi(1.5, 1))
51 if (test__fixunsxfdi(1.99, 1))
53 if (test__fixunsxfdi(2.0, 2))
55 if (test__fixunsxfdi(2.01, 2))
57 if (test__fixunsxfdi(-0.5, 0))
59 if (test__fixunsxfdi(-0.99, 0))
61 if (test__fixunsxfdi(-1.0, 0))
63 if (test__fixunsxfdi(-1.5, 0))
65 if (test__fixunsxfdi(-1.99, 0))
67 if (test__fixunsxfdi(-2.0, 0))
69 if (test__fixunsxfdi(-2.01, 0))
72 if (test__fixunsxfdi(0x1.FFFFFEp
+62, 0x7FFFFF8000000000LL
))
74 if (test__fixunsxfdi(0x1.FFFFFCp
+62, 0x7FFFFF0000000000LL
))
77 if (test__fixunsxfdi(-0x1.FFFFFEp
+62, 0))
79 if (test__fixunsxfdi(-0x1.FFFFFCp
+62, 0))
82 if (test__fixunsxfdi(0x1.FFFFFFFFFFFFFp
+62, 0x7FFFFFFFFFFFFC00LL
))
84 if (test__fixunsxfdi(0x1.FFFFFFFFFFFFEp
+62, 0x7FFFFFFFFFFFF800LL
))
87 if (test__fixunsxfdi(-0x1.FFFFFFFFFFFFFp
+62, 0))
89 if (test__fixunsxfdi(-0x1.FFFFFFFFFFFFEp
+62, 0))
92 if (test__fixunsxfdi(0x1.FFFFFFFFFFFFFFFEp
+63L, 0xFFFFFFFFFFFFFFFFLL
))
94 if (test__fixunsxfdi(0x1.0000000000000002p
+63L, 0x8000000000000001LL
))
96 if (test__fixunsxfdi(0x1.0000000000000000p
+63L, 0x8000000000000000LL
))
98 if (test__fixunsxfdi(0x1.FFFFFFFFFFFFFFFCp
+62L, 0x7FFFFFFFFFFFFFFFLL
))
100 if (test__fixunsxfdi(0x1.FFFFFFFFFFFFFFF8p
+62L, 0x7FFFFFFFFFFFFFFELL
))
103 if (test__fixunsxfdi(-0x1.0000000000000000p
+63L, 0))
105 if (test__fixunsxfdi(-0x1.FFFFFFFFFFFFFFFCp
+62L, 0))
107 if (test__fixunsxfdi(-0x1.FFFFFFFFFFFFFFF8p
+62L, 0))