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