1*7c3d14c8STreehugger Robot //===-- divti3_test.c - Test __divti3 -------------------------------------===//
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 __divti3 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 __divti3(ti_int a, ti_int b);
22*7c3d14c8STreehugger Robot
test__divti3(ti_int a,ti_int b,ti_int expected)23*7c3d14c8STreehugger Robot int test__divti3(ti_int a, ti_int b, ti_int expected)
24*7c3d14c8STreehugger Robot {
25*7c3d14c8STreehugger Robot ti_int x = __divti3(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 __divti3: 0x%llX%.16llX / 0x%llX%.16llX = "
37*7c3d14c8STreehugger Robot "0x%llX%.16llX, expected 0x%llX%.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__divti3(0, 1, 0))
52*7c3d14c8STreehugger Robot return 1;
53*7c3d14c8STreehugger Robot if (test__divti3(0, -1, 0))
54*7c3d14c8STreehugger Robot return 1;
55*7c3d14c8STreehugger Robot
56*7c3d14c8STreehugger Robot if (test__divti3(2, 1, 2))
57*7c3d14c8STreehugger Robot return 1;
58*7c3d14c8STreehugger Robot if (test__divti3(2, -1, -2))
59*7c3d14c8STreehugger Robot return 1;
60*7c3d14c8STreehugger Robot if (test__divti3(-2, 1, -2))
61*7c3d14c8STreehugger Robot return 1;
62*7c3d14c8STreehugger Robot if (test__divti3(-2, -1, 2))
63*7c3d14c8STreehugger Robot return 1;
64*7c3d14c8STreehugger Robot
65*7c3d14c8STreehugger Robot if (test__divti3(make_ti(0x8000000000000000LL, 0), 1, make_ti(0x8000000000000000LL, 0)))
66*7c3d14c8STreehugger Robot return 1;
67*7c3d14c8STreehugger Robot if (test__divti3(make_ti(0x8000000000000000LL, 0), -1, make_ti(0x8000000000000000LL, 0)))
68*7c3d14c8STreehugger Robot return 1;
69*7c3d14c8STreehugger Robot if (test__divti3(make_ti(0x8000000000000000LL, 0), -2, make_ti(0x4000000000000000LL, 0)))
70*7c3d14c8STreehugger Robot return 1;
71*7c3d14c8STreehugger Robot if (test__divti3(make_ti(0x8000000000000000LL, 0), 2, make_ti(0xC000000000000000LL, 0)))
72*7c3d14c8STreehugger Robot return 1;
73*7c3d14c8STreehugger Robot
74*7c3d14c8STreehugger Robot #else
75*7c3d14c8STreehugger Robot printf("skipped\n");
76*7c3d14c8STreehugger Robot #endif
77*7c3d14c8STreehugger Robot return 0;
78*7c3d14c8STreehugger Robot }
79