1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_fixunstfdi
3 //===-- fixunstfdi_test.c - Test __fixunstfdi -----------------------------===//
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 __fixunstfdi for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
17 #if _ARCH_PPC || __aarch64__
21 // Returns: convert a to a unsigned long long, rounding toward zero.
22 // Negative values all become zero.
24 // Assumption: long double is a 128 bit floating point type
25 // du_int is a 64 bit integral type
26 // value in long double is representable in du_int or is negative
27 // (no range checking performed)
29 COMPILER_RT_ABI du_int
__fixunstfdi(long double a
);
31 int test__fixunstfdi(long double a
, du_int expected
)
33 du_int x
= __fixunstfdi(a
);
35 printf("error in __fixunstfdi(%LA) = %llX, expected %llX\n",
40 char assumption_1
[sizeof(du_int
) == 2*sizeof(su_int
)] = {0};
41 char assumption_2
[sizeof(du_int
)*CHAR_BIT
== 64] = {0};
42 char assumption_3
[sizeof(long double)*CHAR_BIT
== 128] = {0};
48 #if _ARCH_PPC || __aarch64__
49 if (test__fixunstfdi(0.0, 0))
52 if (test__fixunstfdi(0.5, 0))
54 if (test__fixunstfdi(0.99, 0))
56 if (test__fixunstfdi(1.0, 1))
58 if (test__fixunstfdi(1.5, 1))
60 if (test__fixunstfdi(1.99, 1))
62 if (test__fixunstfdi(2.0, 2))
64 if (test__fixunstfdi(2.01, 2))
66 if (test__fixunstfdi(-0.5, 0))
68 if (test__fixunstfdi(-0.99, 0))
70 if (test__fixunstfdi(-1.0, 0))
72 if (test__fixunstfdi(-1.5, 0))
74 if (test__fixunstfdi(-1.99, 0))
76 if (test__fixunstfdi(-2.0, 0))
78 if (test__fixunstfdi(-2.01, 0))
81 if (test__fixunstfdi(0x1.FFFFFEp
+62, 0x7FFFFF8000000000LL
))
83 if (test__fixunstfdi(0x1.FFFFFCp
+62, 0x7FFFFF0000000000LL
))
86 if (test__fixunstfdi(-0x1.FFFFFEp
+62, 0))
88 if (test__fixunstfdi(-0x1.FFFFFCp
+62, 0))
91 if (test__fixunstfdi(0x1.FFFFFFFFFFFFFp
+62, 0x7FFFFFFFFFFFFC00LL
))
93 if (test__fixunstfdi(0x1.FFFFFFFFFFFFEp
+62, 0x7FFFFFFFFFFFF800LL
))
96 if (test__fixunstfdi(-0x1.FFFFFFFFFFFFFp
+62, 0))
98 if (test__fixunstfdi(-0x1.FFFFFFFFFFFFEp
+62, 0))
101 if (test__fixunstfdi(0x1.FFFFFFFFFFFFFFFEp
+63L, 0xFFFFFFFFFFFFFFFFLL
))
103 if (test__fixunstfdi(0x1.0000000000000002p
+63L, 0x8000000000000001LL
))
105 if (test__fixunstfdi(0x1.0000000000000000p
+63L, 0x8000000000000000LL
))
107 if (test__fixunstfdi(0x1.FFFFFFFFFFFFFFFCp
+62L, 0x7FFFFFFFFFFFFFFFLL
))
109 if (test__fixunstfdi(0x1.FFFFFFFFFFFFFFF8p
+62L, 0x7FFFFFFFFFFFFFFELL
))
111 if (test__fixunstfdi(0x1.p
+64L, 0xFFFFFFFFFFFFFFFFLL
))
114 if (test__fixunstfdi(-0x1.0000000000000000p
+63L, 0))
116 if (test__fixunstfdi(-0x1.FFFFFFFFFFFFFFFCp
+62L, 0))
118 if (test__fixunstfdi(-0x1.FFFFFFFFFFFFFFF8p
+62L, 0))