Home | History | Annotate | Download | only in Unit
      1 //===-- divmodsi4_test.c - Test __divmodsi4 -------------------------------===//
      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 __divmodsi4 for the compiler_rt library.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #include "int_lib.h"
     15 #include <stdio.h>
     16 
     17 // Returns: a / b
     18 
     19 extern si_int __divmodsi4(si_int a, si_int b, si_int* rem);
     20 
     21 
     22 int test__divmodsi4(si_int a, si_int b,
     23 						si_int expected_result, si_int expected_rem)
     24 {
     25 	si_int rem;
     26     si_int result = __divmodsi4(a, b, &rem);
     27     if (result != expected_result) {
     28         printf("error in __divmodsi4: %d / %d = %d, expected %d\n",
     29                a, b, result, expected_result);
     30 		return 1;
     31 	}
     32     if (rem != expected_rem) {
     33         printf("error in __divmodsi4: %d mod %d = %d, expected %d\n",
     34                a, b, rem, expected_rem);
     35 		return 1;
     36 	}
     37 
     38     return 0;
     39 }
     40 
     41 
     42 int main()
     43 {
     44     if (test__divmodsi4(0, 1, 0, 0))
     45         return 1;
     46     if (test__divmodsi4(0, -1, 0, 0))
     47         return 1;
     48 
     49     if (test__divmodsi4(2, 1, 2, 0))
     50         return 1;
     51     if (test__divmodsi4(2, -1, -2, 0))
     52         return 1;
     53     if (test__divmodsi4(-2, 1, -2, 0))
     54         return 1;
     55     if (test__divmodsi4(-2, -1, 2, 0))
     56         return 1;
     57 
     58 	if (test__divmodsi4(7, 5, 1, 2))
     59         return 1;
     60 	if (test__divmodsi4(-7, 5, -1, -2))
     61         return 1;
     62 	if (test__divmodsi4(19, 5, 3, 4))
     63         return 1;
     64 	if (test__divmodsi4(19, -5, -3, 4))
     65         return 1;
     66 
     67 	if (test__divmodsi4(0x80000000, 8, 0xf0000000, 0))
     68         return 1;
     69 	if (test__divmodsi4(0x80000007, 8, 0xf0000001, -1))
     70         return 1;
     71 
     72     return 0;
     73 }
     74