1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_fixxfdi
3
4 #include "int_lib.h"
5 #include <stdio.h>
6
7
8 #if HAS_80_BIT_LONG_DOUBLE
9 // Returns: convert a to a signed long long, rounding toward zero.
10
11 // Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
12 // su_int is a 32 bit integral type
13 // value in long double is representable in di_int (no range checking performed)
14
15 // gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
16 // 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
17
18 COMPILER_RT_ABI di_int __fixxfdi(long double a);
19
test__fixxfdi(long double a,di_int expected)20 int test__fixxfdi(long double a, di_int expected)
21 {
22 di_int x = __fixxfdi(a);
23 if (x != expected)
24 printf("error in __fixxfdi(%LA) = %llX, expected %llX\n",
25 a, x, expected);
26 return x != expected;
27 }
28
29 char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
30 char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0};
31 char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
32 #endif
33
main()34 int main()
35 {
36 #if HAS_80_BIT_LONG_DOUBLE
37 if (test__fixxfdi(0.0, 0))
38 return 1;
39
40 if (test__fixxfdi(0.5, 0))
41 return 1;
42 if (test__fixxfdi(0.99, 0))
43 return 1;
44 if (test__fixxfdi(1.0, 1))
45 return 1;
46 if (test__fixxfdi(1.5, 1))
47 return 1;
48 if (test__fixxfdi(1.99, 1))
49 return 1;
50 if (test__fixxfdi(2.0, 2))
51 return 1;
52 if (test__fixxfdi(2.01, 2))
53 return 1;
54 if (test__fixxfdi(-0.5, 0))
55 return 1;
56 if (test__fixxfdi(-0.99, 0))
57 return 1;
58 if (test__fixxfdi(-1.0, -1))
59 return 1;
60 if (test__fixxfdi(-1.5, -1))
61 return 1;
62 if (test__fixxfdi(-1.99, -1))
63 return 1;
64 if (test__fixxfdi(-2.0, -2))
65 return 1;
66 if (test__fixxfdi(-2.01, -2))
67 return 1;
68
69 if (test__fixxfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000LL))
70 return 1;
71 if (test__fixxfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000LL))
72 return 1;
73
74 if (test__fixxfdi(-0x1.FFFFFEp+62, 0x8000008000000000LL))
75 return 1;
76 if (test__fixxfdi(-0x1.FFFFFCp+62, 0x8000010000000000LL))
77 return 1;
78
79 if (test__fixxfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00LL))
80 return 1;
81 if (test__fixxfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL))
82 return 1;
83
84 if (test__fixxfdi(-0x1.FFFFFFFFFFFFFp+62, 0x8000000000000400LL))
85 return 1;
86 if (test__fixxfdi(-0x1.FFFFFFFFFFFFEp+62, 0x8000000000000800LL))
87 return 1;
88
89 if (test__fixxfdi(0x1.FFFFFFFFFFFFFFFCp+62L, 0x7FFFFFFFFFFFFFFFLL))
90 return 1;
91 if (test__fixxfdi(0x1.FFFFFFFFFFFFFFF8p+62L, 0x7FFFFFFFFFFFFFFELL))
92 return 1;
93
94 if (test__fixxfdi(-0x1.0000000000000000p+63L, 0x8000000000000000LL))
95 return 1;
96 if (test__fixxfdi(-0x1.FFFFFFFFFFFFFFFCp+62L, 0x8000000000000001LL))
97 return 1;
98 if (test__fixxfdi(-0x1.FFFFFFFFFFFFFFF8p+62L, 0x8000000000000002LL))
99 return 1;
100
101 #else
102 printf("skipped\n");
103 #endif
104 return 0;
105 }
106