xref: /minix3/sys/external/bsd/compiler_rt/dist/test/Unit/modti3_test.c (revision 4684ddb6aab0b36791c8099bc705d6140b3d05d0)
1*4684ddb6SLionel Sambuc //===-- modti3_test.c - Test __modti3 -------------------------------------===//
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 __modti3 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 __modti3(ti_int a, ti_int b);
22*4684ddb6SLionel Sambuc 
test__modti3(ti_int a,ti_int b,ti_int expected)23*4684ddb6SLionel Sambuc int test__modti3(ti_int a, ti_int b, ti_int expected)
24*4684ddb6SLionel Sambuc {
25*4684ddb6SLionel Sambuc     ti_int x = __modti3(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 __modti3: 0x%.16llX%.16llX %% 0x%.16llX%.16llX = "
37*4684ddb6SLionel Sambuc                "0x%.16llX%.16llX, expected 0x%.16llX%.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__modti3(0, 1, 0))
52*4684ddb6SLionel Sambuc         return 1;
53*4684ddb6SLionel Sambuc     if (test__modti3(0, -1, 0))
54*4684ddb6SLionel Sambuc         return 1;
55*4684ddb6SLionel Sambuc 
56*4684ddb6SLionel Sambuc     if (test__modti3(5, 3, 2))
57*4684ddb6SLionel Sambuc         return 1;
58*4684ddb6SLionel Sambuc     if (test__modti3(5, -3, 2))
59*4684ddb6SLionel Sambuc         return 1;
60*4684ddb6SLionel Sambuc     if (test__modti3(-5, 3, -2))
61*4684ddb6SLionel Sambuc         return 1;
62*4684ddb6SLionel Sambuc     if (test__modti3(-5, -3, -2))
63*4684ddb6SLionel Sambuc         return 1;
64*4684ddb6SLionel Sambuc 
65*4684ddb6SLionel Sambuc     if (test__modti3(0x8000000000000000LL, 1, 0x0LL))
66*4684ddb6SLionel Sambuc         return 1;
67*4684ddb6SLionel Sambuc     if (test__modti3(0x8000000000000000LL, -1, 0x0LL))
68*4684ddb6SLionel Sambuc         return 1;
69*4684ddb6SLionel Sambuc     if (test__modti3(0x8000000000000000LL, 2, 0x0LL))
70*4684ddb6SLionel Sambuc         return 1;
71*4684ddb6SLionel Sambuc     if (test__modti3(0x8000000000000000LL, -2, 0x0LL))
72*4684ddb6SLionel Sambuc         return 1;
73*4684ddb6SLionel Sambuc     if (test__modti3(0x8000000000000000LL, 3, 2))
74*4684ddb6SLionel Sambuc         return 1;
75*4684ddb6SLionel Sambuc     if (test__modti3(0x8000000000000000LL, -3, 2))
76*4684ddb6SLionel Sambuc         return 1;
77*4684ddb6SLionel Sambuc 
78*4684ddb6SLionel Sambuc     if (test__modti3(make_ti(0x8000000000000000LL, 0), 1, 0x0LL))
79*4684ddb6SLionel Sambuc         return 1;
80*4684ddb6SLionel Sambuc     if (test__modti3(make_ti(0x8000000000000000LL, 0), -1, 0x0LL))
81*4684ddb6SLionel Sambuc         return 1;
82*4684ddb6SLionel Sambuc     if (test__modti3(make_ti(0x8000000000000000LL, 0), 2, 0x0LL))
83*4684ddb6SLionel Sambuc         return 1;
84*4684ddb6SLionel Sambuc     if (test__modti3(make_ti(0x8000000000000000LL, 0), -2, 0x0LL))
85*4684ddb6SLionel Sambuc         return 1;
86*4684ddb6SLionel Sambuc     if (test__modti3(make_ti(0x8000000000000000LL, 0), 3, -2))
87*4684ddb6SLionel Sambuc         return 1;
88*4684ddb6SLionel Sambuc     if (test__modti3(make_ti(0x8000000000000000LL, 0), -3, -2))
89*4684ddb6SLionel Sambuc         return 1;
90*4684ddb6SLionel Sambuc 
91*4684ddb6SLionel Sambuc #else
92*4684ddb6SLionel Sambuc     printf("skipped\n");
93*4684ddb6SLionel Sambuc #endif
94*4684ddb6SLionel Sambuc     return 0;
95*4684ddb6SLionel Sambuc }
96