1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_fixxfdi
3 //===-- fixxfdi_test.c - Test __fixxfdi -----------------------------------===//
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 __fixxfdi for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
19 #if HAS_80_BIT_LONG_DOUBLE
20 // Returns: convert a to a signed long long, rounding toward zero.
22 // Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
23 // su_int is a 32 bit integral type
24 // value in long double is representable in di_int (no range checking performed)
26 // gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
27 // 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
29 COMPILER_RT_ABI di_int
__fixxfdi(long double a
);
31 int test__fixxfdi(long double a
, di_int expected
)
33 di_int x
= __fixxfdi(a
);
35 printf("error in __fixxfdi(%LA) = %llX, expected %llX\n",
40 char assumption_1
[sizeof(di_int
) == 2*sizeof(si_int
)] = {0};
41 char assumption_2
[sizeof(su_int
)*CHAR_BIT
== 32] = {0};
42 char assumption_3
[sizeof(long double)*CHAR_BIT
== 128] = {0};
47 #if HAS_80_BIT_LONG_DOUBLE
48 if (test__fixxfdi(0.0, 0))
51 if (test__fixxfdi(0.5, 0))
53 if (test__fixxfdi(0.99, 0))
55 if (test__fixxfdi(1.0, 1))
57 if (test__fixxfdi(1.5, 1))
59 if (test__fixxfdi(1.99, 1))
61 if (test__fixxfdi(2.0, 2))
63 if (test__fixxfdi(2.01, 2))
65 if (test__fixxfdi(-0.5, 0))
67 if (test__fixxfdi(-0.99, 0))
69 if (test__fixxfdi(-1.0, -1))
71 if (test__fixxfdi(-1.5, -1))
73 if (test__fixxfdi(-1.99, -1))
75 if (test__fixxfdi(-2.0, -2))
77 if (test__fixxfdi(-2.01, -2))
80 if (test__fixxfdi(0x1.FFFFFEp
+62, 0x7FFFFF8000000000LL
))
82 if (test__fixxfdi(0x1.FFFFFCp
+62, 0x7FFFFF0000000000LL
))
85 if (test__fixxfdi(-0x1.FFFFFEp
+62, 0x8000008000000000LL
))
87 if (test__fixxfdi(-0x1.FFFFFCp
+62, 0x8000010000000000LL
))
90 if (test__fixxfdi(0x1.FFFFFFFFFFFFFp
+62, 0x7FFFFFFFFFFFFC00LL
))
92 if (test__fixxfdi(0x1.FFFFFFFFFFFFEp
+62, 0x7FFFFFFFFFFFF800LL
))
95 if (test__fixxfdi(-0x1.FFFFFFFFFFFFFp
+62, 0x8000000000000400LL
))
97 if (test__fixxfdi(-0x1.FFFFFFFFFFFFEp
+62, 0x8000000000000800LL
))
100 if (test__fixxfdi(0x1.FFFFFFFFFFFFFFFCp
+62L, 0x7FFFFFFFFFFFFFFFLL
))
102 if (test__fixxfdi(0x1.FFFFFFFFFFFFFFF8p
+62L, 0x7FFFFFFFFFFFFFFELL
))
105 if (test__fixxfdi(-0x1.0000000000000000p
+63L, 0x8000000000000000LL
))
107 if (test__fixxfdi(-0x1.FFFFFFFFFFFFFFFCp
+62L, 0x8000000000000001LL
))
109 if (test__fixxfdi(-0x1.FFFFFFFFFFFFFFF8p
+62L, 0x8000000000000002LL
))