]> git.proxmox.com Git - rustc.git/blame - src/libcompiler_builtins/compiler-rt/test/builtins/Unit/fixunstfti_test.c
New upstream version 1.25.0+dfsg1
[rustc.git] / src / libcompiler_builtins / compiler-rt / test / builtins / Unit / fixunstfti_test.c
CommitLineData
2c00a5a8 1// RUN: %clang_builtins %s %librt -o %t && %run %t
92a42be0
SL
2//===-- fixunstfti_test.c - Test __fixunstfti -----------------------------===//
3//
4// The LLVM Compiler Infrastructure
5//
6// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10//
11// This file tests __fixunstfti for the compiler_rt library.
12//
13//===----------------------------------------------------------------------===//
14
15#include <stdio.h>
16
2c00a5a8
XL
17// UNSUPPORTED: mips
18
92a42be0
SL
19#if __LDBL_MANT_DIG__ == 113
20
21#include "fp_test.h"
22#include "int_lib.h"
23
24// Returns: convert a to a unsigned long long, rounding toward zero.
25// Negative values all become zero.
26
27// Assumption: long double is a 128 bit floating point type
28// tu_int is a 128 bit integral type
29// value in long double is representable in tu_int or is negative
30// (no range checking performed)
31
32COMPILER_RT_ABI tu_int __fixunstfti(long double a);
33
34int test__fixunstfti(long double a, tu_int expected)
35{
36 tu_int x = __fixunstfti(a);
37 if (x != expected)
38 {
39 twords xt;
40 xt.all = x;
41
42 twords expectedt;
43 expectedt.all = expected;
44
45 printf("error in __fixunstfti(%.20Lf) = 0x%.16llX%.16llX, "
46 "expected 0x%.16llX%.16llX\n",
47 a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low);
48 }
49 return x != expected;
50}
51
52char assumption_1[sizeof(tu_int) == 4*sizeof(su_int)] = {0};
53char assumption_2[sizeof(tu_int)*CHAR_BIT == 128] = {0};
54char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
55
56#endif
57
58int main()
59{
60#if __LDBL_MANT_DIG__ == 113
61 if (test__fixunstfti(makeInf128(), make_ti(0xffffffffffffffffLL,
62 0xffffffffffffffffLL)))
63 return 1;
64
65 if (test__fixunstfti(0.0, 0))
66 return 1;
67
68 if (test__fixunstfti(0.5, 0))
69 return 1;
70 if (test__fixunstfti(0.99, 0))
71 return 1;
72 if (test__fixunstfti(1.0, 1))
73 return 1;
74 if (test__fixunstfti(1.5, 1))
75 return 1;
76 if (test__fixunstfti(1.99, 1))
77 return 1;
78 if (test__fixunstfti(2.0, 2))
79 return 1;
80 if (test__fixunstfti(2.01, 2))
81 return 1;
82 if (test__fixunstfti(-0.01, 0))
83 return 1;
84 if (test__fixunstfti(-0.99, 0))
85 return 1;
86
87 if (test__fixunstfti(0x1.p+128, make_ti(0xffffffffffffffffLL,
88 0xffffffffffffffffLL)))
89 return 1;
90
91 if (test__fixunstfti(0x1.FFFFFEp+126, make_ti(0x7fffff8000000000LL, 0x0)))
92 return 1;
93 if (test__fixunstfti(0x1.FFFFFEp+127, make_ti(0xffffff0000000000LL, 0x0)))
94 return 1;
95 if (test__fixunstfti(0x1.FFFFFEp+128, make_ti(0xffffffffffffffffLL,
96 0xffffffffffffffffLL)))
97 return 1;
98 if (test__fixunstfti(0x1.FFFFFEp+129, make_ti(0xffffffffffffffffLL,
99 0xffffffffffffffffLL)))
100 return 1;
101
102#else
103 printf("skipped\n");
104#endif
105 return 0;
106}