• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- fixunsxfsi_test.c - Test __fixunsxfsi -----------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file tests __fixunsxfsi for the compiler_rt library.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "int_lib.h"
15 #include <stdio.h>
16 
17 #if HAS_80_BIT_LONG_DOUBLE
18 // Returns: convert a to a unsigned int, rounding toward zero.
19 //          Negative values all become zero.
20 
21 // Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
22 //             su_int is a 32 bit integral type
23 //             value in long double is representable in su_int or is negative
24 //                 (no range checking performed)
25 
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
28 
29 COMPILER_RT_ABI su_int __fixunsxfsi(long double a);
30 
test__fixunsxfsi(long double a,su_int expected)31 int test__fixunsxfsi(long double a, su_int expected)
32 {
33     su_int x = __fixunsxfsi(a);
34     if (x != expected)
35         printf("error in __fixunsxfsi(%LA) = %X, expected %X\n", a, x, expected);
36     return x != expected;
37 }
38 
39 char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0};
40 char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
41 #endif
42 
main()43 int main()
44 {
45 #if HAS_80_BIT_LONG_DOUBLE
46     if (test__fixunsxfsi(0.0, 0))
47         return 1;
48 
49     if (test__fixunsxfsi(0.5, 0))
50         return 1;
51     if (test__fixunsxfsi(0.99, 0))
52         return 1;
53     if (test__fixunsxfsi(1.0, 1))
54         return 1;
55     if (test__fixunsxfsi(1.5, 1))
56         return 1;
57     if (test__fixunsxfsi(1.99, 1))
58         return 1;
59     if (test__fixunsxfsi(2.0, 2))
60         return 1;
61     if (test__fixunsxfsi(2.01, 2))
62         return 1;
63     if (test__fixunsxfsi(-0.5, 0))
64         return 1;
65     if (test__fixunsxfsi(-0.99, 0))
66         return 1;
67 #if !TARGET_LIBGCC
68     if (test__fixunsxfsi(-1.0, 0))  // libgcc ignores "returns 0 for negative input" spec
69         return 1;
70     if (test__fixunsxfsi(-1.5, 0))
71         return 1;
72     if (test__fixunsxfsi(-1.99, 0))
73         return 1;
74     if (test__fixunsxfsi(-2.0, 0))
75         return 1;
76     if (test__fixunsxfsi(-2.01, 0))
77         return 1;
78 #endif
79 
80     if (test__fixunsxfsi(0x1.000000p+31, 0x80000000))
81         return 1;
82     if (test__fixunsxfsi(0x1.FFFFFEp+31, 0xFFFFFF00))
83         return 1;
84     if (test__fixunsxfsi(0x1.FFFFFEp+30, 0x7FFFFF80))
85         return 1;
86     if (test__fixunsxfsi(0x1.FFFFFCp+30, 0x7FFFFF00))
87         return 1;
88 
89 #if !TARGET_LIBGCC
90     if (test__fixunsxfsi(-0x1.FFFFFEp+30, 0))
91         return 1;
92     if (test__fixunsxfsi(-0x1.FFFFFCp+30, 0))
93         return 1;
94 #endif
95 
96     if (test__fixunsxfsi(0x1.FFFFFFFEp+31, 0xFFFFFFFF))
97         return 1;
98     if (test__fixunsxfsi(0x1.FFFFFFFC00000p+30, 0x7FFFFFFF))
99         return 1;
100     if (test__fixunsxfsi(0x1.FFFFFFF800000p+30, 0x7FFFFFFE))
101         return 1;
102 
103 #endif
104    return 0;
105 }
106