1*4684ddb6SLionel Sambuc //===-- fixunsxfdi_test.c - Test __fixunsxfdi -----------------------------===//
2*4684ddb6SLionel Sambuc //
3*4684ddb6SLionel Sambuc // The LLVM Compiler Infrastructure
4*4684ddb6SLionel Sambuc //
5*4684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
6*4684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
7*4684ddb6SLionel Sambuc //
8*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
9*4684ddb6SLionel Sambuc //
10*4684ddb6SLionel Sambuc // This file tests __fixunsxfdi for the compiler_rt library.
11*4684ddb6SLionel Sambuc //
12*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
13*4684ddb6SLionel Sambuc
14*4684ddb6SLionel Sambuc #include "int_lib.h"
15*4684ddb6SLionel Sambuc #include <stdio.h>
16*4684ddb6SLionel Sambuc #include <limits.h>
17*4684ddb6SLionel Sambuc
18*4684ddb6SLionel Sambuc
19*4684ddb6SLionel Sambuc #if HAS_80_BIT_LONG_DOUBLE
20*4684ddb6SLionel Sambuc // Returns: convert a to a unsigned long long, rounding toward zero.
21*4684ddb6SLionel Sambuc // Negative values all become zero.
22*4684ddb6SLionel Sambuc
23*4684ddb6SLionel Sambuc // Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
24*4684ddb6SLionel Sambuc // du_int is a 64 bit integral type
25*4684ddb6SLionel Sambuc // value in long double is representable in du_int or is negative
26*4684ddb6SLionel Sambuc // (no range checking performed)
27*4684ddb6SLionel Sambuc
28*4684ddb6SLionel Sambuc // gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
29*4684ddb6SLionel Sambuc // 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
30*4684ddb6SLionel Sambuc
31*4684ddb6SLionel Sambuc du_int __fixunsxfdi(long double a);
32*4684ddb6SLionel Sambuc
test__fixunsxfdi(long double a,du_int expected)33*4684ddb6SLionel Sambuc int test__fixunsxfdi(long double a, du_int expected)
34*4684ddb6SLionel Sambuc {
35*4684ddb6SLionel Sambuc du_int x = __fixunsxfdi(a);
36*4684ddb6SLionel Sambuc if (x != expected)
37*4684ddb6SLionel Sambuc printf("error in __fixunsxfdi(%LA) = %llX, expected %llX\n",
38*4684ddb6SLionel Sambuc a, x, expected);
39*4684ddb6SLionel Sambuc return x != expected;
40*4684ddb6SLionel Sambuc }
41*4684ddb6SLionel Sambuc
42*4684ddb6SLionel Sambuc char assumption_1[sizeof(du_int) == 2*sizeof(su_int)] = {0};
43*4684ddb6SLionel Sambuc char assumption_2[sizeof(du_int)*CHAR_BIT == 64] = {0};
44*4684ddb6SLionel Sambuc char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
45*4684ddb6SLionel Sambuc #endif
46*4684ddb6SLionel Sambuc
main()47*4684ddb6SLionel Sambuc int main()
48*4684ddb6SLionel Sambuc {
49*4684ddb6SLionel Sambuc #if HAS_80_BIT_LONG_DOUBLE
50*4684ddb6SLionel Sambuc if (test__fixunsxfdi(0.0, 0))
51*4684ddb6SLionel Sambuc return 1;
52*4684ddb6SLionel Sambuc
53*4684ddb6SLionel Sambuc if (test__fixunsxfdi(0.5, 0))
54*4684ddb6SLionel Sambuc return 1;
55*4684ddb6SLionel Sambuc if (test__fixunsxfdi(0.99, 0))
56*4684ddb6SLionel Sambuc return 1;
57*4684ddb6SLionel Sambuc if (test__fixunsxfdi(1.0, 1))
58*4684ddb6SLionel Sambuc return 1;
59*4684ddb6SLionel Sambuc if (test__fixunsxfdi(1.5, 1))
60*4684ddb6SLionel Sambuc return 1;
61*4684ddb6SLionel Sambuc if (test__fixunsxfdi(1.99, 1))
62*4684ddb6SLionel Sambuc return 1;
63*4684ddb6SLionel Sambuc if (test__fixunsxfdi(2.0, 2))
64*4684ddb6SLionel Sambuc return 1;
65*4684ddb6SLionel Sambuc if (test__fixunsxfdi(2.01, 2))
66*4684ddb6SLionel Sambuc return 1;
67*4684ddb6SLionel Sambuc if (test__fixunsxfdi(-0.5, 0))
68*4684ddb6SLionel Sambuc return 1;
69*4684ddb6SLionel Sambuc if (test__fixunsxfdi(-0.99, 0))
70*4684ddb6SLionel Sambuc return 1;
71*4684ddb6SLionel Sambuc if (test__fixunsxfdi(-1.0, 0))
72*4684ddb6SLionel Sambuc return 1;
73*4684ddb6SLionel Sambuc if (test__fixunsxfdi(-1.5, 0))
74*4684ddb6SLionel Sambuc return 1;
75*4684ddb6SLionel Sambuc if (test__fixunsxfdi(-1.99, 0))
76*4684ddb6SLionel Sambuc return 1;
77*4684ddb6SLionel Sambuc if (test__fixunsxfdi(-2.0, 0))
78*4684ddb6SLionel Sambuc return 1;
79*4684ddb6SLionel Sambuc if (test__fixunsxfdi(-2.01, 0))
80*4684ddb6SLionel Sambuc return 1;
81*4684ddb6SLionel Sambuc
82*4684ddb6SLionel Sambuc if (test__fixunsxfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000LL))
83*4684ddb6SLionel Sambuc return 1;
84*4684ddb6SLionel Sambuc if (test__fixunsxfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000LL))
85*4684ddb6SLionel Sambuc return 1;
86*4684ddb6SLionel Sambuc
87*4684ddb6SLionel Sambuc if (test__fixunsxfdi(-0x1.FFFFFEp+62, 0))
88*4684ddb6SLionel Sambuc return 1;
89*4684ddb6SLionel Sambuc if (test__fixunsxfdi(-0x1.FFFFFCp+62, 0))
90*4684ddb6SLionel Sambuc return 1;
91*4684ddb6SLionel Sambuc
92*4684ddb6SLionel Sambuc if (test__fixunsxfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00LL))
93*4684ddb6SLionel Sambuc return 1;
94*4684ddb6SLionel Sambuc if (test__fixunsxfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL))
95*4684ddb6SLionel Sambuc return 1;
96*4684ddb6SLionel Sambuc
97*4684ddb6SLionel Sambuc if (test__fixunsxfdi(-0x1.FFFFFFFFFFFFFp+62, 0))
98*4684ddb6SLionel Sambuc return 1;
99*4684ddb6SLionel Sambuc if (test__fixunsxfdi(-0x1.FFFFFFFFFFFFEp+62, 0))
100*4684ddb6SLionel Sambuc return 1;
101*4684ddb6SLionel Sambuc
102*4684ddb6SLionel Sambuc if (test__fixunsxfdi(0x1.FFFFFFFFFFFFFFFEp+63L, 0xFFFFFFFFFFFFFFFFLL))
103*4684ddb6SLionel Sambuc return 1;
104*4684ddb6SLionel Sambuc if (test__fixunsxfdi(0x1.0000000000000002p+63L, 0x8000000000000001LL))
105*4684ddb6SLionel Sambuc return 1;
106*4684ddb6SLionel Sambuc if (test__fixunsxfdi(0x1.0000000000000000p+63L, 0x8000000000000000LL))
107*4684ddb6SLionel Sambuc return 1;
108*4684ddb6SLionel Sambuc if (test__fixunsxfdi(0x1.FFFFFFFFFFFFFFFCp+62L, 0x7FFFFFFFFFFFFFFFLL))
109*4684ddb6SLionel Sambuc return 1;
110*4684ddb6SLionel Sambuc if (test__fixunsxfdi(0x1.FFFFFFFFFFFFFFF8p+62L, 0x7FFFFFFFFFFFFFFELL))
111*4684ddb6SLionel Sambuc return 1;
112*4684ddb6SLionel Sambuc
113*4684ddb6SLionel Sambuc if (test__fixunsxfdi(-0x1.0000000000000000p+63L, 0))
114*4684ddb6SLionel Sambuc return 1;
115*4684ddb6SLionel Sambuc if (test__fixunsxfdi(-0x1.FFFFFFFFFFFFFFFCp+62L, 0))
116*4684ddb6SLionel Sambuc return 1;
117*4684ddb6SLionel Sambuc if (test__fixunsxfdi(-0x1.FFFFFFFFFFFFFFF8p+62L, 0))
118*4684ddb6SLionel Sambuc return 1;
119*4684ddb6SLionel Sambuc
120*4684ddb6SLionel Sambuc #else
121*4684ddb6SLionel Sambuc printf("skipped\n");
122*4684ddb6SLionel Sambuc #endif
123*4684ddb6SLionel Sambuc return 0;
124*4684ddb6SLionel Sambuc }
125