Author: Richard Plangger <[email protected]>
Branch: s390x-backend
Changeset: r80372:81756cc1745e
Date: 2015-10-21 10:50 +0200
http://bitbucket.org/pypy/pypy/changeset/81756cc1745e/
Log: added BRAS (short version), load from memory 64 bit (LG), testing
constant pool access
diff --git a/rpython/jit/backend/zarch/codebuilder.py
b/rpython/jit/backend/zarch/codebuilder.py
--- a/rpython/jit/backend/zarch/codebuilder.py
+++ b/rpython/jit/backend/zarch/codebuilder.py
@@ -40,6 +40,10 @@
self.writechar(chr((word >> 8) & 0xFF))
self.writechar(chr(word & 0xFF))
+ def write(self, bytestr):
+ for char in bytestr:
+ self.writechar(char)
+
build_instr_codes(AbstractZARCHBuilder)
class InstrBuilder(BlockBuilderMixin, AbstractZARCHBuilder):
@@ -78,7 +82,7 @@
def copy_to_raw_memory(self, addr):
self._copy_to_raw_memory(addr)
self.clear_cache(addr)
- self._dump(addr, "jit-backend-dump", 'arm')
+ self._dump(addr, "jit-backend-dump", "s390x")
def currpos(self):
return self.get_relative_pos()
diff --git a/rpython/jit/backend/zarch/instruction_builder.py
b/rpython/jit/backend/zarch/instruction_builder.py
--- a/rpython/jit/backend/zarch/instruction_builder.py
+++ b/rpython/jit/backend/zarch/instruction_builder.py
@@ -1,7 +1,15 @@
from rpython.jit.backend.zarch.instructions import (all_mnemonic_codes,)
from rpython.rtyper.lltypesystem.rbuilder import always_inline
from rpython.rlib.unroll import unrolling_iterable
+from rpython.jit.backend.zarch import locations as loc
+def dummy_argument(arg):
+ """ NOT_RPYTHON """
+ if arg == 'r' or arg == 'r/m':
+ return 0
+ if arg.startswith('i') or arg.startswith('u'):
+ return 0
+ return loc.addr(0)
class builder(object):
""" NOT_RPYTHON """
@@ -23,8 +31,22 @@
note that a suffix 'l' means long, and a prefix length
"""
+ class Counter(object):
+ def __init__(self):
+ self.counter = 0
+ def writechar(self, char):
+ self.counter += 1
+ def write_i16(self, _):
+ self.counter += 2
+ def write_i32(self, _):
+ self.counter += 4
def impl(func):
func._arguments_ = args_str.split(',')
+ args = [dummy_argument(a) for a in func._arguments_]
+ c = Counter()
+ # invoke it once and get the amount of bytes
+ func(c, *args)
+ func._byte_count = c.counter
return func
return impl
@@ -270,6 +292,7 @@
newargs[i] = args[i]
return func(self, *newargs)
function.__name__ = mnemonic
+ function._byte_count = func._byte_count
return function
def is_branch_relative(name):
@@ -277,11 +300,7 @@
def build_instr_codes(clazz):
for mnemonic, params in all_mnemonic_codes.items():
- options = {}
- if len(params) == 2:
- (instrtype, args) = params
- else:
- (instrtype, args, options) = params
+ (instrtype, args) = params
builder = globals()['build_' + instrtype]
func = builder(mnemonic, args)
name = mnemonic + "_" + instrtype
diff --git a/rpython/jit/backend/zarch/instructions.py
b/rpython/jit/backend/zarch/instructions.py
--- a/rpython/jit/backend/zarch/instructions.py
+++ b/rpython/jit/backend/zarch/instructions.py
@@ -1,6 +1,7 @@
branch_mnemonic_codes = {
'BRASL': ('ril', ['\xC0','\x05']),
+ 'BRAS': ('ri', ['\xA7','\x05']),
'BCR': ('rr', ['\x07']),
'BC': ('rx', ['\x47']),
'BRC': ('ri', ['\xA7','\x04']),
@@ -14,6 +15,11 @@
'A': ('rx', ['\x5A']),
'SR': ('rr', ['\x1B']),
'SGR': ('rre', ['\xB9','\x09']),
+
+ 'AY': ('rxy', ['\xE3','\x5A']),
+ 'AG': ('rxy', ['\xE3','\x08']),
+ 'AGF': ('rxy', ['\xE3','\x18']),
+ 'AHI': ('ri', ['\xA7','\x0A']),
}
logic_mnemonic_codes = {
@@ -23,6 +29,7 @@
# and one byte and store it back at the op2 position
'NI': ('si', ['\x94']),
'NIY': ('siy', ['\xEB','\x54']),
+ 'NC': ('ssa', ['\xD4']),
# AND immediate
'NIHH': ('ri_u', ['\xA5', '\x04']),
@@ -58,10 +65,6 @@
}
all_mnemonic_codes = {
- 'AY': ('rxy', ['\xE3','\x5A']),
- 'AG': ('rxy', ['\xE3','\x08']),
- 'AGF': ('rxy', ['\xE3','\x18']),
- 'AHI': ('ri', ['\xA7','\x0A']),
#
'BXH': ('rs', ['\x86']),
'BXHG': ('rsy', ['\xEB','\x44']),
@@ -70,7 +73,6 @@
#
'NI': ('si', ['\x94']),
'NIY': ('siy', ['\xEB','\x54']),
- 'NC': ('ssa', ['\xD4']),
'AP': ('ssb', ['\xFA']),
'SRP': ('ssc', ['\xF0']),
'MVCK': ('ssd', ['\xD9']),
@@ -81,6 +83,7 @@
'LGHI': ('ri', ['\xA7','\x09']),
'LR': ('rr', ['\x18']),
'LGR': ('rre', ['\xB9','\x04']),
+ 'LG': ('rxy', ['\xE3','\x04']),
'PKA': ('ssf', ['\xE9']),
'STMG': ('rsy', ['\xEB','\x24']),
diff --git a/rpython/jit/backend/zarch/locations.py
b/rpython/jit/backend/zarch/locations.py
--- a/rpython/jit/backend/zarch/locations.py
+++ b/rpython/jit/backend/zarch/locations.py
@@ -170,18 +170,21 @@
class AddressLocation(AssemblerLocation):
_immutable_ = True
- def __init__(self, basereg, indexreg, displace):
+ def __init__(self, basereg, indexreg, displace, length):
self.displace = displace
# designates the absense of an index/base register!
self.base = 0
self.index = 0
+ self.length = 0
if basereg:
self.base = basereg.value
if indexreg:
self.index = indexreg.value
+ if length:
+ self.length = length.value
-def addr(displace, basereg=None, indexreg=None):
- return AddressLocation(basereg, indexreg, displace)
+def addr(displace, basereg=None, indexreg=None, length=None):
+ return AddressLocation(basereg, indexreg, displace, length)
def imm(i):
return ImmLocation(i)
diff --git a/rpython/jit/backend/zarch/test/test_assembler.py
b/rpython/jit/backend/zarch/test/test_assembler.py
--- a/rpython/jit/backend/zarch/test/test_assembler.py
+++ b/rpython/jit/backend/zarch/test/test_assembler.py
@@ -18,6 +18,9 @@
CPU = getcpuclass()
+def byte_count(func):
+ return func._byte_count
+
class TestRunningAssembler(object):
def setup_method(self, method):
cpu = CPU(None, None)
@@ -28,6 +31,7 @@
clt.allgcrefs = []
token.compiled_loop_token = clt
self.a.setup(token)
+ self.mc = self.a.mc
def test_make_operation_list(self):
i = rop.INT_ADD
@@ -35,6 +39,10 @@
assert assembler.asm_operations[i] \
is AssemblerZARCH.emit_op_int_add.im_func
+ def test_byte_count_instr(self):
+ byte_count(self.mc.BRC) == 4
+ byte_count(self.mc.LG) == 6
+
def test_load_small_int_to_reg(self):
self.a.mc.LGHI(reg.r2, loc.imm(123))
self.a.jmpto(reg.r14)
@@ -93,3 +101,13 @@
self.a.mc.XGR(reg.r2, reg.r2)
self.a.jmpto(reg.r14)
assert run_asm(self.a) == 0
+
+ def test_literal_pool(self):
+ self.a.gen_func_prolog()
+ self.a.mc.BRAS(reg.r13, loc.imm(8 + byte_count(self.mc.BRAS)))
+ self.a.mc.write('\x08\x07\x06\x05\x04\x03\x02\x01')
+ self.a.mc.LG(reg.r2, loc.addr(0, reg.r13))
+ self.a.gen_func_epilog()
+ assert run_asm(self.a) == 0x0807060504030201
+
+
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit