1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_fixunstfti
3 // UNSUPPORTED: target=mips{{.*}}
8 #if __LDBL_MANT_DIG__ == 113
13 // Returns: convert a to a unsigned long long, rounding toward zero.
14 // Negative values all become zero.
16 // Assumption: long double is a 128 bit floating point type
17 // tu_int is a 128 bit integral type
18 // value in long double is representable in tu_int or is negative
19 // (no range checking performed)
21 COMPILER_RT_ABI tu_int
__fixunstfti(long double a
);
23 int test__fixunstfti(long double a
, tu_int expected
)
25 tu_int x
= __fixunstfti(a
);
32 expectedt
.all
= expected
;
34 printf("error in __fixunstfti(%.20Lf) = 0x%.16llX%.16llX, "
35 "expected 0x%.16llX%.16llX\n",
36 a
, xt
.s
.high
, xt
.s
.low
, expectedt
.s
.high
, expectedt
.s
.low
);
41 char assumption_1
[sizeof(tu_int
) == 4*sizeof(su_int
)] = {0};
42 char assumption_2
[sizeof(tu_int
)*CHAR_BIT
== 128] = {0};
43 char assumption_3
[sizeof(long double)*CHAR_BIT
== 128] = {0};
49 #if __LDBL_MANT_DIG__ == 113
50 if (test__fixunstfti(makeInf128(), make_ti(0xffffffffffffffffLL
,
51 0xffffffffffffffffLL
)))
54 if (test__fixunstfti(0.0, 0))
57 if (test__fixunstfti(0.5, 0))
59 if (test__fixunstfti(0.99, 0))
61 if (test__fixunstfti(1.0, 1))
63 if (test__fixunstfti(1.5, 1))
65 if (test__fixunstfti(1.99, 1))
67 if (test__fixunstfti(2.0, 2))
69 if (test__fixunstfti(2.01, 2))
71 if (test__fixunstfti(-0.01, 0))
73 if (test__fixunstfti(-0.99, 0))
76 if (test__fixunstfti(0x1.p
+128, make_ti(0xffffffffffffffffLL
,
77 0xffffffffffffffffLL
)))
80 if (test__fixunstfti(0x1.FFFFFEp
+126, make_ti(0x7fffff8000000000LL
, 0x0)))
82 if (test__fixunstfti(0x1.FFFFFEp
+127, make_ti(0xffffff0000000000LL
, 0x0)))
84 if (test__fixunstfti(0x1.FFFFFEp
+128, make_ti(0xffffffffffffffffLL
,
85 0xffffffffffffffffLL
)))
87 if (test__fixunstfti(0x1.FFFFFEp
+129, make_ti(0xffffffffffffffffLL
,
88 0xffffffffffffffffLL
)))