| 1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
| 2 | // REQUIRES: librt_has_divsi3 |
| 3 | |
| 4 | #include "int_lib.h" |
| 5 | #include <stdio.h> |
| 6 | |
| 7 | // Returns: a / b |
| 8 | |
| 9 | COMPILER_RT_ABI si_int __divsi3(si_int a, si_int b); |
| 10 | |
| 11 | int test__divsi3(si_int a, si_int b, si_int expected) |
| 12 | { |
| 13 | si_int x = __divsi3(a, b); |
| 14 | if (x != expected) |
| 15 | printf(format: "error in __divsi3: %d / %d = %d, expected %d\n" , |
| 16 | a, b, x, expected); |
| 17 | return x != expected; |
| 18 | } |
| 19 | |
| 20 | int main() |
| 21 | { |
| 22 | if (test__divsi3(a: 0, b: 1, expected: 0)) |
| 23 | return 1; |
| 24 | if (test__divsi3(a: 0, b: -1, expected: 0)) |
| 25 | return 1; |
| 26 | |
| 27 | if (test__divsi3(a: 2, b: 1, expected: 2)) |
| 28 | return 1; |
| 29 | if (test__divsi3(a: 2, b: -1, expected: -2)) |
| 30 | return 1; |
| 31 | if (test__divsi3(a: -2, b: 1, expected: -2)) |
| 32 | return 1; |
| 33 | if (test__divsi3(a: -2, b: -1, expected: 2)) |
| 34 | return 1; |
| 35 | |
| 36 | if (test__divsi3(a: 0x80000000, b: 1, expected: 0x80000000)) |
| 37 | return 1; |
| 38 | if (test__divsi3(a: 0x80000000, b: -1, expected: 0x80000000)) |
| 39 | return 1; |
| 40 | if (test__divsi3(a: 0x80000000, b: -2, expected: 0x40000000)) |
| 41 | return 1; |
| 42 | if (test__divsi3(a: 0x80000000, b: 2, expected: 0xC0000000)) |
| 43 | return 1; |
| 44 | |
| 45 | return 0; |
| 46 | } |
| 47 | |