Edward O'Callaghan | cc75801 | 2009-10-17 10:19:32 +0000 | [diff] [blame] | 1 | /* ===-- modsi3_test.c - Test __modsi3 -------------------------------------=== |
| 2 | * |
| 3 | * The LLVM Compiler Infrastructure |
| 4 | * |
Howard Hinnant | 9ad441f | 2010-11-16 22:13:33 +0000 | [diff] [blame] | 5 | * This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | * Source Licenses. See LICENSE.TXT for details. |
Edward O'Callaghan | cc75801 | 2009-10-17 10:19:32 +0000 | [diff] [blame] | 7 | * |
| 8 | * ===----------------------------------------------------------------------=== |
| 9 | * |
| 10 | * This file tests __modsi3 for the compiler_rt library. |
| 11 | * |
| 12 | * ===----------------------------------------------------------------------=== |
| 13 | */ |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 14 | |
| 15 | #include "int_lib.h" |
| 16 | #include <stdio.h> |
| 17 | |
Edward O'Callaghan | cc75801 | 2009-10-17 10:19:32 +0000 | [diff] [blame] | 18 | /* Returns: a % b */ |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 19 | |
| 20 | si_int __modsi3(si_int a, si_int b); |
| 21 | |
Edward O'Callaghan | cc75801 | 2009-10-17 10:19:32 +0000 | [diff] [blame] | 22 | int test__modsi3(si_int a, si_int b, si_int expected) { |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 23 | si_int x = __modsi3(a, b); |
| 24 | if (x != expected) |
Edward O'Callaghan | cc75801 | 2009-10-17 10:19:32 +0000 | [diff] [blame] | 25 | fprintf(stderr, "error in __modsi3: %d %% %d = %d, expected %d\n", |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 26 | a, b, x, expected); |
| 27 | return x != expected; |
| 28 | } |
| 29 | |
Edward O'Callaghan | cc75801 | 2009-10-17 10:19:32 +0000 | [diff] [blame] | 30 | int main() { |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 31 | 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 | } |