forked from OSchip/llvm-project
<rdar://problem/8914924> implement udivmodsi4 and divmodsi4 for ARM
llvm-svn: 127778
This commit is contained in:
parent
b1db4b69cc
commit
47a823b281
|
@ -77,8 +77,12 @@ ti_int __modti3 (ti_int a, ti_int b); // a % b signed
|
||||||
su_int __umodsi3 (su_int a, su_int b); // a % b unsigned
|
su_int __umodsi3 (su_int a, su_int b); // a % b unsigned
|
||||||
du_int __umoddi3 (du_int a, du_int b); // a % b unsigned
|
du_int __umoddi3 (du_int a, du_int b); // a % b unsigned
|
||||||
tu_int __umodti3 (tu_int a, tu_int b); // a % b unsigned
|
tu_int __umodti3 (tu_int a, tu_int b); // a % b unsigned
|
||||||
du_int __udivmoddi4(du_int a, du_int b, du_int* rem); // a / b, *rem = a % b
|
du_int __udivmoddi4(du_int a, du_int b, du_int* rem); // a / b, *rem = a % b unsigned
|
||||||
tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem); // a / b, *rem = a % b
|
tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem); // a / b, *rem = a % b unsigned
|
||||||
|
su_int __udivmodsi4(su_int a, su_int b, su_int* rem); // a / b, *rem = a % b unsigned
|
||||||
|
si_int __divmodsi4(si_int a, si_int b, si_int* rem); // a / b, *rem = a % b signed
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Integral arithmetic with trapping overflow
|
// Integral arithmetic with trapping overflow
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*===-- divmodsi4.c - Implement __divmodsi4 --------------------------------===
|
||||||
|
*
|
||||||
|
* The LLVM Compiler Infrastructure
|
||||||
|
*
|
||||||
|
* This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
* Source Licenses. See LICENSE.TXT for details.
|
||||||
|
*
|
||||||
|
* ===----------------------------------------------------------------------===
|
||||||
|
*
|
||||||
|
* This file implements __divmodsi4 for the compiler_rt library.
|
||||||
|
*
|
||||||
|
* ===----------------------------------------------------------------------===
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "int_lib.h"
|
||||||
|
|
||||||
|
extern si_int __divsi3(si_int a, si_int b);
|
||||||
|
|
||||||
|
|
||||||
|
/* Returns: a / b, *rem = a % b */
|
||||||
|
|
||||||
|
si_int
|
||||||
|
__divmodsi4(si_int a, si_int b, si_int* rem)
|
||||||
|
{
|
||||||
|
si_int d = __divsi3(a,b);
|
||||||
|
*rem = a - (d*b);
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*===-- udivmodsi4.c - Implement __udivmodsi4 ------------------------------===
|
||||||
|
*
|
||||||
|
* The LLVM Compiler Infrastructure
|
||||||
|
*
|
||||||
|
* This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
* Source Licenses. See LICENSE.TXT for details.
|
||||||
|
*
|
||||||
|
* ===----------------------------------------------------------------------===
|
||||||
|
*
|
||||||
|
* This file implements __udivmodsi4 for the compiler_rt library.
|
||||||
|
*
|
||||||
|
* ===----------------------------------------------------------------------===
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "int_lib.h"
|
||||||
|
|
||||||
|
extern su_int __udivsi3(su_int n, su_int d);
|
||||||
|
|
||||||
|
|
||||||
|
/* Returns: a / b, *rem = a % b */
|
||||||
|
|
||||||
|
su_int
|
||||||
|
__udivmodsi4(su_int a, su_int b, su_int* rem)
|
||||||
|
{
|
||||||
|
si_int d = __udivsi3(a,b);
|
||||||
|
*rem = a - (d*b);
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,10 +61,10 @@ FUNCTIONS.armv5 := $(FUNCTIONS) \
|
||||||
muldf3 mulsf3 \
|
muldf3 mulsf3 \
|
||||||
negdf2 negsf2 \
|
negdf2 negsf2 \
|
||||||
truncdfsf2 \
|
truncdfsf2 \
|
||||||
modsi3 umodsi3 udivsi3 divsi3 \
|
modsi3 umodsi3 udivsi3 divsi3 udivmodsi4 divmodsi4 \
|
||||||
switch8 switchu8 switch16 switch32 \
|
switch8 switchu8 switch16 switch32 \
|
||||||
sync_synchronize
|
sync_synchronize
|
||||||
|
|
||||||
FUNCTIONS.armv6 := $(FUNCTIONS) \
|
FUNCTIONS.armv6 := $(FUNCTIONS) \
|
||||||
comparedf2 comparesf2 \
|
comparedf2 comparesf2 \
|
||||||
adddf3vfp addsf3vfp bswapdi2 bswapsi2 divdf3vfp \
|
adddf3vfp addsf3vfp bswapdi2 bswapsi2 divdf3vfp \
|
||||||
|
@ -76,10 +76,11 @@ FUNCTIONS.armv6 := $(FUNCTIONS) \
|
||||||
muldf3vfp mulsf3vfp \
|
muldf3vfp mulsf3vfp \
|
||||||
nedf2vfp nesf2vfp \
|
nedf2vfp nesf2vfp \
|
||||||
subdf3vfp subsf3vfp truncdfsf2vfp unorddf2vfp unordsf2vfp \
|
subdf3vfp subsf3vfp truncdfsf2vfp unorddf2vfp unordsf2vfp \
|
||||||
modsi3 umodsi3 udivsi3 divsi3 \
|
modsi3 umodsi3 udivsi3 divsi3 udivmodsi4 divmodsi4 \
|
||||||
switch8 switchu8 switch16 switch32 \
|
switch8 switchu8 switch16 switch32 \
|
||||||
restore_vfp_d8_d15_regs save_vfp_d8_d15_regs \
|
restore_vfp_d8_d15_regs save_vfp_d8_d15_regs \
|
||||||
sync_synchronize
|
sync_synchronize
|
||||||
|
|
||||||
FUNCTIONS.armv7 := $(FUNCTIONS) \
|
FUNCTIONS.armv7 := $(FUNCTIONS) \
|
||||||
comparedf2 comparesf2 \
|
comparedf2 comparesf2 \
|
||||||
adddf3vfp addsf3vfp bswapdi2 bswapsi2 divdf3vfp \
|
adddf3vfp addsf3vfp bswapdi2 bswapsi2 divdf3vfp \
|
||||||
|
@ -91,5 +92,5 @@ FUNCTIONS.armv7 := $(FUNCTIONS) \
|
||||||
muldf3vfp mulsf3vfp \
|
muldf3vfp mulsf3vfp \
|
||||||
nedf2vfp nesf2vfp \
|
nedf2vfp nesf2vfp \
|
||||||
subdf3vfp subsf3vfp truncdfsf2vfp unorddf2vfp unordsf2vfp \
|
subdf3vfp subsf3vfp truncdfsf2vfp unorddf2vfp unordsf2vfp \
|
||||||
modsi3 umodsi3 udivsi3 divsi3
|
modsi3 umodsi3 udivsi3 divsi3 udivmodsi4 divmodsi4
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
//===-- divmodsi4_test.c - Test __divmodsi4 -------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// This file tests __divmodsi4 for the compiler_rt library.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "int_lib.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// Returns: a / b
|
||||||
|
|
||||||
|
extern si_int __divmodsi4(si_int a, si_int b, si_int* rem);
|
||||||
|
|
||||||
|
|
||||||
|
int test__divmodsi4(si_int a, si_int b,
|
||||||
|
si_int expected_result, si_int expected_rem)
|
||||||
|
{
|
||||||
|
si_int rem;
|
||||||
|
si_int result = __divmodsi4(a, b, &rem);
|
||||||
|
if (result != expected_result) {
|
||||||
|
printf("error in __divmodsi4: %d / %d = %d, expected %d\n",
|
||||||
|
a, b, result, expected_result);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (rem != expected_rem) {
|
||||||
|
printf("error in __divmodsi4: %d mod %d = %d, expected %d\n",
|
||||||
|
a, b, rem, expected_rem);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
if (test__divmodsi4(0, 1, 0, 0))
|
||||||
|
return 1;
|
||||||
|
if (test__divmodsi4(0, -1, 0, 0))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (test__divmodsi4(2, 1, 2, 0))
|
||||||
|
return 1;
|
||||||
|
if (test__divmodsi4(2, -1, -2, 0))
|
||||||
|
return 1;
|
||||||
|
if (test__divmodsi4(-2, 1, -2, 0))
|
||||||
|
return 1;
|
||||||
|
if (test__divmodsi4(-2, -1, 2, 0))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (test__divmodsi4(7, 5, 1, 2))
|
||||||
|
return 1;
|
||||||
|
if (test__divmodsi4(-7, 5, -1, -2))
|
||||||
|
return 1;
|
||||||
|
if (test__divmodsi4(19, 5, 3, 4))
|
||||||
|
return 1;
|
||||||
|
if (test__divmodsi4(19, -5, -3, 4))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (test__divmodsi4(0x80000000, 8, 0xf0000000, 0))
|
||||||
|
return 1;
|
||||||
|
if (test__divmodsi4(0x80000007, 8, 0xf0000001, -1))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
//===-- udivmodsi4_test.c - Test __udivmodsi4 -----------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// This file tests __udivmodsi4 for the compiler_rt library.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "int_lib.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// Returns: a / b
|
||||||
|
|
||||||
|
extern su_int __udivmodsi4(su_int a, su_int b, su_int* rem);
|
||||||
|
|
||||||
|
int test__udivmodsi4(su_int a, su_int b,
|
||||||
|
su_int expected_result, su_int expected_rem)
|
||||||
|
{
|
||||||
|
su_int rem;
|
||||||
|
su_int result = __udivmodsi4(a, b, &rem);
|
||||||
|
if (result != expected_result) {
|
||||||
|
printf("error in __udivmodsi4: %u / %u = %u, expected %u\n",
|
||||||
|
a, b, result, expected_result);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (rem != expected_rem) {
|
||||||
|
printf("error in __udivmodsi4: %u mod %u = %u, expected %u\n",
|
||||||
|
a, b, rem, expected_rem);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
if (test__udivmodsi4(0, 1, 0, 0))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (test__udivmodsi4(2, 1, 2, 0))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (test__udivmodsi4(19, 5, 3, 4))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (test__udivmodsi4(0x80000000, 8, 0x10000000, 0))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (test__udivmodsi4(0x80000003, 8, 0x10000000, 3))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue