Author: Richard Plangger <planri...@gmail.com> Branch: s390x-backend Changeset: r80387:ec9e69c4ffde Date: 2015-10-22 13:20 +0200 http://bitbucket.org/pypy/pypy/changeset/ec9e69c4ffde/
Log: allocated memory, and stored float result into it, correctly read it afterwards 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 @@ -90,6 +90,22 @@ byte = displace >> 12 & 0xff mc.writechar(chr(byte)) +@always_inline +def encode_index_base_displace(mc, reg, idxbasedisp): + """ + +----------------------------------------------------+ + | opcode | reg & index | base & displace[0:11] | ... | + +----------------------------------------------------+ + """ + index = idxbasedisp.index + byte = (reg & 0x0f) << 4 | index & 0xf + mc.writechar(chr(byte)) + displace = idxbasedisp.displace & BIT_MASK_12 + base = idxbasedisp.base & 0xf + byte = displace >> 8 & 0xf | base << 4 + mc.writechar(chr(byte)) + mc.writechar(chr(displace & 0xff)) + def build_i(mnemonic, (opcode,)): @builder.arguments('u8') def encode_i(self, imm): @@ -119,14 +135,7 @@ @builder.arguments('r/m,bid') def encode_rx(self, reg_or_mask, idxbasedisp): self.writechar(opcode) - index = idxbasedisp.index - byte = (reg_or_mask & 0x0f) << 4 | index & 0xf - self.writechar(chr(byte)) - displace = idxbasedisp.displace & BIT_MASK_12 - base = idxbasedisp.base & 0xf - byte = displace >> 8 & 0xf | base << 4 - self.writechar(chr(byte)) - self.writechar(chr(displace & 0xff)) + encode_index_base_displace(self, reg_or_mask, idxbasedisp) return encode_rx def build_rxy(mnemonic, (opcode1,opcode2)): @@ -293,20 +302,37 @@ self.writechar(opcode2) return encode_ri -def _build_rrf(args): - def build_rff(mnemonic, (opcode1,opcode2)): - @builder.arguments(args) - def encode_rrf(self, r1, rm3, r2, rm4): - self.writechar(opcode1) - self.writechar(opcode2) - byte = (rm3 & BIT_MASK_4) << 4 | (rm4 & BIT_MASK_4) - self.writechar(chr(byte)) - byte = (r1 & BIT_MASK_4) << 4 | (r2 & BIT_MASK_4) - self.writechar(chr(byte)) - return encode_rrf - return build_rff +def build_rrf(mnemonic, (opcode1,opcode2,argtypes)): + @builder.arguments(argtypes) + def encode_rrf(self, r1, rm3, r2, rm4): + self.writechar(opcode1) + self.writechar(opcode2) + byte = (rm3 & BIT_MASK_4) << 4 | (rm4 & BIT_MASK_4) + self.writechar(chr(byte)) + byte = (r1 & BIT_MASK_4) << 4 | (r2 & BIT_MASK_4) + self.writechar(chr(byte)) + return encode_rrf -build_rrf = _build_rrf('r,u4,r,-') +def build_rxe(mnemonic, (opcode1,opcode2,argtypes)): + @builder.arguments(argtypes) + def encode_rxe(self, reg, idxbasedisp, mask): + self.writechar(opcode1) + encode_index_base_displace(self, reg, idxbasedisp) + self.writechar(chr((mask & 0xf) << 4)) + self.writechar(opcode2) + return encode_rxe + +def build_rxf(mnemonic, (opcode1,opcode2)): + @builder.arguments('r,bidl,r/m') + def encode_rxe(self, reg1, idxbasedisp, reg3): + self.writechar(opcode1) + index = idxbasedisp.index + byte = (reg3 & 0x0f) << 4 | index & 0xf + self.writechar(chr(byte)) + encode_base_displace_long(self, reg, idxbasedisp) + self.writechar(chr((reg1 & 0xf) << 4)) + self.writechar(opcode2) + return encode_rxe def build_unpack_func(mnemonic, func): def function(self, *args): @@ -330,7 +356,12 @@ def build_instr_codes(clazz): for mnemonic, params in all_mnemonic_codes.items(): - (instrtype, args) = params + argtypes = None + if len(params) == 2: + (instrtype, args) = params + else: + (instrtype, args, argtypes) = params + args = tuple(list(args) + [argtypes]) 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 @@ -79,6 +79,9 @@ 'LGR': ('rre', ['\xB9','\x04']), 'LG': ('rxy', ['\xE3','\x04']), + 'STE': ('rx', ['\x70']), + 'STD': ('rx', ['\x60']), + # load binary float # E -> short (32bit), # D -> long (64bit), @@ -92,11 +95,17 @@ } floatingpoint_mnemonic_codes = { - 'FIEBR': ('rrf', ['\xB3','\x57']), - 'FIDBR': ('rrf', ['\xB3','\x5F']), + 'FIEBR': ('rrf', ['\xB3','\x57'], 'r,u4,r,-'), + 'FIDBR': ('rrf', ['\xB3','\x5F'], 'r,u4,r,-'), - 'CGEBR': ('rrf', ['\xB3','\xA8']), - 'CGDBR': ('rrf', ['\xB3','\xA9']), + 'CGEBR': ('rrf', ['\xB3','\xA8'], 'r,u4,r,-'), + 'CGDBR': ('rrf', ['\xB3','\xA9'], 'r,u4,r,-'), + + # arithmetic + 'AEBR': ('rre', ['\xB3','\x0A']), + 'ADBR': ('rre', ['\xB3','\x1A']), + 'AEB': ('rxe', ['\xED','\x0A'], 'r,bidl,-'), + 'ADB': ('rxe', ['\xED','\x1A'], 'r,bidl,-'), } all_mnemonic_codes = { 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 @@ -10,14 +10,16 @@ from rpython.jit.codewriter import longlong from rpython.rtyper.annlowlevel import llhelper -from rpython.rtyper.lltypesystem import lltype, rffi +from rpython.rtyper.lltypesystem import lltype, rffi, ll2ctypes from rpython.jit.metainterp.history import JitCellToken from rpython.jit.backend.model import CompiledLoopToken from rpython.rtyper.lltypesystem import lltype, llmemory, rffi from rpython.rtyper.annlowlevel import llhelper from rpython.rlib.objectmodel import specialize from rpython.rlib.debug import ll_assert -from rpython.rlib.longlong2float import float2longlong +from rpython.rlib.longlong2float import (float2longlong, + DOUBLE_ARRAY_PTR) +import ctypes CPU = getcpuclass() @@ -25,11 +27,14 @@ return func._byte_count def BFL(value): - #assert 0x0000000000000000 == float2longlong(0.0) - #assert 0x8000000000000000 == abs(float2longlong(-0.0)) - #assert hex(0xc02e000000000000) == hex(abs(float2longlong(-15.0))) return struct.pack('>q', float2longlong(value)) +def ADDR(value): + ptr = ll2ctypes.lltype2ctypes(value) + addr = ctypes.addressof(ptr.contents.items) + print hex(addr) + return struct.pack('>Q', addr) + class TestRunningAssembler(object): def setup_method(self, method): cpu = CPU(None, None) @@ -204,3 +209,21 @@ self.mc.CGDBR(reg.r2, msk.RND_CURMODE, reg.f0) self.a.jmpto(reg.r14) assert run_asm(self.a) == -15 + + def test_float_to_memory(self): + with lltype.scoped_alloc(DOUBLE_ARRAY_PTR.TO, 16) as mem: + with self.label('func', func=True): + with self.label('lit'): + self.mc.BRAS(reg.r13, loc.imm(0)) + self.mc.write(BFL(-15.0)) + self.mc.write(ADDR(mem)) + self.jump_here(self.mc.BRAS, 'lit') + self.mc.LD(reg.f0, loc.addr(0, reg.r13)) + self.mc.LDR(reg.f1, reg.f0) + self.mc.ADBR(reg.f0, reg.f1) + self.mc.LG(reg.r11, loc.addr(8, reg.r13)) + self.mc.STD(reg.f0, loc.addr(0, reg.r11)) + self.a.jmpto(reg.r14) + run_asm(self.a) + assert mem[0] == -30.0 + _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit