]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/builtins/Unit/absvti2_test.c
Vendor import of compiler-rt trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / test / builtins / Unit / absvti2_test.c
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: int128
3 //===-- absvti2_test.c - Test __absvti2 -----------------------------------===//
4 //
5 //                     The LLVM Compiler Infrastructure
6 //
7 // This file is dual licensed under the MIT and the University of Illinois Open
8 // Source Licenses. See LICENSE.TXT for details.
9 //
10 //===----------------------------------------------------------------------===//
11 //
12 // This file tests __absvti2 for the compiler_rt library.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #include "int_lib.h"
17 #include <stdio.h>
18 #include <stdlib.h>
19
20 #ifdef CRT_HAS_128BIT
21
22 // Returns: absolute value
23
24 // Effects: aborts if abs(x) < 0
25
26 COMPILER_RT_ABI ti_int __absvti2(ti_int a);
27
28 int test__absvti2(ti_int a)
29 {
30     ti_int x = __absvti2(a);
31     ti_int expected = a;
32     if (expected < 0)
33         expected = -expected;
34     if (x != expected || expected < 0)
35     {
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);
46     }
47     return x != expected;
48 }
49
50 #endif
51
52 int main()
53 {
54 #ifdef CRT_HAS_128BIT
55
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;
76
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;
86 }