xref: /minix3/sys/external/bsd/compiler_rt/dist/test/Unit/divmodsi4_test.c (revision 4684ddb6aab0b36791c8099bc705d6140b3d05d0)
1*4684ddb6SLionel Sambuc //===-- divmodsi4_test.c - Test __divmodsi4 -------------------------------===//
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 __divmodsi4 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 extern si_int __divmodsi4(si_int a, si_int b, si_int* rem);
20*4684ddb6SLionel Sambuc 
21*4684ddb6SLionel Sambuc 
test__divmodsi4(si_int a,si_int b,si_int expected_result,si_int expected_rem)22*4684ddb6SLionel Sambuc int test__divmodsi4(si_int a, si_int b,
23*4684ddb6SLionel Sambuc 						si_int expected_result, si_int expected_rem)
24*4684ddb6SLionel Sambuc {
25*4684ddb6SLionel Sambuc 	si_int rem;
26*4684ddb6SLionel Sambuc     si_int result = __divmodsi4(a, b, &rem);
27*4684ddb6SLionel Sambuc     if (result != expected_result) {
28*4684ddb6SLionel Sambuc         printf("error in __divmodsi4: %d / %d = %d, expected %d\n",
29*4684ddb6SLionel Sambuc                a, b, result, expected_result);
30*4684ddb6SLionel Sambuc 		return 1;
31*4684ddb6SLionel Sambuc 	}
32*4684ddb6SLionel Sambuc     if (rem != expected_rem) {
33*4684ddb6SLionel Sambuc         printf("error in __divmodsi4: %d mod %d = %d, expected %d\n",
34*4684ddb6SLionel Sambuc                a, b, rem, expected_rem);
35*4684ddb6SLionel Sambuc 		return 1;
36*4684ddb6SLionel Sambuc 	}
37*4684ddb6SLionel Sambuc 
38*4684ddb6SLionel Sambuc     return 0;
39*4684ddb6SLionel Sambuc }
40*4684ddb6SLionel Sambuc 
41*4684ddb6SLionel Sambuc 
main()42*4684ddb6SLionel Sambuc int main()
43*4684ddb6SLionel Sambuc {
44*4684ddb6SLionel Sambuc     if (test__divmodsi4(0, 1, 0, 0))
45*4684ddb6SLionel Sambuc         return 1;
46*4684ddb6SLionel Sambuc     if (test__divmodsi4(0, -1, 0, 0))
47*4684ddb6SLionel Sambuc         return 1;
48*4684ddb6SLionel Sambuc 
49*4684ddb6SLionel Sambuc     if (test__divmodsi4(2, 1, 2, 0))
50*4684ddb6SLionel Sambuc         return 1;
51*4684ddb6SLionel Sambuc     if (test__divmodsi4(2, -1, -2, 0))
52*4684ddb6SLionel Sambuc         return 1;
53*4684ddb6SLionel Sambuc     if (test__divmodsi4(-2, 1, -2, 0))
54*4684ddb6SLionel Sambuc         return 1;
55*4684ddb6SLionel Sambuc     if (test__divmodsi4(-2, -1, 2, 0))
56*4684ddb6SLionel Sambuc         return 1;
57*4684ddb6SLionel Sambuc 
58*4684ddb6SLionel Sambuc 	if (test__divmodsi4(7, 5, 1, 2))
59*4684ddb6SLionel Sambuc         return 1;
60*4684ddb6SLionel Sambuc 	if (test__divmodsi4(-7, 5, -1, -2))
61*4684ddb6SLionel Sambuc         return 1;
62*4684ddb6SLionel Sambuc 	if (test__divmodsi4(19, 5, 3, 4))
63*4684ddb6SLionel Sambuc         return 1;
64*4684ddb6SLionel Sambuc 	if (test__divmodsi4(19, -5, -3, 4))
65*4684ddb6SLionel Sambuc         return 1;
66*4684ddb6SLionel Sambuc 
67*4684ddb6SLionel Sambuc 	if (test__divmodsi4(0x80000000, 8, 0xf0000000, 0))
68*4684ddb6SLionel Sambuc         return 1;
69*4684ddb6SLionel Sambuc 	if (test__divmodsi4(0x80000007, 8, 0xf0000001, -1))
70*4684ddb6SLionel Sambuc         return 1;
71*4684ddb6SLionel Sambuc 
72*4684ddb6SLionel Sambuc     return 0;
73*4684ddb6SLionel Sambuc }
74