xref: /aosp_15_r20/external/compiler-rt/test/builtins/Unit/addvti3_test.c (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot //===-- addvti3_test.c - Test __addvti3 -----------------------------------===//
2*7c3d14c8STreehugger Robot //
3*7c3d14c8STreehugger Robot //                     The LLVM Compiler Infrastructure
4*7c3d14c8STreehugger Robot //
5*7c3d14c8STreehugger Robot // This file is dual licensed under the MIT and the University of Illinois Open
6*7c3d14c8STreehugger Robot // Source Licenses. See LICENSE.TXT for details.
7*7c3d14c8STreehugger Robot //
8*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
9*7c3d14c8STreehugger Robot //
10*7c3d14c8STreehugger Robot // This file tests __addvti3 for the compiler_rt library.
11*7c3d14c8STreehugger Robot //
12*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
13*7c3d14c8STreehugger Robot 
14*7c3d14c8STreehugger Robot #include "int_lib.h"
15*7c3d14c8STreehugger Robot #include <stdio.h>
16*7c3d14c8STreehugger Robot 
17*7c3d14c8STreehugger Robot #ifdef CRT_HAS_128BIT
18*7c3d14c8STreehugger Robot 
19*7c3d14c8STreehugger Robot // Returns: a + b
20*7c3d14c8STreehugger Robot 
21*7c3d14c8STreehugger Robot // Effects: aborts if a + b overflows
22*7c3d14c8STreehugger Robot 
23*7c3d14c8STreehugger Robot COMPILER_RT_ABI ti_int __addvti3(ti_int a, ti_int b);
24*7c3d14c8STreehugger Robot 
test__addvti3(ti_int a,ti_int b)25*7c3d14c8STreehugger Robot int test__addvti3(ti_int a, ti_int b)
26*7c3d14c8STreehugger Robot {
27*7c3d14c8STreehugger Robot     ti_int x = __addvti3(a, b);
28*7c3d14c8STreehugger Robot     ti_int expected = a + b;
29*7c3d14c8STreehugger Robot     if (x != expected)
30*7c3d14c8STreehugger Robot     {
31*7c3d14c8STreehugger Robot         twords at;
32*7c3d14c8STreehugger Robot         at.all = a;
33*7c3d14c8STreehugger Robot         twords bt;
34*7c3d14c8STreehugger Robot         bt.all = b;
35*7c3d14c8STreehugger Robot         twords xt;
36*7c3d14c8STreehugger Robot         xt.all = x;
37*7c3d14c8STreehugger Robot         twords expectedt;
38*7c3d14c8STreehugger Robot         expectedt.all = expected;
39*7c3d14c8STreehugger Robot         printf("error in test__addvti3(0x%llX%.16llX, 0x%llX%.16llX) = "
40*7c3d14c8STreehugger Robot                "0x%llX%.16llX, expected 0x%llX%.16llX\n",
41*7c3d14c8STreehugger Robot                 at.s.high, at.s.low, bt.s.high, bt.s.low, xt.s.high, xt.s.low,
42*7c3d14c8STreehugger Robot                 expectedt.s.high, expectedt.s.low);
43*7c3d14c8STreehugger Robot     }
44*7c3d14c8STreehugger Robot     return x != expected;
45*7c3d14c8STreehugger Robot }
46*7c3d14c8STreehugger Robot 
47*7c3d14c8STreehugger Robot #endif
48*7c3d14c8STreehugger Robot 
main()49*7c3d14c8STreehugger Robot int main()
50*7c3d14c8STreehugger Robot {
51*7c3d14c8STreehugger Robot #ifdef CRT_HAS_128BIT
52*7c3d14c8STreehugger Robot // should abort
53*7c3d14c8STreehugger Robot //     test__addvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
54*7c3d14c8STreehugger Robot //                   make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL));
55*7c3d14c8STreehugger Robot // should abort
56*7c3d14c8STreehugger Robot //     test__addvti3(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
57*7c3d14c8STreehugger Robot //                   make_ti(0x8000000000000000LL, 0x0000000000000000LL));
58*7c3d14c8STreehugger Robot // should abort
59*7c3d14c8STreehugger Robot //     test__addvti3(make_ti(0x0000000000000000LL, 0x0000000000000001LL),
60*7c3d14c8STreehugger Robot //                   make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL));
61*7c3d14c8STreehugger Robot // should abort
62*7c3d14c8STreehugger Robot //     test__addvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
63*7c3d14c8STreehugger Robot //                   make_ti(0x0000000000000000LL, 0x0000000000000001LL));
64*7c3d14c8STreehugger Robot 
65*7c3d14c8STreehugger Robot     if (test__addvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
66*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000000LL, 0x0000000000000001LL)))
67*7c3d14c8STreehugger Robot         return 1;
68*7c3d14c8STreehugger Robot     if (test__addvti3(make_ti(0x0000000000000000LL, 0x0000000000000001LL),
69*7c3d14c8STreehugger Robot                       make_ti(0x8000000000000000LL, 0x0000000000000000LL)))
70*7c3d14c8STreehugger Robot         return 1;
71*7c3d14c8STreehugger Robot     if (test__addvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
72*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000000LL, 0x0000000000000000LL)))
73*7c3d14c8STreehugger Robot         return 1;
74*7c3d14c8STreehugger Robot     if (test__addvti3(make_ti(0x0000000000000000LL, 0x0000000000000000LL),
75*7c3d14c8STreehugger Robot                       make_ti(0x8000000000000000LL, 0x0000000000000000LL)))
76*7c3d14c8STreehugger Robot         return 1;
77*7c3d14c8STreehugger Robot     if (test__addvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
78*7c3d14c8STreehugger Robot                       make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
79*7c3d14c8STreehugger Robot         return 1;
80*7c3d14c8STreehugger Robot     if (test__addvti3(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
81*7c3d14c8STreehugger Robot                       make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
82*7c3d14c8STreehugger Robot         return 1;
83*7c3d14c8STreehugger Robot     if (test__addvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
84*7c3d14c8STreehugger Robot                       make_ti(0x0000000000000000LL, 0x0000000000000000LL)))
85*7c3d14c8STreehugger Robot         return 1;
86*7c3d14c8STreehugger Robot     if (test__addvti3(make_ti(0x0000000000000000LL, 0x0000000000000000LL),
87*7c3d14c8STreehugger Robot                       make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
88*7c3d14c8STreehugger Robot         return 1;
89*7c3d14c8STreehugger Robot 
90*7c3d14c8STreehugger Robot #else
91*7c3d14c8STreehugger Robot     printf("skipped\n");
92*7c3d14c8STreehugger Robot #endif
93*7c3d14c8STreehugger Robot     return 0;
94*7c3d14c8STreehugger Robot }
95