1 //===-- fixxfti_test.c - Test __fixxfti -----------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file tests __fixxfti for the compiler_rt library.
12 //===----------------------------------------------------------------------===//
19 // Returns: convert a to a signed long long, rounding toward zero.
21 // Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
22 // su_int is a 32 bit integral type
23 // value in long double is representable in ti_int (no range checking performed)
25 // gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
26 // 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
28 ti_int
__fixxfti(long double a
);
30 int test__fixxfti(long double a
, ti_int expected
)
32 ti_int x
= __fixxfti(a
);
38 expectedt
.all
= expected
;
39 printf("error in __fixxfti(%LA) = 0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
40 a
, xt
.s
.high
, xt
.s
.low
, expectedt
.s
.high
, expectedt
.s
.low
);
45 char assumption_1
[sizeof(ti_int
) == 2*sizeof(di_int
)] = {0};
46 char assumption_2
[sizeof(su_int
)*CHAR_BIT
== 32] = {0};
47 char assumption_3
[sizeof(long double)*CHAR_BIT
== 128] = {0};
54 if (test__fixxfti(0.0, 0))
57 if (test__fixxfti(0.5, 0))
59 if (test__fixxfti(0.99, 0))
61 if (test__fixxfti(1.0, 1))
63 if (test__fixxfti(1.5, 1))
65 if (test__fixxfti(1.99, 1))
67 if (test__fixxfti(2.0, 2))
69 if (test__fixxfti(2.01, 2))
71 if (test__fixxfti(-0.5, 0))
73 if (test__fixxfti(-0.99, 0))
75 if (test__fixxfti(-1.0, -1))
77 if (test__fixxfti(-1.5, -1))
79 if (test__fixxfti(-1.99, -1))
81 if (test__fixxfti(-2.0, -2))
83 if (test__fixxfti(-2.01, -2))
86 if (test__fixxfti(0x1.FFFFFEp
+62, 0x7FFFFF8000000000LL
))
88 if (test__fixxfti(0x1.FFFFFCp
+62, 0x7FFFFF0000000000LL
))
91 if (test__fixxfti(-0x1.FFFFFEp
+62, make_ti(0xFFFFFFFFFFFFFFFFLL
,
92 0x8000008000000000LL
)))
94 if (test__fixxfti(-0x1.FFFFFCp
+62, make_ti(0xFFFFFFFFFFFFFFFFLL
,
95 0x8000010000000000LL
)))
98 if (test__fixxfti(0x1.FFFFFFFFFFFFFp
+62, 0x7FFFFFFFFFFFFC00LL
))
100 if (test__fixxfti(0x1.FFFFFFFFFFFFEp
+62, 0x7FFFFFFFFFFFF800LL
))
103 if (test__fixxfti(-0x1.FFFFFFFFFFFFFp
+62, make_ti(0xFFFFFFFFFFFFFFFFLL
,
104 0x8000000000000400LL
)))
106 if (test__fixxfti(-0x1.FFFFFFFFFFFFEp
+62, make_ti(0xFFFFFFFFFFFFFFFFLL
,
107 0x8000000000000800LL
)))
110 if (test__fixxfti(0x1.FFFFFFFFFFFFFFFCp
+62L, 0x7FFFFFFFFFFFFFFFLL
))
112 if (test__fixxfti(0x1.FFFFFFFFFFFFFFF8p
+62L, 0x7FFFFFFFFFFFFFFELL
))
115 if (test__fixxfti(-0x1.0000000000000000p
+63L, make_ti(0xFFFFFFFFFFFFFFFFLL
,
116 0x8000000000000000LL
)))
118 if (test__fixxfti(-0x1.FFFFFFFFFFFFFFFCp
+62L, make_ti(0xFFFFFFFFFFFFFFFFLL
,
119 0x8000000000000001LL
)))
121 if (test__fixxfti(-0x1.FFFFFFFFFFFFFFF8p
+62L, make_ti(0xFFFFFFFFFFFFFFFFLL
,
122 0x8000000000000002LL
)))
125 if (test__fixxfti(0x1.FFFFFFFFFFFFFFFEp
+126L, make_ti(0x7FFFFFFFFFFFFFFFLL
,
126 0x8000000000000000LL
)))
128 if (test__fixxfti(0x1.FFFFFFFFFFFFFFFCp
+126L, make_ti(0x7FFFFFFFFFFFFFFFLL
,
129 0x0000000000000000LL
)))
133 if (test__fixxfti(-0x1.0000000000000000p
+127L, make_ti(0x8000000000000000LL
,
134 0x0000000000000000LL
)))
136 if (test__fixxfti(-0x1.FFFFFFFFFFFFFFFEp
+126L, make_ti(0x8000000000000000LL
,
137 0x8000000000000000LL
)))
139 if (test__fixxfti(-0x1.FFFFFFFFFFFFFFFCp
+126L, make_ti(0x8000000000000001LL
,
140 0x0000000000000000LL
)))