1*4684ddb6SLionel Sambuc //===-- umodti3_test.c - Test __umodti3 -----------------------------------===//
2*4684ddb6SLionel Sambuc //
3*4684ddb6SLionel Sambuc // The LLVM Compiler Infrastructure
4*4684ddb6SLionel Sambuc //
5*4684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
6*4684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
7*4684ddb6SLionel Sambuc //
8*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
9*4684ddb6SLionel Sambuc //
10*4684ddb6SLionel Sambuc // This file tests __umodti3 for the compiler_rt library.
11*4684ddb6SLionel Sambuc //
12*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
13*4684ddb6SLionel Sambuc
14*4684ddb6SLionel Sambuc #if __x86_64
15*4684ddb6SLionel Sambuc
16*4684ddb6SLionel Sambuc #include "int_lib.h"
17*4684ddb6SLionel Sambuc #include <stdio.h>
18*4684ddb6SLionel Sambuc
19*4684ddb6SLionel Sambuc // Returns: a % b
20*4684ddb6SLionel Sambuc
21*4684ddb6SLionel Sambuc tu_int __umodti3(tu_int a, tu_int b);
22*4684ddb6SLionel Sambuc
test__umodti3(tu_int a,tu_int b,tu_int expected_r)23*4684ddb6SLionel Sambuc int test__umodti3(tu_int a, tu_int b, tu_int expected_r)
24*4684ddb6SLionel Sambuc {
25*4684ddb6SLionel Sambuc tu_int r = __umodti3(a, b);
26*4684ddb6SLionel Sambuc if (r != expected_r)
27*4684ddb6SLionel Sambuc {
28*4684ddb6SLionel Sambuc utwords at;
29*4684ddb6SLionel Sambuc at.all = a;
30*4684ddb6SLionel Sambuc utwords bt;
31*4684ddb6SLionel Sambuc bt.all = b;
32*4684ddb6SLionel Sambuc utwords rt;
33*4684ddb6SLionel Sambuc rt.all = r;
34*4684ddb6SLionel Sambuc utwords expected_rt;
35*4684ddb6SLionel Sambuc expected_rt.all = expected_r;
36*4684ddb6SLionel Sambuc printf("error in __umodti3: 0x%llX%.16llX %% 0x%llX%.16llX = "
37*4684ddb6SLionel Sambuc "0x%llX%.16llX, expected 0x%llX%.16llX\n",
38*4684ddb6SLionel Sambuc at.s.high, at.s.low, bt.s.high, bt.s.low, rt.s.high, rt.s.low,
39*4684ddb6SLionel Sambuc expected_rt.s.high, expected_rt.s.low);
40*4684ddb6SLionel Sambuc }
41*4684ddb6SLionel Sambuc return r != expected_r;
42*4684ddb6SLionel Sambuc }
43*4684ddb6SLionel Sambuc
44*4684ddb6SLionel Sambuc #endif
45*4684ddb6SLionel Sambuc
main()46*4684ddb6SLionel Sambuc int main()
47*4684ddb6SLionel Sambuc {
48*4684ddb6SLionel Sambuc #if __x86_64
49*4684ddb6SLionel Sambuc if (test__umodti3(0, 1, 0))
50*4684ddb6SLionel Sambuc return 1;
51*4684ddb6SLionel Sambuc if (test__umodti3(2, 1, 0))
52*4684ddb6SLionel Sambuc return 1;
53*4684ddb6SLionel Sambuc if (test__umodti3(make_tu(0x8000000000000000uLL, 0), 1, 0x0uLL))
54*4684ddb6SLionel Sambuc return 1;
55*4684ddb6SLionel Sambuc if (test__umodti3(make_tu(0x8000000000000000uLL, 0), 2, 0x0uLL))
56*4684ddb6SLionel Sambuc return 1;
57*4684ddb6SLionel Sambuc if (test__umodti3(make_tu(0xFFFFFFFFFFFFFFFFuLL, 0xFFFFFFFFFFFFFFFFuLL),
58*4684ddb6SLionel Sambuc 2, 0x1uLL))
59*4684ddb6SLionel Sambuc return 1;
60*4684ddb6SLionel Sambuc
61*4684ddb6SLionel Sambuc #else
62*4684ddb6SLionel Sambuc printf("skipped\n");
63*4684ddb6SLionel Sambuc #endif
64*4684ddb6SLionel Sambuc return 0;
65*4684ddb6SLionel Sambuc }
66