xref: /minix3/sys/external/bsd/compiler_rt/dist/test/Unit/fixunstfdi_test.c (revision 4684ddb6aab0b36791c8099bc705d6140b3d05d0)
1*4684ddb6SLionel Sambuc //===-- fixunstfdi_test.c - Test __fixunstfdi -----------------------------===//
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 __fixunstfdi for the compiler_rt library.
11*4684ddb6SLionel Sambuc //
12*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
13*4684ddb6SLionel Sambuc 
14*4684ddb6SLionel Sambuc #if _ARCH_PPC
15*4684ddb6SLionel Sambuc 
16*4684ddb6SLionel Sambuc #include "int_lib.h"
17*4684ddb6SLionel Sambuc #include <stdio.h>
18*4684ddb6SLionel Sambuc 
19*4684ddb6SLionel Sambuc // Returns: convert a to a unsigned long long, rounding toward zero.
20*4684ddb6SLionel Sambuc //          Negative values all become zero.
21*4684ddb6SLionel Sambuc 
22*4684ddb6SLionel Sambuc // Assumption: long double is a ppc 128 bit floating point type
23*4684ddb6SLionel Sambuc //             du_int is a 64 bit integral type
24*4684ddb6SLionel Sambuc //             value in long double is representable in du_int or is negative
25*4684ddb6SLionel Sambuc //                 (no range checking performed)
26*4684ddb6SLionel Sambuc 
27*4684ddb6SLionel Sambuc du_int __fixunstfdi(long double a);
28*4684ddb6SLionel Sambuc 
test__fixunstfdi(long double a,du_int expected)29*4684ddb6SLionel Sambuc int test__fixunstfdi(long double a, du_int expected)
30*4684ddb6SLionel Sambuc {
31*4684ddb6SLionel Sambuc     du_int x = __fixunstfdi(a);
32*4684ddb6SLionel Sambuc     if (x != expected)
33*4684ddb6SLionel Sambuc         printf("error in __fixunstfdi(%LA) = %llX, expected %llX\n",
34*4684ddb6SLionel Sambuc                a, x, expected);
35*4684ddb6SLionel Sambuc     return x != expected;
36*4684ddb6SLionel Sambuc }
37*4684ddb6SLionel Sambuc 
38*4684ddb6SLionel Sambuc char assumption_1[sizeof(du_int) == 2*sizeof(su_int)] = {0};
39*4684ddb6SLionel Sambuc char assumption_2[sizeof(du_int)*CHAR_BIT == 64] = {0};
40*4684ddb6SLionel Sambuc char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
41*4684ddb6SLionel Sambuc 
42*4684ddb6SLionel Sambuc #endif
43*4684ddb6SLionel Sambuc 
main()44*4684ddb6SLionel Sambuc int main()
45*4684ddb6SLionel Sambuc {
46*4684ddb6SLionel Sambuc #if _ARCH_PPC
47*4684ddb6SLionel Sambuc     if (test__fixunstfdi(0.0, 0))
48*4684ddb6SLionel Sambuc         return 1;
49*4684ddb6SLionel Sambuc 
50*4684ddb6SLionel Sambuc     if (test__fixunstfdi(0.5, 0))
51*4684ddb6SLionel Sambuc         return 1;
52*4684ddb6SLionel Sambuc     if (test__fixunstfdi(0.99, 0))
53*4684ddb6SLionel Sambuc         return 1;
54*4684ddb6SLionel Sambuc     if (test__fixunstfdi(1.0, 1))
55*4684ddb6SLionel Sambuc         return 1;
56*4684ddb6SLionel Sambuc     if (test__fixunstfdi(1.5, 1))
57*4684ddb6SLionel Sambuc         return 1;
58*4684ddb6SLionel Sambuc     if (test__fixunstfdi(1.99, 1))
59*4684ddb6SLionel Sambuc         return 1;
60*4684ddb6SLionel Sambuc     if (test__fixunstfdi(2.0, 2))
61*4684ddb6SLionel Sambuc         return 1;
62*4684ddb6SLionel Sambuc     if (test__fixunstfdi(2.01, 2))
63*4684ddb6SLionel Sambuc         return 1;
64*4684ddb6SLionel Sambuc     if (test__fixunstfdi(-0.5, 0))
65*4684ddb6SLionel Sambuc         return 1;
66*4684ddb6SLionel Sambuc     if (test__fixunstfdi(-0.99, 0))
67*4684ddb6SLionel Sambuc         return 1;
68*4684ddb6SLionel Sambuc     if (test__fixunstfdi(-1.0, 0))
69*4684ddb6SLionel Sambuc         return 1;
70*4684ddb6SLionel Sambuc     if (test__fixunstfdi(-1.5, 0))
71*4684ddb6SLionel Sambuc         return 1;
72*4684ddb6SLionel Sambuc     if (test__fixunstfdi(-1.99, 0))
73*4684ddb6SLionel Sambuc         return 1;
74*4684ddb6SLionel Sambuc     if (test__fixunstfdi(-2.0, 0))
75*4684ddb6SLionel Sambuc         return 1;
76*4684ddb6SLionel Sambuc     if (test__fixunstfdi(-2.01, 0))
77*4684ddb6SLionel Sambuc         return 1;
78*4684ddb6SLionel Sambuc 
79*4684ddb6SLionel Sambuc     if (test__fixunstfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000LL))
80*4684ddb6SLionel Sambuc         return 1;
81*4684ddb6SLionel Sambuc     if (test__fixunstfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000LL))
82*4684ddb6SLionel Sambuc         return 1;
83*4684ddb6SLionel Sambuc 
84*4684ddb6SLionel Sambuc     if (test__fixunstfdi(-0x1.FFFFFEp+62, 0))
85*4684ddb6SLionel Sambuc         return 1;
86*4684ddb6SLionel Sambuc     if (test__fixunstfdi(-0x1.FFFFFCp+62, 0))
87*4684ddb6SLionel Sambuc         return 1;
88*4684ddb6SLionel Sambuc 
89*4684ddb6SLionel Sambuc     if (test__fixunstfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00LL))
90*4684ddb6SLionel Sambuc         return 1;
91*4684ddb6SLionel Sambuc     if (test__fixunstfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL))
92*4684ddb6SLionel Sambuc         return 1;
93*4684ddb6SLionel Sambuc 
94*4684ddb6SLionel Sambuc     if (test__fixunstfdi(-0x1.FFFFFFFFFFFFFp+62, 0))
95*4684ddb6SLionel Sambuc         return 1;
96*4684ddb6SLionel Sambuc     if (test__fixunstfdi(-0x1.FFFFFFFFFFFFEp+62, 0))
97*4684ddb6SLionel Sambuc         return 1;
98*4684ddb6SLionel Sambuc 
99*4684ddb6SLionel Sambuc     if (test__fixunstfdi(0x1.FFFFFFFFFFFFFFFEp+63L, 0xFFFFFFFFFFFFFFFFLL))
100*4684ddb6SLionel Sambuc         return 1;
101*4684ddb6SLionel Sambuc     if (test__fixunstfdi(0x1.0000000000000002p+63L, 0x8000000000000001LL))
102*4684ddb6SLionel Sambuc         return 1;
103*4684ddb6SLionel Sambuc     if (test__fixunstfdi(0x1.0000000000000000p+63L, 0x8000000000000000LL))
104*4684ddb6SLionel Sambuc         return 1;
105*4684ddb6SLionel Sambuc     if (test__fixunstfdi(0x1.FFFFFFFFFFFFFFFCp+62L, 0x7FFFFFFFFFFFFFFFLL))
106*4684ddb6SLionel Sambuc         return 1;
107*4684ddb6SLionel Sambuc     if (test__fixunstfdi(0x1.FFFFFFFFFFFFFFF8p+62L, 0x7FFFFFFFFFFFFFFELL))
108*4684ddb6SLionel Sambuc         return 1;
109*4684ddb6SLionel Sambuc 
110*4684ddb6SLionel Sambuc     if (test__fixunstfdi(-0x1.0000000000000000p+63L, 0))
111*4684ddb6SLionel Sambuc         return 1;
112*4684ddb6SLionel Sambuc     if (test__fixunstfdi(-0x1.FFFFFFFFFFFFFFFCp+62L, 0))
113*4684ddb6SLionel Sambuc         return 1;
114*4684ddb6SLionel Sambuc     if (test__fixunstfdi(-0x1.FFFFFFFFFFFFFFF8p+62L, 0))
115*4684ddb6SLionel Sambuc         return 1;
116*4684ddb6SLionel Sambuc 
117*4684ddb6SLionel Sambuc #else
118*4684ddb6SLionel Sambuc     printf("skipped\n");
119*4684ddb6SLionel Sambuc #endif
120*4684ddb6SLionel Sambuc    return 0;
121*4684ddb6SLionel Sambuc }
122