1230151Sadrian//===-- udivmodsi4_test.c - Test __udivmodsi4 -----------------------------===//
2230151Sadrian//
3230151Sadrian//                     The LLVM Compiler Infrastructure
4230151Sadrian//
5230151Sadrian// This file is dual licensed under the MIT and the University of Illinois Open
6230151Sadrian// Source Licenses. See LICENSE.TXT for details.
7230151Sadrian//
8230151Sadrian//===----------------------------------------------------------------------===//
9230151Sadrian//
10230151Sadrian// This file tests __udivmodsi4 for the compiler_rt library.
11230151Sadrian//
12230151Sadrian//===----------------------------------------------------------------------===//
13230151Sadrian
14230151Sadrian#include "int_lib.h"
15230151Sadrian#include <stdio.h>
16230151Sadrian
17230151Sadrian// Returns: a / b
18230151Sadrian
19230151Sadrianextern COMPILER_RT_ABI su_int __udivmodsi4(su_int a, su_int b, su_int* rem);
20230151Sadrian
21230151Sadrianint test__udivmodsi4(su_int a, su_int b,
22230151Sadrian						su_int expected_result, su_int expected_rem)
23230151Sadrian{
24230151Sadrian	su_int rem;
25230151Sadrian    su_int result = __udivmodsi4(a, b, &rem);
26230151Sadrian    if (result != expected_result) {
27230151Sadrian        printf("error in __udivmodsi4: %u / %u = %u, expected %u\n",
28230151Sadrian               a, b, result, expected_result);
29230151Sadrian		return 1;
30230151Sadrian	}
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
41int 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