[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / ucmpti2_test.c
blobdb61b949ba63ea0992d508ac825e3652a824bb0e
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_ucmpti2
3 // REQUIRES: int128
4 //===-- ucmpti2_test.c - Test __ucmpti2 -----------------------------------===//
5 //
6 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
7 // See https://llvm.org/LICENSE.txt for license information.
8 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 //
10 //===----------------------------------------------------------------------===//
12 // This file tests __ucmpti2 for the compiler_rt library.
14 //===----------------------------------------------------------------------===//
16 #include "int_lib.h"
17 #include <stdio.h>
19 #ifdef CRT_HAS_128BIT
21 // Returns: if (a < b) returns 0
22 // if (a == b) returns 1
23 // if (a > b) returns 2
25 COMPILER_RT_ABI si_int __ucmpti2(tu_int a, tu_int b);
27 int test__ucmpti2(tu_int a, tu_int b, si_int expected)
29 si_int x = __ucmpti2(a, b);
30 if (x != expected)
32 utwords at;
33 at.all = a;
34 utwords bt;
35 bt.all = b;
36 printf("error in __ucmpti2(0x%.16llX%.16llX, 0x%.16llX%.16llX) = %d, "
37 "expected %d\n",
38 at.s.high, at.s.low, bt.s.high, bt.s.low, x, expected);
40 return x != expected;
43 #endif
45 int main()
47 #ifdef CRT_HAS_128BIT
48 if (test__ucmpti2(0, 0, 1))
49 return 1;
50 if (test__ucmpti2(1, 1, 1))
51 return 1;
52 if (test__ucmpti2(2, 2, 1))
53 return 1;
54 if (test__ucmpti2(0x7FFFFFFF, 0x7FFFFFFF, 1))
55 return 1;
56 if (test__ucmpti2(0x80000000, 0x80000000, 1))
57 return 1;
58 if (test__ucmpti2(0x80000001, 0x80000001, 1))
59 return 1;
60 if (test__ucmpti2(0xFFFFFFFF, 0xFFFFFFFF, 1))
61 return 1;
62 if (test__ucmpti2(0x000000010000000LL, 0x000000010000000LL, 1))
63 return 1;
64 if (test__ucmpti2(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL, 1))
65 return 1;
67 if (test__ucmpti2(0x0000000200000002LL, 0x0000000300000001LL, 0))
68 return 1;
69 if (test__ucmpti2(0x0000000200000002LL, 0x0000000300000002LL, 0))
70 return 1;
71 if (test__ucmpti2(0x0000000200000002LL, 0x0000000300000003LL, 0))
72 return 1;
74 if (test__ucmpti2(0x0000000200000002LL, 0x0000000100000001LL, 2))
75 return 1;
76 if (test__ucmpti2(0x0000000200000002LL, 0x0000000100000002LL, 2))
77 return 1;
78 if (test__ucmpti2(0x0000000200000002LL, 0x0000000100000003LL, 2))
79 return 1;
81 if (test__ucmpti2(0x0000000200000002LL, 0x0000000200000001LL, 2))
82 return 1;
83 if (test__ucmpti2(0x0000000200000002LL, 0x0000000200000002LL, 1))
84 return 1;
85 if (test__ucmpti2(0x0000000200000002LL, 0x0000000200000003LL, 0))
86 return 1;
88 if (test__ucmpti2(make_tu(0x0000000000000001uLL, 0x0000000000000000uLL),
89 make_tu(0x0000000000000000uLL, 0xFFFFFFFFFFFFFFFFuLL), 2))
90 return 1;
91 if (test__ucmpti2(make_tu(0x0000000000000001uLL, 0x0000000000000000uLL),
92 make_tu(0x0000000000000001uLL, 0x0000000000000000uLL), 1))
93 return 1;
94 if (test__ucmpti2(make_tu(0x0000000000000001uLL, 0x0000000000000000uLL),
95 make_tu(0x0000000000000001uLL, 0x0000000000000001uLL), 0))
96 return 1;
98 if (test__ucmpti2(make_tu(0x8000000000000000uLL, 0x0000000000000000uLL),
99 make_tu(0x7FFFFFFFFFFFFFFFuLL, 0xFFFFFFFFFFFFFFFFuLL), 2))
100 return 1;
101 if (test__ucmpti2(make_tu(0x8000000000000000uLL, 0x0000000000000000uLL),
102 make_tu(0x8000000000000000uLL, 0x0000000000000000uLL), 1))
103 return 1;
104 if (test__ucmpti2(make_tu(0x8000000000000000uLL, 0x0000000000000000uLL),
105 make_tu(0x8000000000000000uLL, 0x0000000000000001uLL), 0))
106 return 1;
108 if (test__ucmpti2(make_tu(0xFFFFFFFFFFFFFFFFuLL, 0xFFFFFFFFFFFFFFFFuLL),
109 make_tu(0xFFFFFFFFFFFFFFFFuLL, 0xFFFFFFFFFFFFFFFEuLL), 2))
110 return 1;
111 if (test__ucmpti2(make_tu(0xFFFFFFFFFFFFFFFFuLL, 0xFFFFFFFFFFFFFFFFuLL),
112 make_tu(0xFFFFFFFFFFFFFFFFuLL, 0xFFFFFFFFFFFFFFFFuLL), 1))
113 return 1;
114 #else
115 printf("skipped\n");
116 #endif
117 return 0;