1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_fixxfti
3 // REQUIRES: x86-target-arch
5 //===-- fixxfti_test.c - Test __fixxfti -----------------------------------===//
7 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8 // See https://llvm.org/LICENSE.txt for license information.
9 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11 //===----------------------------------------------------------------------===//
13 // This file tests __fixxfti for the compiler_rt library.
15 //===----------------------------------------------------------------------===//
20 #if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE
22 // Returns: convert a to a signed long long, rounding toward zero.
24 // Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
25 // su_int is a 32 bit integral type
26 // value in long double is representable in ti_int (no range checking performed)
28 // gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
29 // 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
31 COMPILER_RT_ABI ti_int
__fixxfti(long double a
);
33 int test__fixxfti(long double a
, ti_int expected
)
35 ti_int x
= __fixxfti(a
);
41 expectedt
.all
= expected
;
42 printf("error in __fixxfti(%LA) = 0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
43 a
, xt
.s
.high
, xt
.s
.low
, expectedt
.s
.high
, expectedt
.s
.low
);
48 COMPILE_TIME_ASSERT(sizeof(ti_int
) == 2*sizeof(di_int
));
49 COMPILE_TIME_ASSERT(sizeof(su_int
)*CHAR_BIT
== 32);
50 COMPILE_TIME_ASSERT(sizeof(long double)*CHAR_BIT
== 128);
56 #if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE
57 if (test__fixxfti(0.0, 0))
60 if (test__fixxfti(0.5, 0))
62 if (test__fixxfti(0.99, 0))
64 if (test__fixxfti(1.0, 1))
66 if (test__fixxfti(1.5, 1))
68 if (test__fixxfti(1.99, 1))
70 if (test__fixxfti(2.0, 2))
72 if (test__fixxfti(2.01, 2))
74 if (test__fixxfti(-0.5, 0))
76 if (test__fixxfti(-0.99, 0))
78 if (test__fixxfti(-1.0, -1))
80 if (test__fixxfti(-1.5, -1))
82 if (test__fixxfti(-1.99, -1))
84 if (test__fixxfti(-2.0, -2))
86 if (test__fixxfti(-2.01, -2))
89 if (test__fixxfti(0x1.FFFFFEp
+62, 0x7FFFFF8000000000LL
))
91 if (test__fixxfti(0x1.FFFFFCp
+62, 0x7FFFFF0000000000LL
))
94 if (test__fixxfti(-0x1.FFFFFEp
+62, make_ti(0xFFFFFFFFFFFFFFFFLL
,
95 0x8000008000000000LL
)))
97 if (test__fixxfti(-0x1.FFFFFCp
+62, make_ti(0xFFFFFFFFFFFFFFFFLL
,
98 0x8000010000000000LL
)))
101 if (test__fixxfti(0x1.FFFFFFFFFFFFFp
+62, 0x7FFFFFFFFFFFFC00LL
))
103 if (test__fixxfti(0x1.FFFFFFFFFFFFEp
+62, 0x7FFFFFFFFFFFF800LL
))
106 if (test__fixxfti(-0x1.FFFFFFFFFFFFFp
+62, make_ti(0xFFFFFFFFFFFFFFFFLL
,
107 0x8000000000000400LL
)))
109 if (test__fixxfti(-0x1.FFFFFFFFFFFFEp
+62, make_ti(0xFFFFFFFFFFFFFFFFLL
,
110 0x8000000000000800LL
)))
113 if (test__fixxfti(0x1.FFFFFFFFFFFFFFFCp
+62L, 0x7FFFFFFFFFFFFFFFLL
))
115 if (test__fixxfti(0x1.FFFFFFFFFFFFFFF8p
+62L, 0x7FFFFFFFFFFFFFFELL
))
118 if (test__fixxfti(-0x1.0000000000000000p
+63L, make_ti(0xFFFFFFFFFFFFFFFFLL
,
119 0x8000000000000000LL
)))
121 if (test__fixxfti(-0x1.FFFFFFFFFFFFFFFCp
+62L, make_ti(0xFFFFFFFFFFFFFFFFLL
,
122 0x8000000000000001LL
)))
124 if (test__fixxfti(-0x1.FFFFFFFFFFFFFFF8p
+62L, make_ti(0xFFFFFFFFFFFFFFFFLL
,
125 0x8000000000000002LL
)))
128 if (test__fixxfti(0x1.FFFFFFFFFFFFFFFEp
+126L, make_ti(0x7FFFFFFFFFFFFFFFLL
,
129 0x8000000000000000LL
)))
131 if (test__fixxfti(0x1.FFFFFFFFFFFFFFFCp
+126L, make_ti(0x7FFFFFFFFFFFFFFFLL
,
132 0x0000000000000000LL
)))
136 if (test__fixxfti(-0x1.0000000000000000p
+127L, make_ti(0x8000000000000000LL
,
137 0x0000000000000000LL
)))
139 if (test__fixxfti(-0x1.FFFFFFFFFFFFFFFEp
+126L, make_ti(0x8000000000000000LL
,
140 0x8000000000000000LL
)))
142 if (test__fixxfti(-0x1.FFFFFFFFFFFFFFFCp
+126L, make_ti(0x8000000000000001LL
,
143 0x0000000000000000LL
)))