Author: Richard Plangger <planri...@gmail.com> Branch: s390x-backend Changeset: r80214:b21ba89abdb2 Date: 2015-10-14 19:01 +0200 http://bitbucket.org/pypy/pypy/changeset/b21ba89abdb2/
Log: extending to the different opcode formats, now supporting agr the 64 bit version of signed integer add! 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 @@ -24,13 +24,41 @@ self.BL(addr, c) return f +class Operand(object): + pass -codes = { - 'ADD_rr': 0x1A, +def build_rr(mnemonic, args): + opcode = args[0] + assert isinstance(opcode, str) + def encode_rr(self, reg1, reg2): + self.writechar(opcode) + operands = ((reg2 & 0x0f) << 4) | (reg1 & 0xf) + self.writechar(chr(operands)) + return encode_rr + +def build_rre(mnemonic, args): + opcode1,opcode2 = args[0] + assert isinstance(opcode1, str) + assert isinstance(opcode2, str) + def encode_rr(self, reg1, reg2): + self.writechar(opcode1) + self.writechar(opcode2) + self.writechar('\x00') + #self.writechar('\x00') + operands = ((reg2 & 0x0f) << 4) | (reg1 & 0xf) + self.writechar(chr(operands)) + return encode_rr + +_mnemonic_codes = { + 'AR': (build_rr, ['\x1A']), + 'AGR': (build_rre, ['\xB9\x08']) } -def encode_rr(reg1, reg2): - return chr(((reg2 & 0x0f) << 4) | (reg1 & 0xf)) +def build_instr_codes(clazz): + for mnemonic, (builder, args) in _mnemonic_codes.items(): + func = builder(mnemonic, args) + name = mnemonic + "_" + builder.__name__.split("_")[1] + setattr(clazz, name, func) class AbstractZARCHBuilder(object): def write32(self, word): @@ -43,6 +71,9 @@ self.writechar(chr(0x1A)) self.writechar(encode_rr(reg1, reg2)) +build_instr_codes(AbstractZARCHBuilder) + + class InstrBuilder(BlockBuilderMixin, AbstractZARCHBuilder): def __init__(self): diff --git a/rpython/jit/backend/zarch/test/test_auto_encoding.py b/rpython/jit/backend/zarch/test/test_auto_encoding.py --- a/rpython/jit/backend/zarch/test/test_auto_encoding.py +++ b/rpython/jit/backend/zarch/test/test_auto_encoding.py @@ -4,6 +4,7 @@ from rpython.jit.backend.zarch import codebuilder from rpython.rlib.rarithmetic import intmask from rpython.tool.udir import udir +import itertools INPUTNAME = 'checkfile_%s.s' FILENAME = 'checkfile_%s.o' @@ -26,8 +27,8 @@ and self.index == self.instrindex): return # ignore the extra character '\x40' print self.op - print "\x09from codebuilder.py:", hexdump(self.expected[self.instrindex:self.index] + char)+"..." - print "\x09from 'as': ", hexdump(self.expected[self.instrindex:self.index+15])+"..." + print "\x09from codebuilder.py: ", hexdump(self.expected[self.instrindex:self.index] + char)+"..." + print "\x09from 'as': ", hexdump(self.expected[self.instrindex:self.index+15])+"..." raise Exception("Differs") self.index += 1 @@ -113,6 +114,7 @@ def get_all_tests(self): return { 'r': self.reg_tests, + 'e': lambda: [], } def assembler_operand_reg(self, regnum): @@ -207,38 +209,20 @@ return oplist, as_code def make_all_tests(self, methname, modes, args=[]): - if modes: - tests = self.get_all_tests() - m = modes[0] - lst = tests[m]() - random.shuffle(lst) - if methname == 'PSRAD_xi' and m == 'i': - lst = [x for x in lst if 0 <= x <= 31] - result = [] - for v in lst: - result += self.make_all_tests(methname, modes[1:], args+[v]) - return result - else: - # special cases - if methname in ('ADD_ri', 'AND_ri', 'CMP_ri', 'OR_ri', - 'SUB_ri', 'XOR_ri', 'SBB_ri'): - if args[0] == rx86.R.eax: - return [] # ADD EAX, constant: there is a special encoding - if methname in ('CMP8_ri',): - if args[0] == rx86.R.al: - return [] # CMP AL, constant: there is a special encoding - if methname == 'XCHG_rr' and rx86.R.eax in args: - return [] # special encoding - if methname == 'MOV_rj' and args[0] == rx86.R.eax: - return [] # MOV EAX, [immediate]: there is a special encoding - if methname == 'MOV_jr' and args[1] == rx86.R.eax: - return [] # MOV [immediate], EAX: there is a special encoding - if methname == 'MOV8_rj' and args[0] == rx86.R.al: - return [] # MOV AL, [immediate]: there is a special encoding - if methname == 'MOV8_jr' and args[1] == rx86.R.al: - return [] # MOV [immediate], AL: there is a special encoding - - return [args] + tests = { + 'r': self.REGS, + 'e': None, + } + combinations = [] + for m in modes: + if tests[m] is not None: + elems = tests[m] + random.shuffle(elems) + combinations.append(elems) + results = [] + for args in itertools.product(*combinations): + results.append(args) + return results def should_skip_instruction(self, instrname, argmodes): return False _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit