blob: 28a7e9783c53357f126923fc2cadcd1004db01b4 [file] [log] [blame]
Weiming Zhao9b7bbec2017-03-21 05:32:51 +00001// RUN: %clang_builtins %s %librt -o %t && %run %t
2// XFAIL: aarch64
3// test fails for aarch64 (see pr32260)
4
Daniel Dunbarfd089992009-06-26 16:47:03 +00005//===-- fixunsxfti_test.c - Test __fixunsxfti -----------------------------===//
6//
7// The LLVM Compiler Infrastructure
8//
Howard Hinnant5b791f62010-11-16 22:13:33 +00009// This file is dual licensed under the MIT and the University of Illinois Open
10// Source Licenses. See LICENSE.TXT for details.
Daniel Dunbarfd089992009-06-26 16:47:03 +000011//
12//===----------------------------------------------------------------------===//
13//
14// This file tests __fixunsxfti for the compiler_rt library.
15//
16//===----------------------------------------------------------------------===//
17
Daniel Dunbarfd089992009-06-26 16:47:03 +000018#include "int_lib.h"
19#include <stdio.h>
20
Joerg Sonnenberger14743122014-03-18 21:35:30 +000021#ifdef CRT_HAS_128BIT
22
Daniel Dunbarfd089992009-06-26 16:47:03 +000023// Returns: convert a to a unsigned long long, rounding toward zero.
24// Negative values all become zero.
25
26// Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
27// tu_int is a 64 bit integral type
28// value in long double is representable in tu_int or is negative
29// (no range checking performed)
30
31// gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
32// 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
33
Derek Schuffeb0ebc32015-04-24 15:45:57 +000034COMPILER_RT_ABI tu_int __fixunsxfti(long double a);
Daniel Dunbarfd089992009-06-26 16:47:03 +000035
36int test__fixunsxfti(long double a, tu_int expected)
37{
38 tu_int x = __fixunsxfti(a);
39 if (x != expected)
40 {
41 utwords xt;
42 xt.all = x;
43 utwords expectedt;
44 expectedt.all = expected;
45 printf("error in __fixunsxfti(%LA) = 0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
Daniel Dunbar64857202009-10-27 17:49:07 +000046 a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low);
Daniel Dunbarfd089992009-06-26 16:47:03 +000047 }
48 return x != expected;
49}
50
51char assumption_1[sizeof(tu_int) == 2*sizeof(du_int)] = {0};
52char assumption_2[sizeof(tu_int)*CHAR_BIT == 128] = {0};
53char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
54
55#endif
56
57int main()
58{
Joerg Sonnenberger14743122014-03-18 21:35:30 +000059#ifdef CRT_HAS_128BIT
Daniel Dunbarfd089992009-06-26 16:47:03 +000060 if (test__fixunsxfti(0.0, 0))
61 return 1;
62
63 if (test__fixunsxfti(0.5, 0))
64 return 1;
65 if (test__fixunsxfti(0.99, 0))
66 return 1;
67 if (test__fixunsxfti(1.0, 1))
68 return 1;
69 if (test__fixunsxfti(1.5, 1))
70 return 1;
71 if (test__fixunsxfti(1.99, 1))
72 return 1;
73 if (test__fixunsxfti(2.0, 2))
74 return 1;
75 if (test__fixunsxfti(2.01, 2))
76 return 1;
77 if (test__fixunsxfti(-0.5, 0))
78 return 1;
79 if (test__fixunsxfti(-0.99, 0))
80 return 1;
81 if (test__fixunsxfti(-1.0, 0))
82 return 1;
83 if (test__fixunsxfti(-1.5, 0))
84 return 1;
85 if (test__fixunsxfti(-1.99, 0))
86 return 1;
87 if (test__fixunsxfti(-2.0, 0))
88 return 1;
89 if (test__fixunsxfti(-2.01, 0))
90 return 1;
91
92 if (test__fixunsxfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000LL))
93 return 1;
94 if (test__fixunsxfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000LL))
95 return 1;
96
97 if (test__fixunsxfti(-0x1.FFFFFEp+62, 0))
98 return 1;
99 if (test__fixunsxfti(-0x1.FFFFFCp+62, 0))
100 return 1;
101
102 if (test__fixunsxfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00LL))
103 return 1;
104 if (test__fixunsxfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL))
105 return 1;
106
107 if (test__fixunsxfti(-0x1.FFFFFFFFFFFFFp+62, 0))
108 return 1;
109 if (test__fixunsxfti(-0x1.FFFFFFFFFFFFEp+62, 0))
110 return 1;
111
112 if (test__fixunsxfti(0x1.FFFFFFFFFFFFFFFEp+63L, 0xFFFFFFFFFFFFFFFFLL))
113 return 1;
114 if (test__fixunsxfti(0x1.0000000000000002p+63L, 0x8000000000000001LL))
115 return 1;
116 if (test__fixunsxfti(0x1.0000000000000000p+63L, 0x8000000000000000LL))
117 return 1;
118 if (test__fixunsxfti(0x1.FFFFFFFFFFFFFFFCp+62L, 0x7FFFFFFFFFFFFFFFLL))
119 return 1;
120 if (test__fixunsxfti(0x1.FFFFFFFFFFFFFFF8p+62L, 0x7FFFFFFFFFFFFFFELL))
121 return 1;
122
123 if (test__fixunsxfti(-0x1.0000000000000000p+63L, 0))
124 return 1;
125 if (test__fixunsxfti(-0x1.FFFFFFFFFFFFFFFCp+62L, 0))
126 return 1;
127 if (test__fixunsxfti(-0x1.FFFFFFFFFFFFFFF8p+62L, 0))
128 return 1;
129
130 if (test__fixunsxfti(0x1.FFFFFFFFFFFFFFFEp+127L, make_ti(0xFFFFFFFFFFFFFFFFLL, 0)))
131 return 1;
132 if (test__fixunsxfti(0x1.0000000000000002p+127L, make_ti(0x8000000000000001LL, 0)))
133 return 1;
134 if (test__fixunsxfti(0x1.0000000000000000p+127L, make_ti(0x8000000000000000LL, 0)))
135 return 1;
136 if (test__fixunsxfti(0x1.FFFFFFFFFFFFFFFCp+126L, make_ti(0x7FFFFFFFFFFFFFFFLL, 0)))
137 return 1;
138 if (test__fixunsxfti(0x1.FFFFFFFFFFFFFFF8p+126L, make_ti(0x7FFFFFFFFFFFFFFELL, 0)))
139 return 1;
140
Joerg Sonnenbergerd9bcddd2011-05-29 21:43:29 +0000141#else
142 printf("skipped\n");
Daniel Dunbarfd089992009-06-26 16:47:03 +0000143#endif
144 return 0;
145}