xref: /minix3/sys/external/bsd/compiler_rt/dist/test/Unit/divti3_test.c (revision 4684ddb6aab0b36791c8099bc705d6140b3d05d0)
1*4684ddb6SLionel Sambuc //===-- divti3_test.c - Test __divti3 -------------------------------------===//
2*4684ddb6SLionel Sambuc //
3*4684ddb6SLionel Sambuc //                     The LLVM Compiler Infrastructure
4*4684ddb6SLionel Sambuc //
5*4684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
6*4684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
7*4684ddb6SLionel Sambuc //
8*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
9*4684ddb6SLionel Sambuc //
10*4684ddb6SLionel Sambuc // This file tests __divti3 for the compiler_rt library.
11*4684ddb6SLionel Sambuc //
12*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
13*4684ddb6SLionel Sambuc 
14*4684ddb6SLionel Sambuc #if __x86_64
15*4684ddb6SLionel Sambuc 
16*4684ddb6SLionel Sambuc #include "int_lib.h"
17*4684ddb6SLionel Sambuc #include <stdio.h>
18*4684ddb6SLionel Sambuc 
19*4684ddb6SLionel Sambuc // Returns: a / b
20*4684ddb6SLionel Sambuc 
21*4684ddb6SLionel Sambuc ti_int __divti3(ti_int a, ti_int b);
22*4684ddb6SLionel Sambuc 
test__divti3(ti_int a,ti_int b,ti_int expected)23*4684ddb6SLionel Sambuc int test__divti3(ti_int a, ti_int b, ti_int expected)
24*4684ddb6SLionel Sambuc {
25*4684ddb6SLionel Sambuc     ti_int x = __divti3(a, b);
26*4684ddb6SLionel Sambuc     if (x != expected)
27*4684ddb6SLionel Sambuc     {
28*4684ddb6SLionel Sambuc         twords at;
29*4684ddb6SLionel Sambuc         at.all = a;
30*4684ddb6SLionel Sambuc         twords bt;
31*4684ddb6SLionel Sambuc         bt.all = b;
32*4684ddb6SLionel Sambuc         twords xt;
33*4684ddb6SLionel Sambuc         xt.all = x;
34*4684ddb6SLionel Sambuc         twords expectedt;
35*4684ddb6SLionel Sambuc         expectedt.all = expected;
36*4684ddb6SLionel Sambuc         printf("error in __divti3: 0x%llX%.16llX / 0x%llX%.16llX = "
37*4684ddb6SLionel Sambuc                "0x%llX%.16llX, expected 0x%llX%.16llX\n",
38*4684ddb6SLionel Sambuc                at.s.high, at.s.low, bt.s.high, bt.s.low, xt.s.high, xt.s.low,
39*4684ddb6SLionel Sambuc                expectedt.s.high, expectedt.s.low);
40*4684ddb6SLionel Sambuc     }
41*4684ddb6SLionel Sambuc     return x != expected;
42*4684ddb6SLionel Sambuc }
43*4684ddb6SLionel Sambuc 
44*4684ddb6SLionel Sambuc char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
45*4684ddb6SLionel Sambuc 
46*4684ddb6SLionel Sambuc #endif
47*4684ddb6SLionel Sambuc 
main()48*4684ddb6SLionel Sambuc int main()
49*4684ddb6SLionel Sambuc {
50*4684ddb6SLionel Sambuc #if __x86_64
51*4684ddb6SLionel Sambuc     if (test__divti3(0, 1, 0))
52*4684ddb6SLionel Sambuc         return 1;
53*4684ddb6SLionel Sambuc     if (test__divti3(0, -1, 0))
54*4684ddb6SLionel Sambuc         return 1;
55*4684ddb6SLionel Sambuc 
56*4684ddb6SLionel Sambuc     if (test__divti3(2, 1, 2))
57*4684ddb6SLionel Sambuc         return 1;
58*4684ddb6SLionel Sambuc     if (test__divti3(2, -1, -2))
59*4684ddb6SLionel Sambuc         return 1;
60*4684ddb6SLionel Sambuc     if (test__divti3(-2, 1, -2))
61*4684ddb6SLionel Sambuc         return 1;
62*4684ddb6SLionel Sambuc     if (test__divti3(-2, -1, 2))
63*4684ddb6SLionel Sambuc         return 1;
64*4684ddb6SLionel Sambuc 
65*4684ddb6SLionel Sambuc     if (test__divti3(make_ti(0x8000000000000000LL, 0), 1, make_ti(0x8000000000000000LL, 0)))
66*4684ddb6SLionel Sambuc         return 1;
67*4684ddb6SLionel Sambuc     if (test__divti3(make_ti(0x8000000000000000LL, 0), -1, make_ti(0x8000000000000000LL, 0)))
68*4684ddb6SLionel Sambuc         return 1;
69*4684ddb6SLionel Sambuc     if (test__divti3(make_ti(0x8000000000000000LL, 0), -2, make_ti(0x4000000000000000LL, 0)))
70*4684ddb6SLionel Sambuc         return 1;
71*4684ddb6SLionel Sambuc     if (test__divti3(make_ti(0x8000000000000000LL, 0), 2, make_ti(0xC000000000000000LL, 0)))
72*4684ddb6SLionel Sambuc         return 1;
73*4684ddb6SLionel Sambuc 
74*4684ddb6SLionel Sambuc #else
75*4684ddb6SLionel Sambuc     printf("skipped\n");
76*4684ddb6SLionel Sambuc #endif
77*4684ddb6SLionel Sambuc     return 0;
78*4684ddb6SLionel Sambuc }
79