1// RUN: %clang_builtins %s %librt -o %t && %run %t
2// REQUIRES: librt_has_ucmpti2
3// REQUIRES: int128
4
5#include "int_lib.h"
6#include <stdio.h>
7
8#ifdef CRT_HAS_128BIT
9
10// Returns: if (a < b) returns 0
11// if (a == b) returns 1
12// if (a > b) returns 2
13
14COMPILER_RT_ABI si_int __ucmpti2(tu_int a, tu_int b);
15
16int test__ucmpti2(tu_int a, tu_int b, si_int expected)
17{
18 si_int x = __ucmpti2(a, b);
19 if (x != expected)
20 {
21 utwords at;
22 at.all = a;
23 utwords bt;
24 bt.all = b;
25 printf(format: "error in __ucmpti2(0x%.16llX%.16llX, 0x%.16llX%.16llX) = %d, "
26 "expected %d\n",
27 at.s.high, at.s.low, bt.s.high, bt.s.low, x, expected);
28 }
29 return x != expected;
30}
31
32#endif
33
34int main()
35{
36#ifdef CRT_HAS_128BIT
37 if (test__ucmpti2(a: 0, b: 0, expected: 1))
38 return 1;
39 if (test__ucmpti2(a: 1, b: 1, expected: 1))
40 return 1;
41 if (test__ucmpti2(a: 2, b: 2, expected: 1))
42 return 1;
43 if (test__ucmpti2(a: 0x7FFFFFFF, b: 0x7FFFFFFF, expected: 1))
44 return 1;
45 if (test__ucmpti2(a: 0x80000000, b: 0x80000000, expected: 1))
46 return 1;
47 if (test__ucmpti2(a: 0x80000001, b: 0x80000001, expected: 1))
48 return 1;
49 if (test__ucmpti2(a: 0xFFFFFFFF, b: 0xFFFFFFFF, expected: 1))
50 return 1;
51 if (test__ucmpti2(a: 0x000000010000000LL, b: 0x000000010000000LL, expected: 1))
52 return 1;
53 if (test__ucmpti2(a: 0xFFFFFFFFFFFFFFFFLL, b: 0xFFFFFFFFFFFFFFFFLL, expected: 1))
54 return 1;
55
56 if (test__ucmpti2(a: 0x0000000200000002LL, b: 0x0000000300000001LL, expected: 0))
57 return 1;
58 if (test__ucmpti2(a: 0x0000000200000002LL, b: 0x0000000300000002LL, expected: 0))
59 return 1;
60 if (test__ucmpti2(a: 0x0000000200000002LL, b: 0x0000000300000003LL, expected: 0))
61 return 1;
62
63 if (test__ucmpti2(a: 0x0000000200000002LL, b: 0x0000000100000001LL, expected: 2))
64 return 1;
65 if (test__ucmpti2(a: 0x0000000200000002LL, b: 0x0000000100000002LL, expected: 2))
66 return 1;
67 if (test__ucmpti2(a: 0x0000000200000002LL, b: 0x0000000100000003LL, expected: 2))
68 return 1;
69
70 if (test__ucmpti2(a: 0x0000000200000002LL, b: 0x0000000200000001LL, expected: 2))
71 return 1;
72 if (test__ucmpti2(a: 0x0000000200000002LL, b: 0x0000000200000002LL, expected: 1))
73 return 1;
74 if (test__ucmpti2(a: 0x0000000200000002LL, b: 0x0000000200000003LL, expected: 0))
75 return 1;
76
77 if (test__ucmpti2(a: make_tu(h: 0x0000000000000001uLL, l: 0x0000000000000000uLL),
78 b: make_tu(h: 0x0000000000000000uLL, l: 0xFFFFFFFFFFFFFFFFuLL), expected: 2))
79 return 1;
80 if (test__ucmpti2(a: make_tu(h: 0x0000000000000001uLL, l: 0x0000000000000000uLL),
81 b: make_tu(h: 0x0000000000000001uLL, l: 0x0000000000000000uLL), expected: 1))
82 return 1;
83 if (test__ucmpti2(a: make_tu(h: 0x0000000000000001uLL, l: 0x0000000000000000uLL),
84 b: make_tu(h: 0x0000000000000001uLL, l: 0x0000000000000001uLL), expected: 0))
85 return 1;
86
87 if (test__ucmpti2(a: make_tu(h: 0x8000000000000000uLL, l: 0x0000000000000000uLL),
88 b: make_tu(h: 0x7FFFFFFFFFFFFFFFuLL, l: 0xFFFFFFFFFFFFFFFFuLL), expected: 2))
89 return 1;
90 if (test__ucmpti2(a: make_tu(h: 0x8000000000000000uLL, l: 0x0000000000000000uLL),
91 b: make_tu(h: 0x8000000000000000uLL, l: 0x0000000000000000uLL), expected: 1))
92 return 1;
93 if (test__ucmpti2(a: make_tu(h: 0x8000000000000000uLL, l: 0x0000000000000000uLL),
94 b: make_tu(h: 0x8000000000000000uLL, l: 0x0000000000000001uLL), expected: 0))
95 return 1;
96
97 if (test__ucmpti2(a: make_tu(h: 0xFFFFFFFFFFFFFFFFuLL, l: 0xFFFFFFFFFFFFFFFFuLL),
98 b: make_tu(h: 0xFFFFFFFFFFFFFFFFuLL, l: 0xFFFFFFFFFFFFFFFEuLL), expected: 2))
99 return 1;
100 if (test__ucmpti2(a: make_tu(h: 0xFFFFFFFFFFFFFFFFuLL, l: 0xFFFFFFFFFFFFFFFFuLL),
101 b: make_tu(h: 0xFFFFFFFFFFFFFFFFuLL, l: 0xFFFFFFFFFFFFFFFFuLL), expected: 1))
102 return 1;
103#else
104 printf("skipped\n");
105#endif
106 return 0;
107}
108

source code of compiler-rt/test/builtins/Unit/ucmpti2_test.c