1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_ucmpti2
4 //===-- ucmpti2_test.c - Test __ucmpti2 -----------------------------------===//
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
10 //===----------------------------------------------------------------------===//
12 // This file tests __ucmpti2 for the compiler_rt library.
14 //===----------------------------------------------------------------------===//
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
);
36 printf("error in __ucmpti2(0x%.16llX%.16llX, 0x%.16llX%.16llX) = %d, "
38 at
.s
.high
, at
.s
.low
, bt
.s
.high
, bt
.s
.low
, x
, expected
);
48 if (test__ucmpti2(0, 0, 1))
50 if (test__ucmpti2(1, 1, 1))
52 if (test__ucmpti2(2, 2, 1))
54 if (test__ucmpti2(0x7FFFFFFF, 0x7FFFFFFF, 1))
56 if (test__ucmpti2(0x80000000, 0x80000000, 1))
58 if (test__ucmpti2(0x80000001, 0x80000001, 1))
60 if (test__ucmpti2(0xFFFFFFFF, 0xFFFFFFFF, 1))
62 if (test__ucmpti2(0x000000010000000LL
, 0x000000010000000LL
, 1))
64 if (test__ucmpti2(0xFFFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
, 1))
67 if (test__ucmpti2(0x0000000200000002LL
, 0x0000000300000001LL
, 0))
69 if (test__ucmpti2(0x0000000200000002LL
, 0x0000000300000002LL
, 0))
71 if (test__ucmpti2(0x0000000200000002LL
, 0x0000000300000003LL
, 0))
74 if (test__ucmpti2(0x0000000200000002LL
, 0x0000000100000001LL
, 2))
76 if (test__ucmpti2(0x0000000200000002LL
, 0x0000000100000002LL
, 2))
78 if (test__ucmpti2(0x0000000200000002LL
, 0x0000000100000003LL
, 2))
81 if (test__ucmpti2(0x0000000200000002LL
, 0x0000000200000001LL
, 2))
83 if (test__ucmpti2(0x0000000200000002LL
, 0x0000000200000002LL
, 1))
85 if (test__ucmpti2(0x0000000200000002LL
, 0x0000000200000003LL
, 0))
88 if (test__ucmpti2(make_tu(0x0000000000000001uLL
, 0x0000000000000000uLL
),
89 make_tu(0x0000000000000000uLL
, 0xFFFFFFFFFFFFFFFFuLL
), 2))
91 if (test__ucmpti2(make_tu(0x0000000000000001uLL
, 0x0000000000000000uLL
),
92 make_tu(0x0000000000000001uLL
, 0x0000000000000000uLL
), 1))
94 if (test__ucmpti2(make_tu(0x0000000000000001uLL
, 0x0000000000000000uLL
),
95 make_tu(0x0000000000000001uLL
, 0x0000000000000001uLL
), 0))
98 if (test__ucmpti2(make_tu(0x8000000000000000uLL
, 0x0000000000000000uLL
),
99 make_tu(0x7FFFFFFFFFFFFFFFuLL
, 0xFFFFFFFFFFFFFFFFuLL
), 2))
101 if (test__ucmpti2(make_tu(0x8000000000000000uLL
, 0x0000000000000000uLL
),
102 make_tu(0x8000000000000000uLL
, 0x0000000000000000uLL
), 1))
104 if (test__ucmpti2(make_tu(0x8000000000000000uLL
, 0x0000000000000000uLL
),
105 make_tu(0x8000000000000000uLL
, 0x0000000000000001uLL
), 0))
108 if (test__ucmpti2(make_tu(0xFFFFFFFFFFFFFFFFuLL
, 0xFFFFFFFFFFFFFFFFuLL
),
109 make_tu(0xFFFFFFFFFFFFFFFFuLL
, 0xFFFFFFFFFFFFFFFEuLL
), 2))
111 if (test__ucmpti2(make_tu(0xFFFFFFFFFFFFFFFFuLL
, 0xFFFFFFFFFFFFFFFFuLL
),
112 make_tu(0xFFFFFFFFFFFFFFFFuLL
, 0xFFFFFFFFFFFFFFFFuLL
), 1))