1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_absvti2
4 //===-- absvti2_test.c - Test __absvti2 -----------------------------------===//
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 __absvti2 for the compiler_rt library.
14 //===----------------------------------------------------------------------===//
22 // Returns: absolute value
24 // Effects: aborts if abs(x) < 0
26 COMPILER_RT_ABI ti_int
__absvti2(ti_int a
);
28 int test__absvti2(ti_int a
)
30 ti_int x
= __absvti2(a
);
34 if (x
!= expected
|| expected
< 0)
41 expectedt
.all
= expected
;
42 printf("error in __absvti2(0x%llX%.16llX) = "
43 "0x%llX%.16llX, expected positive 0x%llX%.16llX\n",
44 at
.s
.high
, at
.s
.low
, xt
.s
.high
, xt
.s
.low
,
45 expectedt
.s
.high
, expectedt
.s
.low
);
56 // if (test__absvti2(make_ti(0x8000000000000000LL, 0))) // should abort
58 if (test__absvti2(0x0000000000000000LL
))
60 if (test__absvti2(0x0000000000000001LL
))
62 if (test__absvti2(0x0000000000000002LL
))
64 if (test__absvti2(make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFELL
)))
66 if (test__absvti2(make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
)))
68 if (test__absvti2(make_ti(0x8000000000000000LL
, 0x0000000000000001LL
)))
70 if (test__absvti2(make_ti(0x8000000000000000LL
, 0x0000000000000002LL
)))
72 if (test__absvti2(make_ti(0xFFFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFELL
)))
74 if (test__absvti2(make_ti(0xFFFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
)))
78 for (i
= 0; i
< 10000; ++i
)
79 if (test__absvti2(make_ti(((ti_int
)rand() << 32) | rand(),
80 ((ti_int
)rand() << 32) | rand())))