1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_addvti3
3 // REQUIRES: int128
4
5 #include "int_lib.h"
6 #include <stdio.h>
7
8 #ifdef CRT_HAS_128BIT
9
10 // Returns: a + b
11
12 // Effects: aborts if a + b overflows
13
14 COMPILER_RT_ABI ti_int __addvti3(ti_int a, ti_int b);
15
test__addvti3(ti_int a,ti_int b)16 int test__addvti3(ti_int a, ti_int b)
17 {
18 ti_int x = __addvti3(a, b);
19 ti_int expected = a + b;
20 if (x != expected)
21 {
22 twords at;
23 at.all = a;
24 twords bt;
25 bt.all = b;
26 twords xt;
27 xt.all = x;
28 twords expectedt;
29 expectedt.all = expected;
30 printf("error in test__addvti3(0x%llX%.16llX, 0x%llX%.16llX) = "
31 "0x%llX%.16llX, expected 0x%llX%.16llX\n",
32 at.s.high, at.s.low, bt.s.high, bt.s.low, xt.s.high, xt.s.low,
33 expectedt.s.high, expectedt.s.low);
34 }
35 return x != expected;
36 }
37
38 #endif
39
main()40 int main()
41 {
42 #ifdef CRT_HAS_128BIT
43 // should abort
44 // test__addvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
45 // make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL));
46 // should abort
47 // test__addvti3(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
48 // make_ti(0x8000000000000000LL, 0x0000000000000000LL));
49 // should abort
50 // test__addvti3(make_ti(0x0000000000000000LL, 0x0000000000000001LL),
51 // make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL));
52 // should abort
53 // test__addvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
54 // make_ti(0x0000000000000000LL, 0x0000000000000001LL));
55
56 if (test__addvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
57 make_ti(0x0000000000000000LL, 0x0000000000000001LL)))
58 return 1;
59 if (test__addvti3(make_ti(0x0000000000000000LL, 0x0000000000000001LL),
60 make_ti(0x8000000000000000LL, 0x0000000000000000LL)))
61 return 1;
62 if (test__addvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
63 make_ti(0x0000000000000000LL, 0x0000000000000000LL)))
64 return 1;
65 if (test__addvti3(make_ti(0x0000000000000000LL, 0x0000000000000000LL),
66 make_ti(0x8000000000000000LL, 0x0000000000000000LL)))
67 return 1;
68 if (test__addvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
69 make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
70 return 1;
71 if (test__addvti3(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
72 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
73 return 1;
74 if (test__addvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
75 make_ti(0x0000000000000000LL, 0x0000000000000000LL)))
76 return 1;
77 if (test__addvti3(make_ti(0x0000000000000000LL, 0x0000000000000000LL),
78 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
79 return 1;
80
81 #else
82 printf("skipped\n");
83 #endif
84 return 0;
85 }
86