[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / absvti2_test.c
blob635c0f92ba17800b889857d6b517ddb085e5496f
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_absvti2
3 // REQUIRES: int128
4 //===-- absvti2_test.c - Test __absvti2 -----------------------------------===//
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 __absvti2 for the compiler_rt library.
14 //===----------------------------------------------------------------------===//
16 #include "int_lib.h"
17 #include <stdio.h>
18 #include <stdlib.h>
20 #ifdef CRT_HAS_128BIT
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);
31 ti_int expected = a;
32 if (expected < 0)
33 expected = -expected;
34 if (x != expected || expected < 0)
36 twords at;
37 at.all = a;
38 twords xt;
39 xt.all = x;
40 twords expectedt;
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);
47 return x != expected;
50 #endif
52 int main()
54 #ifdef CRT_HAS_128BIT
56 // if (test__absvti2(make_ti(0x8000000000000000LL, 0))) // should abort
57 // return 1;
58 if (test__absvti2(0x0000000000000000LL))
59 return 1;
60 if (test__absvti2(0x0000000000000001LL))
61 return 1;
62 if (test__absvti2(0x0000000000000002LL))
63 return 1;
64 if (test__absvti2(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFELL)))
65 return 1;
66 if (test__absvti2(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
67 return 1;
68 if (test__absvti2(make_ti(0x8000000000000000LL, 0x0000000000000001LL)))
69 return 1;
70 if (test__absvti2(make_ti(0x8000000000000000LL, 0x0000000000000002LL)))
71 return 1;
72 if (test__absvti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFELL)))
73 return 1;
74 if (test__absvti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
75 return 1;
77 int i;
78 for (i = 0; i < 10000; ++i)
79 if (test__absvti2(make_ti(((ti_int)rand() << 32) | rand(),
80 ((ti_int)rand() << 32) | rand())))
81 return 1;
82 #else
83 printf("skipped\n");
84 #endif
85 return 0;