xref: /aosp_15_r20/external/compiler-rt/test/builtins/Unit/subvti3_test.c (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot //===-- subvti3_test.c - Test __subvti3 -----------------------------------===//
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 __subvti3 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 #include <stdlib.h>
17*7c3d14c8STreehugger Robot 
18*7c3d14c8STreehugger Robot #ifdef CRT_HAS_128BIT
19*7c3d14c8STreehugger Robot 
20*7c3d14c8STreehugger Robot // Returns: a - b
21*7c3d14c8STreehugger Robot 
22*7c3d14c8STreehugger Robot // Effects: aborts if a - b overflows
23*7c3d14c8STreehugger Robot 
24*7c3d14c8STreehugger Robot COMPILER_RT_ABI ti_int __subvti3(ti_int a, ti_int b);
25*7c3d14c8STreehugger Robot 
test__subvti3(ti_int a,ti_int b)26*7c3d14c8STreehugger Robot int test__subvti3(ti_int a, ti_int b)
27*7c3d14c8STreehugger Robot {
28*7c3d14c8STreehugger Robot     ti_int x = __subvti3(a, b);
29*7c3d14c8STreehugger Robot     ti_int expected = a - b;
30*7c3d14c8STreehugger Robot     if (x != expected)
31*7c3d14c8STreehugger Robot     {
32*7c3d14c8STreehugger Robot         twords at;
33*7c3d14c8STreehugger Robot         at.all = a;
34*7c3d14c8STreehugger Robot         twords bt;
35*7c3d14c8STreehugger Robot         bt.all = b;
36*7c3d14c8STreehugger Robot         twords xt;
37*7c3d14c8STreehugger Robot         xt.all = x;
38*7c3d14c8STreehugger Robot         twords expectedt;
39*7c3d14c8STreehugger Robot         expectedt.all = expected;
40*7c3d14c8STreehugger Robot         printf("error in test__subvsi3(0x%.16llX%.16llX, 0x%.16llX%.16llX) = "
41*7c3d14c8STreehugger Robot                "0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
42*7c3d14c8STreehugger Robot                at.s.high, at.s.low, bt.s.high, bt.s.low, xt.s.high, xt.s.low,
43*7c3d14c8STreehugger Robot                expectedt.s.high, expectedt.s.low);
44*7c3d14c8STreehugger Robot     }
45*7c3d14c8STreehugger Robot     return x != expected;
46*7c3d14c8STreehugger Robot }
47*7c3d14c8STreehugger Robot 
48*7c3d14c8STreehugger Robot #endif
49*7c3d14c8STreehugger Robot 
main()50*7c3d14c8STreehugger Robot int main()
51*7c3d14c8STreehugger Robot {
52*7c3d14c8STreehugger Robot #ifdef CRT_HAS_128BIT
53*7c3d14c8STreehugger Robot //     test__subvti3(make_ti(0x8000000000000000LL, 0), 1);  // should abort
54*7c3d14c8STreehugger Robot //     test__subvti3(0, make_ti(0x8000000000000000LL, 0));  // should abort
55*7c3d14c8STreehugger Robot //     test__subvti3(1, make_ti(0x8000000000000000LL, 0));  // should abort
56*7c3d14c8STreehugger Robot //     test__subvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), -1);  // should abort
57*7c3d14c8STreehugger Robot //     test__subvti3(-2, make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL));  // should abort
58*7c3d14c8STreehugger Robot 
59*7c3d14c8STreehugger Robot     if (test__subvti3(make_ti(0x8000000000000000LL, 0), -1))
60*7c3d14c8STreehugger Robot         return 1;
61*7c3d14c8STreehugger Robot     if (test__subvti3(make_ti(0x8000000000000000LL, 0), 0))
62*7c3d14c8STreehugger Robot         return 1;
63*7c3d14c8STreehugger Robot     if (test__subvti3(-1, make_ti(0x8000000000000000LL, 0)))
64*7c3d14c8STreehugger Robot         return 1;
65*7c3d14c8STreehugger Robot     if (test__subvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 1))
66*7c3d14c8STreehugger Robot         return 1;
67*7c3d14c8STreehugger Robot     if (test__subvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 0))
68*7c3d14c8STreehugger Robot         return 1;
69*7c3d14c8STreehugger Robot     if (test__subvti3(1, make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
70*7c3d14c8STreehugger Robot         return 1;
71*7c3d14c8STreehugger Robot     if (test__subvti3(0, make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
72*7c3d14c8STreehugger Robot         return 1;
73*7c3d14c8STreehugger Robot     if (test__subvti3(-1, make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
74*7c3d14c8STreehugger Robot         return 1;
75*7c3d14c8STreehugger Robot 
76*7c3d14c8STreehugger Robot #else
77*7c3d14c8STreehugger Robot     printf("skipped\n");
78*7c3d14c8STreehugger Robot #endif
79*7c3d14c8STreehugger Robot     return 0;
80*7c3d14c8STreehugger Robot }
81