xref: /minix3/sys/external/bsd/compiler_rt/dist/test/Unit/moddi3_test.c (revision 4684ddb6aab0b36791c8099bc705d6140b3d05d0)
1*4684ddb6SLionel Sambuc //===-- moddi3_test.c - Test __moddi3 -------------------------------------===//
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 __moddi3 for the compiler_rt library.
11*4684ddb6SLionel Sambuc //
12*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
13*4684ddb6SLionel Sambuc 
14*4684ddb6SLionel Sambuc #include "int_lib.h"
15*4684ddb6SLionel Sambuc #include <stdio.h>
16*4684ddb6SLionel Sambuc 
17*4684ddb6SLionel Sambuc // Returns: a % b
18*4684ddb6SLionel Sambuc 
19*4684ddb6SLionel Sambuc di_int __moddi3(di_int a, di_int b);
20*4684ddb6SLionel Sambuc 
test__moddi3(di_int a,di_int b,di_int expected)21*4684ddb6SLionel Sambuc int test__moddi3(di_int a, di_int b, di_int expected)
22*4684ddb6SLionel Sambuc {
23*4684ddb6SLionel Sambuc     di_int x = __moddi3(a, b);
24*4684ddb6SLionel Sambuc     if (x != expected)
25*4684ddb6SLionel Sambuc         printf("error in __moddi3: %lld %% %lld = %lld, expected %lld\n",
26*4684ddb6SLionel Sambuc                a, b, x, expected);
27*4684ddb6SLionel Sambuc     return x != expected;
28*4684ddb6SLionel Sambuc }
29*4684ddb6SLionel Sambuc 
30*4684ddb6SLionel Sambuc char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
31*4684ddb6SLionel Sambuc 
main()32*4684ddb6SLionel Sambuc int main()
33*4684ddb6SLionel Sambuc {
34*4684ddb6SLionel Sambuc     if (test__moddi3(0, 1, 0))
35*4684ddb6SLionel Sambuc         return 1;
36*4684ddb6SLionel Sambuc     if (test__moddi3(0, -1, 0))
37*4684ddb6SLionel Sambuc         return 1;
38*4684ddb6SLionel Sambuc 
39*4684ddb6SLionel Sambuc     if (test__moddi3(5, 3, 2))
40*4684ddb6SLionel Sambuc         return 1;
41*4684ddb6SLionel Sambuc     if (test__moddi3(5, -3, 2))
42*4684ddb6SLionel Sambuc         return 1;
43*4684ddb6SLionel Sambuc     if (test__moddi3(-5, 3, -2))
44*4684ddb6SLionel Sambuc         return 1;
45*4684ddb6SLionel Sambuc     if (test__moddi3(-5, -3, -2))
46*4684ddb6SLionel Sambuc         return 1;
47*4684ddb6SLionel Sambuc 
48*4684ddb6SLionel Sambuc     if (test__moddi3(0x8000000000000000LL, 1, 0x0LL))
49*4684ddb6SLionel Sambuc         return 1;
50*4684ddb6SLionel Sambuc     if (test__moddi3(0x8000000000000000LL, -1, 0x0LL))
51*4684ddb6SLionel Sambuc         return 1;
52*4684ddb6SLionel Sambuc     if (test__moddi3(0x8000000000000000LL, 2, 0x0LL))
53*4684ddb6SLionel Sambuc         return 1;
54*4684ddb6SLionel Sambuc     if (test__moddi3(0x8000000000000000LL, -2, 0x0LL))
55*4684ddb6SLionel Sambuc         return 1;
56*4684ddb6SLionel Sambuc     if (test__moddi3(0x8000000000000000LL, 3, -2))
57*4684ddb6SLionel Sambuc         return 1;
58*4684ddb6SLionel Sambuc     if (test__moddi3(0x8000000000000000LL, -3, -2))
59*4684ddb6SLionel Sambuc         return 1;
60*4684ddb6SLionel Sambuc 
61*4684ddb6SLionel Sambuc     return 0;
62*4684ddb6SLionel Sambuc }
63