[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / fixunsdfdi_test.c
blob770cb2ffee689d9f476081948044c1f2b7a87de0
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_fixunsdfdi
3 //===-- fixunsdfdi_test.c - Test __fixunsdfdi -----------------------------===//
4 //
5 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 // See https://llvm.org/LICENSE.txt for license information.
7 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //
9 //===----------------------------------------------------------------------===//
11 // This file tests __fixunsdfdi for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
15 #include "int_lib.h"
16 #include <stdio.h>
18 // Returns: convert a to a unsigned long long, rounding toward zero.
19 // Negative values all become zero.
21 // Assumption: double is a IEEE 64 bit floating point type
22 // du_int is a 64 bit integral type
23 // value in double is representable in du_int or is negative
24 // (no range checking performed)
26 // seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
28 COMPILER_RT_ABI du_int __fixunsdfdi(double a);
30 int test__fixunsdfdi(double a, du_int expected)
32 du_int x = __fixunsdfdi(a);
33 if (x != expected)
34 printf("error in __fixunsdfdi(%A) = %llX, expected %llX\n", a, x, expected);
35 return x != expected;
38 char assumption_1[sizeof(du_int) == 2*sizeof(su_int)] = {0};
39 char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0};
40 char assumption_3[sizeof(double)*CHAR_BIT == 64] = {0};
42 int main()
44 if (test__fixunsdfdi(0.0, 0))
45 return 1;
47 if (test__fixunsdfdi(0.5, 0))
48 return 1;
49 if (test__fixunsdfdi(0.99, 0))
50 return 1;
51 if (test__fixunsdfdi(1.0, 1))
52 return 1;
53 if (test__fixunsdfdi(1.5, 1))
54 return 1;
55 if (test__fixunsdfdi(1.99, 1))
56 return 1;
57 if (test__fixunsdfdi(2.0, 2))
58 return 1;
59 if (test__fixunsdfdi(2.01, 2))
60 return 1;
61 if (test__fixunsdfdi(-0.5, 0))
62 return 1;
63 if (test__fixunsdfdi(-0.99, 0))
64 return 1;
65 #if !TARGET_LIBGCC
66 if (test__fixunsdfdi(-1.0, 0)) // libgcc ignores "returns 0 for negative input" spec
67 return 1;
68 if (test__fixunsdfdi(-1.5, 0))
69 return 1;
70 if (test__fixunsdfdi(-1.99, 0))
71 return 1;
72 if (test__fixunsdfdi(-2.0, 0))
73 return 1;
74 if (test__fixunsdfdi(-2.01, 0))
75 return 1;
76 #endif
78 if (test__fixunsdfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000LL))
79 return 1;
80 if (test__fixunsdfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000LL))
81 return 1;
83 #if !TARGET_LIBGCC
84 if (test__fixunsdfdi(-0x1.FFFFFEp+62, 0))
85 return 1;
86 if (test__fixunsdfdi(-0x1.FFFFFCp+62, 0))
87 return 1;
88 #endif
90 if (test__fixunsdfdi(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800LL))
91 return 1;
92 if (test__fixunsdfdi(0x1.0000000000000p+63, 0x8000000000000000LL))
93 return 1;
94 if (test__fixunsdfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00LL))
95 return 1;
96 if (test__fixunsdfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL))
97 return 1;
99 #if !TARGET_LIBGCC
100 if (test__fixunsdfdi(-0x1.FFFFFFFFFFFFFp+62, 0))
101 return 1;
102 if (test__fixunsdfdi(-0x1.FFFFFFFFFFFFEp+62, 0))
103 return 1;
104 #endif
106 return 0;