blob: 52ec9a0ae36b3b359fa7c42b7bd2d64217cef0e4 [file] [log] [blame]
Edward O'Callaghancc758012009-10-17 10:19:32 +00001/* ===-- modsi3_test.c - Test __modsi3 -------------------------------------===
2 *
3 * The LLVM Compiler Infrastructure
4 *
Howard Hinnant9ad441f2010-11-16 22:13:33 +00005 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
Edward O'Callaghancc758012009-10-17 10:19:32 +00007 *
8 * ===----------------------------------------------------------------------===
9 *
10 * This file tests __modsi3 for the compiler_rt library.
11 *
12 * ===----------------------------------------------------------------------===
13 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000014
15#include "int_lib.h"
16#include <stdio.h>
17
Edward O'Callaghancc758012009-10-17 10:19:32 +000018/* Returns: a % b */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000019
20si_int __modsi3(si_int a, si_int b);
21
Edward O'Callaghancc758012009-10-17 10:19:32 +000022int test__modsi3(si_int a, si_int b, si_int expected) {
Daniel Dunbarb3a69012009-06-26 16:47:03 +000023 si_int x = __modsi3(a, b);
24 if (x != expected)
Edward O'Callaghancc758012009-10-17 10:19:32 +000025 fprintf(stderr, "error in __modsi3: %d %% %d = %d, expected %d\n",
Daniel Dunbarb3a69012009-06-26 16:47:03 +000026 a, b, x, expected);
27 return x != expected;
28}
29
Edward O'Callaghancc758012009-10-17 10:19:32 +000030int main() {
Daniel Dunbarb3a69012009-06-26 16:47:03 +000031 if (test__modsi3(0, 1, 0))
32 return 1;
33 if (test__modsi3(0, -1, 0))
34 return 1;
35
36 if (test__modsi3(5, 3, 2))
37 return 1;
38 if (test__modsi3(5, -3, 2))
39 return 1;
40 if (test__modsi3(-5, 3, -2))
41 return 1;
42 if (test__modsi3(-5, -3, -2))
43 return 1;
44
45 if (test__modsi3(0x80000000, 1, 0x0))
46 return 1;
47 if (test__modsi3(0x80000000, 2, 0x0))
48 return 1;
49 if (test__modsi3(0x80000000, -2, 0x0))
50 return 1;
51 if (test__modsi3(0x80000000, 3, -2))
52 return 1;
53 if (test__modsi3(0x80000000, -3, -2))
54 return 1;
55
56 return 0;
57}