[pypy-svn] pypy arm-backend-2: provide a c function wrapping div, unsigned div and mod which are called from the jit for the corresponding operations because arm's application profile does not implement these operations.
bivab
commits-noreply at bitbucket.org
Mon Feb 21 14:20:17 CET 2011
Author: David Schneider <david.schneider at picle.org>
Branch: arm-backend-2
Changeset: r42197:2fc7eab2a9ba
Date: 2011-02-20 21:19 +0100
http://bitbucket.org/pypy/pypy/changeset/2fc7eab2a9ba/
Log: provide a c function wrapping div, unsigned div and mod which are
called from the jit for the corresponding operations because arm's
application profile does not implement these operations.
diff --git a/pypy/jit/backend/arm/arch.py b/pypy/jit/backend/arm/arch.py
--- a/pypy/jit/backend/arm/arch.py
+++ b/pypy/jit/backend/arm/arch.py
@@ -1,3 +1,4 @@
+from pypy.rpython.lltypesystem import lltype, rffi
from pypy.rlib.rarithmetic import r_uint
from pypy.rpython.lltypesystem import lltype
@@ -6,16 +7,40 @@
# The Address in the PC points two words befind the current instruction
PC_OFFSET = 8
+from pypy.translator.tool.cbuild import ExternalCompilationInfo
+eci = ExternalCompilationInfo(post_include_bits=["""
+static int pypy__arm_int_div(int a, int b) {
+ return a/b;
+}
+static uint pypy__arm_uint_div(uint a, uint b) {
+ return a/b;
+}
+static int pypy__arm_int_mod(uint a, uint b) {
+ return a % b;
+}
+"""])
+
arm_int_div_sign = lltype.Ptr(lltype.FuncType([lltype.Signed, lltype.Signed], lltype.Signed))
-def arm_int_div(a, b):
+def arm_int_div_emulator(a, b):
return int(a/float(b))
+arm_int_div = rffi.llexternal(
+ "pypy__arm_int_div", [lltype.Signed, lltype.Signed], lltype.Signed,
+ _callable=arm_int_div_emulator,
+ compilation_info=eci,
+ _nowrapper=True, pure_function=True)
arm_uint_div_sign = lltype.Ptr(lltype.FuncType([lltype.Unsigned, lltype.Unsigned], lltype.Unsigned))
-def arm_uint_div(a, b):
+def arm_uint_div_emulator(a, b):
return r_uint(a)/r_uint(b)
+arm_uint_div = rffi.llexternal(
+ "pypy__arm_uint_div", [lltype.Unsigned, lltype.Unsigned], lltype.Unsigned,
+ _callable=arm_uint_div_emulator,
+ compilation_info=eci,
+ _nowrapper=True, pure_function=True)
+
arm_int_mod_sign = arm_int_div_sign
-def arm_int_mod(a, b):
+def arm_int_mod_emulator(a, b):
sign = 1
if a < 0:
a = -1 * a
@@ -24,4 +49,9 @@
b = -1 * b
res = a % b
return sign * res
+arm_int_mod = rffi.llexternal(
+ "pypy__arm_int_mod", [lltype.Signed, lltype.Signed], lltype.Signed,
+ _callable=arm_int_mod_emulator,
+ compilation_info=eci,
+ _nowrapper=True, pure_function=True)
diff --git a/pypy/jit/backend/arm/test/test_arch.py b/pypy/jit/backend/arm/test/test_arch.py
--- a/pypy/jit/backend/arm/test/test_arch.py
+++ b/pypy/jit/backend/arm/test/test_arch.py
@@ -15,3 +15,9 @@
assert arch.arm_int_mod(11, -2) == 1
assert arch.arm_int_mod(11, -3) == 2
+
+def test_div():
+ assert arch.arm_int_div(-7, 2) == -3
+ assert arch.arm_int_div(9, 2) == 4
+ assert arch.arm_int_div(10, 5) == 2
+
diff --git a/pypy/jit/backend/arm/codebuilder.py b/pypy/jit/backend/arm/codebuilder.py
--- a/pypy/jit/backend/arm/codebuilder.py
+++ b/pypy/jit/backend/arm/codebuilder.py
@@ -18,7 +18,7 @@
def f(self, c=cond.AL):
"""Generates a call to a helper function, takes its
arguments in r0 and r1, result is placed in r0"""
- addr = rffi.cast(lltype.Signed, llhelper(signature, function))
+ addr = rffi.cast(lltype.Signed, function)
if c == cond.AL:
self.BL(addr)
else:
More information about the Pypy-commit
mailing list