]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/builtins/Unit/addvti3_test.c
Vendor import of compiler-rt trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / test / builtins / Unit / addvti3_test.c
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: int128
3 //===-- addvti3_test.c - Test __addvti3 -----------------------------------===//
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 __addvti3 for the compiler_rt library.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #include "int_lib.h"
17 #include <stdio.h>
18
19 #ifdef CRT_HAS_128BIT
20
21 // Returns: a + b
22
23 // Effects: aborts if a + b overflows
24
25 COMPILER_RT_ABI ti_int __addvti3(ti_int a, ti_int b);
26
27 int test__addvti3(ti_int a, ti_int b)
28 {
29     ti_int x = __addvti3(a, b);
30     ti_int expected = a + b;
31     if (x != expected)
32     {
33         twords at;
34         at.all = a;
35         twords bt;
36         bt.all = b;
37         twords xt;
38         xt.all = x;
39         twords expectedt;
40         expectedt.all = expected;
41         printf("error in test__addvti3(0x%llX%.16llX, 0x%llX%.16llX) = "
42                "0x%llX%.16llX, expected 0x%llX%.16llX\n",
43                 at.s.high, at.s.low, bt.s.high, bt.s.low, xt.s.high, xt.s.low,
44                 expectedt.s.high, expectedt.s.low);
45     }
46     return x != expected;
47 }
48
49 #endif
50
51 int main()
52 {
53 #ifdef CRT_HAS_128BIT
54 // should abort
55 //     test__addvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
56 //                   make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL));
57 // should abort
58 //     test__addvti3(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
59 //                   make_ti(0x8000000000000000LL, 0x0000000000000000LL));
60 // should abort
61 //     test__addvti3(make_ti(0x0000000000000000LL, 0x0000000000000001LL),
62 //                   make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL));
63 // should abort
64 //     test__addvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
65 //                   make_ti(0x0000000000000000LL, 0x0000000000000001LL));
66
67     if (test__addvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
68                       make_ti(0x0000000000000000LL, 0x0000000000000001LL)))
69         return 1;
70     if (test__addvti3(make_ti(0x0000000000000000LL, 0x0000000000000001LL),
71                       make_ti(0x8000000000000000LL, 0x0000000000000000LL)))
72         return 1;
73     if (test__addvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
74                       make_ti(0x0000000000000000LL, 0x0000000000000000LL)))
75         return 1;
76     if (test__addvti3(make_ti(0x0000000000000000LL, 0x0000000000000000LL),
77                       make_ti(0x8000000000000000LL, 0x0000000000000000LL)))
78         return 1;
79     if (test__addvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
80                       make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
81         return 1;
82     if (test__addvti3(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
83                       make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
84         return 1;
85     if (test__addvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
86                       make_ti(0x0000000000000000LL, 0x0000000000000000LL)))
87         return 1;
88     if (test__addvti3(make_ti(0x0000000000000000LL, 0x0000000000000000LL),
89                       make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
90         return 1;
91
92 #else
93     printf("skipped\n");
94 #endif
95     return 0;
96 }