Home | History | Annotate | Download | only in Unit
      1 //===-- udivmodsi4_test.c - Test __udivmodsi4 -----------------------------===//
      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 __udivmodsi4 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 su_int __udivmodsi4(su_int a, su_int b, su_int* rem);
     20 
     21 int test__udivmodsi4(su_int a, su_int b,
     22 						su_int expected_result, su_int expected_rem)
     23 {
     24 	su_int rem;
     25     su_int result = __udivmodsi4(a, b, &rem);
     26     if (result != expected_result) {
     27         printf("error in __udivmodsi4: %u / %u = %u, expected %u\n",
     28                a, b, result, expected_result);
     29 		return 1;
     30 	}
     31     if (rem != expected_rem) {
     32         printf("error in __udivmodsi4: %u mod %u = %u, expected %u\n",
     33                a, b, rem, expected_rem);
     34 		return 1;
     35 	}
     36 
     37     return 0;
     38 }
     39 
     40 
     41 int main()
     42 {
     43     if (test__udivmodsi4(0, 1, 0, 0))
     44         return 1;
     45 
     46     if (test__udivmodsi4(2, 1, 2, 0))
     47         return 1;
     48 
     49 	if (test__udivmodsi4(19, 5, 3, 4))
     50         return 1;
     51 
     52 	if (test__udivmodsi4(0x80000000, 8, 0x10000000, 0))
     53         return 1;
     54 
     55  	if (test__udivmodsi4(0x80000003, 8, 0x10000000, 3))
     56         return 1;
     57 
     58 	return 0;
     59 }
     60