1// RUN: %clang_builtins %s %librt -o %t && %run %t
2// REQUIRES: librt_has_udivti3
3// REQUIRES: int128
4
5#include "int_lib.h"
6#include <stdio.h>
7
8#ifdef CRT_HAS_128BIT
9
10// Returns: a / b
11
12COMPILER_RT_ABI tu_int __udivti3(tu_int a, tu_int b);
13
14int test__udivti3(tu_int a, tu_int b, tu_int expected_q)
15{
16 tu_int q = __udivti3(a, b);
17 if (q != expected_q)
18 {
19 utwords at;
20 at.all = a;
21 utwords bt;
22 bt.all = b;
23 utwords qt;
24 qt.all = q;
25 utwords expected_qt;
26 expected_qt.all = expected_q;
27 printf(format: "error in __udivti3: 0x%llX%.16llX / 0x%llX%.16llX = "
28 "0x%llX%.16llX, expected 0x%llX%.16llX\n",
29 at.s.high, at.s.low, bt.s.high, bt.s.low, qt.s.high, qt.s.low,
30 expected_qt.s.high, expected_qt.s.low);
31 }
32 return q != expected_q;
33}
34
35#endif
36
37int main()
38{
39#ifdef CRT_HAS_128BIT
40 if (test__udivti3(a: 0, b: 1, expected_q: 0))
41 return 1;
42 if (test__udivti3(a: 2, b: 1, expected_q: 2))
43 return 1;
44 if (test__udivti3(a: make_tu(h: 0x8000000000000000uLL, l: 0), b: 1,
45 expected_q: make_tu(h: 0x8000000000000000uLL, l: 0)))
46 return 1;
47 if (test__udivti3(a: make_tu(h: 0x8000000000000000uLL, l: 0), b: 2,
48 expected_q: make_tu(h: 0x4000000000000000uLL, l: 0)))
49 return 1;
50 if (test__udivti3(a: make_tu(h: 0xFFFFFFFFFFFFFFFFuLL, l: 0xFFFFFFFFFFFFFFFFuLL), b: 2,
51 expected_q: make_tu(h: 0x7FFFFFFFFFFFFFFFuLL, l: 0xFFFFFFFFFFFFFFFFuLL)))
52 return 1;
53
54#else
55 printf("skipped\n");
56#endif
57 return 0;
58}
59

source code of compiler-rt/test/builtins/Unit/udivti3_test.c