blob: 5bce0258ae38f54aae1e16d5c6cd0b87a5efd8aa [file] [log] [blame]
Weiming Zhao9b7bbec2017-03-21 05:32:51 +00001// RUN: %clang_builtins %s %librt -o %t && %run %t
Daniel Dunbarfd089992009-06-26 16:47:03 +00002//===-- umodti3_test.c - Test __umodti3 -----------------------------------===//
3//
4// The LLVM Compiler Infrastructure
5//
Howard Hinnant5b791f62010-11-16 22:13:33 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Daniel Dunbarfd089992009-06-26 16:47:03 +00008//
9//===----------------------------------------------------------------------===//
10//
11// This file tests __umodti3 for the compiler_rt library.
12//
13//===----------------------------------------------------------------------===//
14
Daniel Dunbarfd089992009-06-26 16:47:03 +000015#include "int_lib.h"
16#include <stdio.h>
17
Joerg Sonnenberger14743122014-03-18 21:35:30 +000018#ifdef CRT_HAS_128BIT
19
Daniel Dunbarfd089992009-06-26 16:47:03 +000020// Returns: a % b
21
Derek Schuffeb0ebc32015-04-24 15:45:57 +000022COMPILER_RT_ABI tu_int __umodti3(tu_int a, tu_int b);
Daniel Dunbarfd089992009-06-26 16:47:03 +000023
24int test__umodti3(tu_int a, tu_int b, tu_int expected_r)
25{
26 tu_int r = __umodti3(a, b);
27 if (r != expected_r)
28 {
29 utwords at;
30 at.all = a;
31 utwords bt;
32 bt.all = b;
33 utwords rt;
34 rt.all = r;
35 utwords expected_rt;
36 expected_rt.all = expected_r;
37 printf("error in __umodti3: 0x%llX%.16llX %% 0x%llX%.16llX = "
38 "0x%llX%.16llX, expected 0x%llX%.16llX\n",
Daniel Dunbar64857202009-10-27 17:49:07 +000039 at.s.high, at.s.low, bt.s.high, bt.s.low, rt.s.high, rt.s.low,
40 expected_rt.s.high, expected_rt.s.low);
Daniel Dunbarfd089992009-06-26 16:47:03 +000041 }
42 return r != expected_r;
43}
44
45#endif
46
47int main()
48{
Joerg Sonnenberger14743122014-03-18 21:35:30 +000049#ifdef CRT_HAS_128BIT
Daniel Dunbarfd089992009-06-26 16:47:03 +000050 if (test__umodti3(0, 1, 0))
51 return 1;
52 if (test__umodti3(2, 1, 0))
53 return 1;
54 if (test__umodti3(make_tu(0x8000000000000000uLL, 0), 1, 0x0uLL))
55 return 1;
56 if (test__umodti3(make_tu(0x8000000000000000uLL, 0), 2, 0x0uLL))
57 return 1;
58 if (test__umodti3(make_tu(0xFFFFFFFFFFFFFFFFuLL, 0xFFFFFFFFFFFFFFFFuLL),
59 2, 0x1uLL))
60 return 1;
61
Joerg Sonnenbergerd9bcddd2011-05-29 21:43:29 +000062#else
63 printf("skipped\n");
Daniel Dunbarfd089992009-06-26 16:47:03 +000064#endif
65 return 0;
66}