1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_divmodsi4
3 //===-- divmodsi4_test.c - Test __divmodsi4 -------------------------------===//
5 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 // See https://llvm.org/LICENSE.txt for license information.
7 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 //===----------------------------------------------------------------------===//
11 // This file tests __divmodsi4 for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
20 extern COMPILER_RT_ABI si_int
__divmodsi4(si_int a
, si_int b
, si_int
* rem
);
23 int test__divmodsi4(si_int a
, si_int b
,
24 si_int expected_result
, si_int expected_rem
)
27 si_int result
= __divmodsi4(a
, b
, &rem
);
28 if (result
!= expected_result
) {
29 printf("error in __divmodsi4: %d / %d = %d, expected %d\n",
30 a
, b
, result
, expected_result
);
33 if (rem
!= expected_rem
) {
34 printf("error in __divmodsi4: %d mod %d = %d, expected %d\n",
35 a
, b
, rem
, expected_rem
);
45 if (test__divmodsi4(0, 1, 0, 0))
47 if (test__divmodsi4(0, -1, 0, 0))
50 if (test__divmodsi4(2, 1, 2, 0))
52 if (test__divmodsi4(2, -1, -2, 0))
54 if (test__divmodsi4(-2, 1, -2, 0))
56 if (test__divmodsi4(-2, -1, 2, 0))
59 if (test__divmodsi4(7, 5, 1, 2))
61 if (test__divmodsi4(-7, 5, -1, -2))
63 if (test__divmodsi4(19, 5, 3, 4))
65 if (test__divmodsi4(19, -5, -3, 4))
68 if (test__divmodsi4(0x80000000, 8, 0xf0000000, 0))
70 if (test__divmodsi4(0x80000007, 8, 0xf0000001, -1))