1 1.1 joerg //===-- divmodsi4_test.c - Test __divmodsi4 -------------------------------===// 2 1.1 joerg // 3 1.1 joerg // The LLVM Compiler Infrastructure 4 1.1 joerg // 5 1.1 joerg // This file is dual licensed under the MIT and the University of Illinois Open 6 1.1 joerg // Source Licenses. See LICENSE.TXT for details. 7 1.1 joerg // 8 1.1 joerg //===----------------------------------------------------------------------===// 9 1.1 joerg // 10 1.1 joerg // This file tests __divmodsi4 for the compiler_rt library. 11 1.1 joerg // 12 1.1 joerg //===----------------------------------------------------------------------===// 13 1.1 joerg 14 1.1 joerg #include "int_lib.h" 15 1.1 joerg #include <stdio.h> 16 1.1 joerg 17 1.1 joerg // Returns: a / b 18 1.1 joerg 19 1.1 joerg extern si_int __divmodsi4(si_int a, si_int b, si_int* rem); 20 1.1 joerg 21 1.1 joerg 22 1.1 joerg int test__divmodsi4(si_int a, si_int b, 23 1.1 joerg si_int expected_result, si_int expected_rem) 24 1.1 joerg { 25 1.1 joerg si_int rem; 26 1.1 joerg si_int result = __divmodsi4(a, b, &rem); 27 1.1 joerg if (result != expected_result) { 28 1.1 joerg printf("error in __divmodsi4: %d / %d = %d, expected %d\n", 29 1.1 joerg a, b, result, expected_result); 30 1.1 joerg return 1; 31 1.1 joerg } 32 1.1 joerg if (rem != expected_rem) { 33 1.1 joerg printf("error in __divmodsi4: %d mod %d = %d, expected %d\n", 34 1.1 joerg a, b, rem, expected_rem); 35 1.1 joerg return 1; 36 1.1 joerg } 37 1.1 joerg 38 1.1 joerg return 0; 39 1.1 joerg } 40 1.1 joerg 41 1.1 joerg 42 1.1 joerg int main() 43 1.1 joerg { 44 1.1 joerg if (test__divmodsi4(0, 1, 0, 0)) 45 1.1 joerg return 1; 46 1.1 joerg if (test__divmodsi4(0, -1, 0, 0)) 47 1.1 joerg return 1; 48 1.1 joerg 49 1.1 joerg if (test__divmodsi4(2, 1, 2, 0)) 50 1.1 joerg return 1; 51 1.1 joerg if (test__divmodsi4(2, -1, -2, 0)) 52 1.1 joerg return 1; 53 1.1 joerg if (test__divmodsi4(-2, 1, -2, 0)) 54 1.1 joerg return 1; 55 1.1 joerg if (test__divmodsi4(-2, -1, 2, 0)) 56 1.1 joerg return 1; 57 1.1 joerg 58 1.1 joerg if (test__divmodsi4(7, 5, 1, 2)) 59 1.1 joerg return 1; 60 1.1 joerg if (test__divmodsi4(-7, 5, -1, -2)) 61 1.1 joerg return 1; 62 1.1 joerg if (test__divmodsi4(19, 5, 3, 4)) 63 1.1 joerg return 1; 64 1.1 joerg if (test__divmodsi4(19, -5, -3, 4)) 65 1.1 joerg return 1; 66 1.1 joerg 67 1.1 joerg if (test__divmodsi4(0x80000000, 8, 0xf0000000, 0)) 68 1.1 joerg return 1; 69 1.1 joerg if (test__divmodsi4(0x80000007, 8, 0xf0000001, -1)) 70 1.1 joerg return 1; 71 1.1 joerg 72 1.1 joerg return 0; 73 1.1 joerg } 74