xref: /minix3/sys/external/bsd/compiler_rt/dist/test/Unit/fixunsxfsi_test.c (revision 4684ddb6aab0b36791c8099bc705d6140b3d05d0)
1*4684ddb6SLionel Sambuc //===-- fixunsxfsi_test.c - Test __fixunsxfsi -----------------------------===//
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 __fixunsxfsi 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 
17*4684ddb6SLionel Sambuc #if HAS_80_BIT_LONG_DOUBLE
18*4684ddb6SLionel Sambuc // Returns: convert a to a unsigned int, rounding toward zero.
19*4684ddb6SLionel Sambuc //          Negative values all become zero.
20*4684ddb6SLionel Sambuc 
21*4684ddb6SLionel Sambuc // Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
22*4684ddb6SLionel Sambuc //             su_int is a 32 bit integral type
23*4684ddb6SLionel Sambuc //             value in long double is representable in su_int or is negative
24*4684ddb6SLionel Sambuc //                 (no range checking performed)
25*4684ddb6SLionel Sambuc 
26*4684ddb6SLionel Sambuc // gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
27*4684ddb6SLionel Sambuc // 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
28*4684ddb6SLionel Sambuc 
29*4684ddb6SLionel Sambuc su_int __fixunsxfsi(long double a);
30*4684ddb6SLionel Sambuc 
test__fixunsxfsi(long double a,su_int expected)31*4684ddb6SLionel Sambuc int test__fixunsxfsi(long double a, su_int expected)
32*4684ddb6SLionel Sambuc {
33*4684ddb6SLionel Sambuc     su_int x = __fixunsxfsi(a);
34*4684ddb6SLionel Sambuc     if (x != expected)
35*4684ddb6SLionel Sambuc         printf("error in __fixunsxfsi(%LA) = %X, expected %X\n", a, x, expected);
36*4684ddb6SLionel Sambuc     return x != expected;
37*4684ddb6SLionel Sambuc }
38*4684ddb6SLionel Sambuc 
39*4684ddb6SLionel Sambuc char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0};
40*4684ddb6SLionel Sambuc char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
41*4684ddb6SLionel Sambuc #endif
42*4684ddb6SLionel Sambuc 
main()43*4684ddb6SLionel Sambuc int main()
44*4684ddb6SLionel Sambuc {
45*4684ddb6SLionel Sambuc #if HAS_80_BIT_LONG_DOUBLE
46*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(0.0, 0))
47*4684ddb6SLionel Sambuc         return 1;
48*4684ddb6SLionel Sambuc 
49*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(0.5, 0))
50*4684ddb6SLionel Sambuc         return 1;
51*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(0.99, 0))
52*4684ddb6SLionel Sambuc         return 1;
53*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(1.0, 1))
54*4684ddb6SLionel Sambuc         return 1;
55*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(1.5, 1))
56*4684ddb6SLionel Sambuc         return 1;
57*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(1.99, 1))
58*4684ddb6SLionel Sambuc         return 1;
59*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(2.0, 2))
60*4684ddb6SLionel Sambuc         return 1;
61*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(2.01, 2))
62*4684ddb6SLionel Sambuc         return 1;
63*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(-0.5, 0))
64*4684ddb6SLionel Sambuc         return 1;
65*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(-0.99, 0))
66*4684ddb6SLionel Sambuc         return 1;
67*4684ddb6SLionel Sambuc #if !TARGET_LIBGCC
68*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(-1.0, 0))  // libgcc ignores "returns 0 for negative input" spec
69*4684ddb6SLionel Sambuc         return 1;
70*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(-1.5, 0))
71*4684ddb6SLionel Sambuc         return 1;
72*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(-1.99, 0))
73*4684ddb6SLionel Sambuc         return 1;
74*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(-2.0, 0))
75*4684ddb6SLionel Sambuc         return 1;
76*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(-2.01, 0))
77*4684ddb6SLionel Sambuc         return 1;
78*4684ddb6SLionel Sambuc #endif
79*4684ddb6SLionel Sambuc 
80*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(0x1.000000p+31, 0x80000000))
81*4684ddb6SLionel Sambuc         return 1;
82*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(0x1.FFFFFEp+31, 0xFFFFFF00))
83*4684ddb6SLionel Sambuc         return 1;
84*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(0x1.FFFFFEp+30, 0x7FFFFF80))
85*4684ddb6SLionel Sambuc         return 1;
86*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(0x1.FFFFFCp+30, 0x7FFFFF00))
87*4684ddb6SLionel Sambuc         return 1;
88*4684ddb6SLionel Sambuc 
89*4684ddb6SLionel Sambuc #if !TARGET_LIBGCC
90*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(-0x1.FFFFFEp+30, 0))
91*4684ddb6SLionel Sambuc         return 1;
92*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(-0x1.FFFFFCp+30, 0))
93*4684ddb6SLionel Sambuc         return 1;
94*4684ddb6SLionel Sambuc #endif
95*4684ddb6SLionel Sambuc 
96*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(0x1.FFFFFFFEp+31, 0xFFFFFFFF))
97*4684ddb6SLionel Sambuc         return 1;
98*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(0x1.FFFFFFFC00000p+30, 0x7FFFFFFF))
99*4684ddb6SLionel Sambuc         return 1;
100*4684ddb6SLionel Sambuc     if (test__fixunsxfsi(0x1.FFFFFFF800000p+30, 0x7FFFFFFE))
101*4684ddb6SLionel Sambuc         return 1;
102*4684ddb6SLionel Sambuc 
103*4684ddb6SLionel Sambuc #endif
104*4684ddb6SLionel Sambuc    return 0;
105*4684ddb6SLionel Sambuc }
106