1 /* ===-- modsi3_test.c - Test __modsi3 -------------------------------------=== 2 * 3 * The LLVM Compiler Infrastructure 4 * 5 * This file is dual licensed under the MIT and the University of Illinois Open 6 * Source Licenses. See LICENSE.TXT for details. 7 * 8 * ===----------------------------------------------------------------------=== 9 * 10 * This file tests __modsi3 for the compiler_rt library. 11 * 12 * ===----------------------------------------------------------------------=== 13 */ 14 15 #include "int_lib.h" 16 #include <stdio.h> 17 18 /* Returns: a % b */ 19 20 COMPILER_RT_ABI si_int __modsi3(si_int a, si_int b); 21 22 int test__modsi3(si_int a, si_int b, si_int expected) { 23 si_int x = __modsi3(a, b); 24 if (x != expected) 25 fprintf(stderr, "error in __modsi3: %d %% %d = %d, expected %d\n", 26 a, b, x, expected); 27 return x != expected; 28 } 29 30 int main() { 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 } 58