1*4684ddb6SLionel Sambuc /* ===-- modsi3_test.c - Test __modsi3 -------------------------------------===
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 __modsi3 for the compiler_rt library.
11*4684ddb6SLionel Sambuc *
12*4684ddb6SLionel Sambuc * ===----------------------------------------------------------------------===
13*4684ddb6SLionel Sambuc */
14*4684ddb6SLionel Sambuc
15*4684ddb6SLionel Sambuc #include "int_lib.h"
16*4684ddb6SLionel Sambuc #include <stdio.h>
17*4684ddb6SLionel Sambuc
18*4684ddb6SLionel Sambuc /* Returns: a % b */
19*4684ddb6SLionel Sambuc
20*4684ddb6SLionel Sambuc si_int __modsi3(si_int a, si_int b);
21*4684ddb6SLionel Sambuc
test__modsi3(si_int a,si_int b,si_int expected)22*4684ddb6SLionel Sambuc int test__modsi3(si_int a, si_int b, si_int expected) {
23*4684ddb6SLionel Sambuc si_int x = __modsi3(a, b);
24*4684ddb6SLionel Sambuc if (x != expected)
25*4684ddb6SLionel Sambuc fprintf(stderr, "error in __modsi3: %d %% %d = %d, expected %d\n",
26*4684ddb6SLionel Sambuc a, b, x, expected);
27*4684ddb6SLionel Sambuc return x != expected;
28*4684ddb6SLionel Sambuc }
29*4684ddb6SLionel Sambuc
main()30*4684ddb6SLionel Sambuc int main() {
31*4684ddb6SLionel Sambuc if (test__modsi3(0, 1, 0))
32*4684ddb6SLionel Sambuc return 1;
33*4684ddb6SLionel Sambuc if (test__modsi3(0, -1, 0))
34*4684ddb6SLionel Sambuc return 1;
35*4684ddb6SLionel Sambuc
36*4684ddb6SLionel Sambuc if (test__modsi3(5, 3, 2))
37*4684ddb6SLionel Sambuc return 1;
38*4684ddb6SLionel Sambuc if (test__modsi3(5, -3, 2))
39*4684ddb6SLionel Sambuc return 1;
40*4684ddb6SLionel Sambuc if (test__modsi3(-5, 3, -2))
41*4684ddb6SLionel Sambuc return 1;
42*4684ddb6SLionel Sambuc if (test__modsi3(-5, -3, -2))
43*4684ddb6SLionel Sambuc return 1;
44*4684ddb6SLionel Sambuc
45*4684ddb6SLionel Sambuc if (test__modsi3(0x80000000, 1, 0x0))
46*4684ddb6SLionel Sambuc return 1;
47*4684ddb6SLionel Sambuc if (test__modsi3(0x80000000, 2, 0x0))
48*4684ddb6SLionel Sambuc return 1;
49*4684ddb6SLionel Sambuc if (test__modsi3(0x80000000, -2, 0x0))
50*4684ddb6SLionel Sambuc return 1;
51*4684ddb6SLionel Sambuc if (test__modsi3(0x80000000, 3, -2))
52*4684ddb6SLionel Sambuc return 1;
53*4684ddb6SLionel Sambuc if (test__modsi3(0x80000000, -3, -2))
54*4684ddb6SLionel Sambuc return 1;
55*4684ddb6SLionel Sambuc
56*4684ddb6SLionel Sambuc return 0;
57*4684ddb6SLionel Sambuc }
58