| 1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
| 2 | // REQUIRES: librt_has_udivdi3 |
| 3 | |
| 4 | #include "int_lib.h" |
| 5 | #include <stdio.h> |
| 6 | |
| 7 | // Returns: a / b |
| 8 | |
| 9 | COMPILER_RT_ABI du_int __udivdi3(du_int a, du_int b); |
| 10 | |
| 11 | int test__udivdi3(du_int a, du_int b, du_int expected_q) |
| 12 | { |
| 13 | du_int q = __udivdi3(a, b); |
| 14 | if (q != expected_q) |
| 15 | printf(format: "error in __udivdi3: %lld / %lld = %lld, expected %lld\n" , |
| 16 | a, b, q, expected_q); |
| 17 | return q != expected_q; |
| 18 | } |
| 19 | |
| 20 | int main() |
| 21 | { |
| 22 | if (test__udivdi3(a: 0, b: 1, expected_q: 0)) |
| 23 | return 1; |
| 24 | if (test__udivdi3(a: 2, b: 1, expected_q: 2)) |
| 25 | return 1; |
| 26 | if (test__udivdi3(a: 0x8000000000000000uLL, b: 1, expected_q: 0x8000000000000000uLL)) |
| 27 | return 1; |
| 28 | if (test__udivdi3(a: 0x8000000000000000uLL, b: 2, expected_q: 0x4000000000000000uLL)) |
| 29 | return 1; |
| 30 | if (test__udivdi3(a: 0xFFFFFFFFFFFFFFFFuLL, b: 2, expected_q: 0x7FFFFFFFFFFFFFFFuLL)) |
| 31 | return 1; |
| 32 | |
| 33 | return 0; |
| 34 | } |
| 35 | |