[pypy-svn] r18407 - in pypy/dist/pypy/translator/asm: . test
mwh at codespeak.net
mwh at codespeak.net
Tue Oct 11 16:26:44 CEST 2005
Author: mwh
Date: Tue Oct 11 16:26:42 2005
New Revision: 18407
Modified:
pypy/dist/pypy/translator/asm/genasm.py
pypy/dist/pypy/translator/asm/infregmachine.py
pypy/dist/pypy/translator/asm/test/test_asm.py
Log:
(mwh, andrewt)
A new test (a loop!) and associated fixes that turned out to be
required:
- check number and type of input and output arguments
- integer multiplication, less than calculation
- less wasteful condition register bit manipulation
- allow passing of constants across links.
Modified: pypy/dist/pypy/translator/asm/genasm.py
==============================================================================
--- pypy/dist/pypy/translator/asm/genasm.py (original)
+++ pypy/dist/pypy/translator/asm/genasm.py Tue Oct 11 16:26:42 2005
@@ -1,6 +1,7 @@
import sys, os
from pypy.objspace.flow.model import traverse, Block, Variable, Constant
from pypy.translator.asm import infregmachine
+from pypy.rpython.lltype import Signed
#Available Machine code targets (processor+operating system)
TARGET_UNKNOWN=0
@@ -38,12 +39,19 @@
graph = translator.getflowgraph(f)
+ retvar = graph.returnblock.inputargs[0]
+
+ assert retvar.concretetype is Signed
+
+ for v in graph.startblock.inputargs:
+ assert v.concretetype is Signed
+
g = FuncGenerator(graph)
g.gencode()
# g.assembler.dump()
finreg = g.assembler.allocate_registers(30)
- return make_func(finreg.assemble(), 'i', 'ii')
+ return make_func(finreg.assemble(), 'i', 'i'*len(graph.startblock.inputargs))
class FuncGenerator(object):
@@ -97,7 +105,7 @@
def genlinkcode(self, link):
A = self.assembler
for s, t in zip(link.args, link.target.inputargs):
- if s.name != t.name:
+ if isinstance(s, Constant) or s.name != t.name:
A.emit('MOV', self.reg(t), self.reg(s))
A.emit('J', self.blocktarget(link.target))
Modified: pypy/dist/pypy/translator/asm/infregmachine.py
==============================================================================
--- pypy/dist/pypy/translator/asm/infregmachine.py (original)
+++ pypy/dist/pypy/translator/asm/infregmachine.py Tue Oct 11 16:26:42 2005
@@ -78,12 +78,18 @@
def int_add(self, A, dest, a, b):
A.add(dest + 2, a + 2, b + 2)
+ def int_sub(self, A, dest, a, b):
+ A.sub(dest + 2, a + 2, b + 2)
+
+ def int_mul(self, A, dest, a, b):
+ A.mullw(dest + 2, a + 2, b + 2)
+
def int_gt(self, A, a, b):
A.cmpw(a + 2, b + 2)
- A.mfcr(0)
- # copy bit 1 ('gt') of register 0 to bit 0 of register 0 ('lt')
- A.rlwimi(0, 0, 1, 0, 0)
- A.mtcr(0)
+ A.crmove(0, 1)
+
+ def int_lt(self, A, a, b):
+ A.cmpw(a + 2, b + 2)
def JT(self, A, branch):
# should be "A.bt(BI=0, BD=branch)" but this crashes.
@@ -92,9 +98,6 @@
def J(self, A, branch):
A.b(branch)
- def int_sub(self, A, dest, a, b):
- A.sub(dest + 2, a + 2, b + 2)
-
def RETPYTHON(self, A, reg):
A.mr(3, reg + 2)
A.blr()
Modified: pypy/dist/pypy/translator/asm/test/test_asm.py
==============================================================================
--- pypy/dist/pypy/translator/asm/test/test_asm.py (original)
+++ pypy/dist/pypy/translator/asm/test/test_asm.py Tue Oct 11 16:26:42 2005
@@ -46,3 +46,19 @@
assert f(2, 3) == testfn(2, 3)
assert f(-2, 3) == testfn(-2, 3)
+
+ def test_loop(self):
+ def testfn(lim=int):
+ r = 0
+ i = 0
+ while i < lim:
+ r += i*i
+ i += 1
+ return r
+ f = self.getcompiled(testfn)#, view=True)
+
+ assert f(0) == testfn(0)
+ assert f(10) == testfn(10)
+ assert f(100) == testfn(100)
+ assert f(1000) == testfn(1000)
+
More information about the Pypy-commit
mailing list