1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_fixunstfti
3 //===-- fixunstfti_test.c - Test __fixunstfti -----------------------------===//
5 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 // See https://llvm.org/LICENSE.txt for license information.
7 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 //===----------------------------------------------------------------------===//
11 // This file tests __fixunstfti for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
19 #if __LDBL_MANT_DIG__ == 113
24 // Returns: convert a to a unsigned long long, rounding toward zero.
25 // Negative values all become zero.
27 // Assumption: long double is a 128 bit floating point type
28 // tu_int is a 128 bit integral type
29 // value in long double is representable in tu_int or is negative
30 // (no range checking performed)
32 COMPILER_RT_ABI tu_int
__fixunstfti(long double a
);
34 int test__fixunstfti(long double a
, tu_int expected
)
36 tu_int x
= __fixunstfti(a
);
43 expectedt
.all
= expected
;
45 printf("error in __fixunstfti(%.20Lf) = 0x%.16llX%.16llX, "
46 "expected 0x%.16llX%.16llX\n",
47 a
, xt
.s
.high
, xt
.s
.low
, expectedt
.s
.high
, expectedt
.s
.low
);
52 char assumption_1
[sizeof(tu_int
) == 4*sizeof(su_int
)] = {0};
53 char assumption_2
[sizeof(tu_int
)*CHAR_BIT
== 128] = {0};
54 char assumption_3
[sizeof(long double)*CHAR_BIT
== 128] = {0};
60 #if __LDBL_MANT_DIG__ == 113
61 if (test__fixunstfti(makeInf128(), make_ti(0xffffffffffffffffLL
,
62 0xffffffffffffffffLL
)))
65 if (test__fixunstfti(0.0, 0))
68 if (test__fixunstfti(0.5, 0))
70 if (test__fixunstfti(0.99, 0))
72 if (test__fixunstfti(1.0, 1))
74 if (test__fixunstfti(1.5, 1))
76 if (test__fixunstfti(1.99, 1))
78 if (test__fixunstfti(2.0, 2))
80 if (test__fixunstfti(2.01, 2))
82 if (test__fixunstfti(-0.01, 0))
84 if (test__fixunstfti(-0.99, 0))
87 if (test__fixunstfti(0x1.p
+128, make_ti(0xffffffffffffffffLL
,
88 0xffffffffffffffffLL
)))
91 if (test__fixunstfti(0x1.FFFFFEp
+126, make_ti(0x7fffff8000000000LL
, 0x0)))
93 if (test__fixunstfti(0x1.FFFFFEp
+127, make_ti(0xffffff0000000000LL
, 0x0)))
95 if (test__fixunstfti(0x1.FFFFFEp
+128, make_ti(0xffffffffffffffffLL
,
96 0xffffffffffffffffLL
)))
98 if (test__fixunstfti(0x1.FFFFFEp
+129, make_ti(0xffffffffffffffffLL
,
99 0xffffffffffffffffLL
)))