1*7c3d14c8STreehugger Robot //===-- modti3_test.c - Test __modti3 -------------------------------------===//
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 __modti3 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 COMPILER_RT_ABI ti_int __modti3(ti_int a, ti_int b);
22*7c3d14c8STreehugger Robot
test__modti3(ti_int a,ti_int b,ti_int expected)23*7c3d14c8STreehugger Robot int test__modti3(ti_int a, ti_int b, ti_int expected)
24*7c3d14c8STreehugger Robot {
25*7c3d14c8STreehugger Robot ti_int x = __modti3(a, b);
26*7c3d14c8STreehugger Robot if (x != expected)
27*7c3d14c8STreehugger Robot {
28*7c3d14c8STreehugger Robot twords at;
29*7c3d14c8STreehugger Robot at.all = a;
30*7c3d14c8STreehugger Robot twords bt;
31*7c3d14c8STreehugger Robot bt.all = b;
32*7c3d14c8STreehugger Robot twords xt;
33*7c3d14c8STreehugger Robot xt.all = x;
34*7c3d14c8STreehugger Robot twords expectedt;
35*7c3d14c8STreehugger Robot expectedt.all = expected;
36*7c3d14c8STreehugger Robot printf("error in __modti3: 0x%.16llX%.16llX %% 0x%.16llX%.16llX = "
37*7c3d14c8STreehugger Robot "0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
38*7c3d14c8STreehugger Robot at.s.high, at.s.low, bt.s.high, bt.s.low, xt.s.high, xt.s.low,
39*7c3d14c8STreehugger Robot expectedt.s.high, expectedt.s.low);
40*7c3d14c8STreehugger Robot }
41*7c3d14c8STreehugger Robot return x != expected;
42*7c3d14c8STreehugger Robot }
43*7c3d14c8STreehugger Robot
44*7c3d14c8STreehugger Robot char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
45*7c3d14c8STreehugger Robot
46*7c3d14c8STreehugger Robot #endif
47*7c3d14c8STreehugger Robot
main()48*7c3d14c8STreehugger Robot int main()
49*7c3d14c8STreehugger Robot {
50*7c3d14c8STreehugger Robot #ifdef CRT_HAS_128BIT
51*7c3d14c8STreehugger Robot if (test__modti3(0, 1, 0))
52*7c3d14c8STreehugger Robot return 1;
53*7c3d14c8STreehugger Robot if (test__modti3(0, -1, 0))
54*7c3d14c8STreehugger Robot return 1;
55*7c3d14c8STreehugger Robot
56*7c3d14c8STreehugger Robot if (test__modti3(5, 3, 2))
57*7c3d14c8STreehugger Robot return 1;
58*7c3d14c8STreehugger Robot if (test__modti3(5, -3, 2))
59*7c3d14c8STreehugger Robot return 1;
60*7c3d14c8STreehugger Robot if (test__modti3(-5, 3, -2))
61*7c3d14c8STreehugger Robot return 1;
62*7c3d14c8STreehugger Robot if (test__modti3(-5, -3, -2))
63*7c3d14c8STreehugger Robot return 1;
64*7c3d14c8STreehugger Robot
65*7c3d14c8STreehugger Robot if (test__modti3(0x8000000000000000LL, 1, 0x0LL))
66*7c3d14c8STreehugger Robot return 1;
67*7c3d14c8STreehugger Robot if (test__modti3(0x8000000000000000LL, -1, 0x0LL))
68*7c3d14c8STreehugger Robot return 1;
69*7c3d14c8STreehugger Robot if (test__modti3(0x8000000000000000LL, 2, 0x0LL))
70*7c3d14c8STreehugger Robot return 1;
71*7c3d14c8STreehugger Robot if (test__modti3(0x8000000000000000LL, -2, 0x0LL))
72*7c3d14c8STreehugger Robot return 1;
73*7c3d14c8STreehugger Robot if (test__modti3(0x8000000000000000LL, 3, 2))
74*7c3d14c8STreehugger Robot return 1;
75*7c3d14c8STreehugger Robot if (test__modti3(0x8000000000000000LL, -3, 2))
76*7c3d14c8STreehugger Robot return 1;
77*7c3d14c8STreehugger Robot
78*7c3d14c8STreehugger Robot if (test__modti3(make_ti(0x8000000000000000LL, 0), 1, 0x0LL))
79*7c3d14c8STreehugger Robot return 1;
80*7c3d14c8STreehugger Robot if (test__modti3(make_ti(0x8000000000000000LL, 0), -1, 0x0LL))
81*7c3d14c8STreehugger Robot return 1;
82*7c3d14c8STreehugger Robot if (test__modti3(make_ti(0x8000000000000000LL, 0), 2, 0x0LL))
83*7c3d14c8STreehugger Robot return 1;
84*7c3d14c8STreehugger Robot if (test__modti3(make_ti(0x8000000000000000LL, 0), -2, 0x0LL))
85*7c3d14c8STreehugger Robot return 1;
86*7c3d14c8STreehugger Robot if (test__modti3(make_ti(0x8000000000000000LL, 0), 3, -2))
87*7c3d14c8STreehugger Robot return 1;
88*7c3d14c8STreehugger Robot if (test__modti3(make_ti(0x8000000000000000LL, 0), -3, -2))
89*7c3d14c8STreehugger Robot return 1;
90*7c3d14c8STreehugger Robot
91*7c3d14c8STreehugger Robot #else
92*7c3d14c8STreehugger Robot printf("skipped\n");
93*7c3d14c8STreehugger Robot #endif
94*7c3d14c8STreehugger Robot return 0;
95*7c3d14c8STreehugger Robot }
96