def test_neg(self): a = PPCBuilder() a.load_imm(r10, 0x0000F0F0) a.neg(3, 10) a.blr() f = a.get_assembler_function() assert f() == hex_to_signed_int("FFFF0F10")
def test_xx3_instr(self): a = PPCBuilder() def assign_to_self(v): self.last_value = v a.emit = assign_to_self a.xxspltdl(32, 32, 32) # tttttaaaaabbbbb abt assert hex(int(self.last_value)) == hex(0b11110000000000000000000001010111) a.xxspltdl(32, 2, 2) # tttttaaaaabbbbb abt assert hex(int(self.last_value)) == hex(0b11110000000000100001000001010001) a.xxspltdl(0, 63, 0) # tttttaaaaabbbbb abt assert hex(int(self.last_value)) == hex(0b11110000000111110000000001010100) a.xxspltdl(0, 0, 63) # tttttaaaaabbbbb abt assert hex(int(self.last_value)) == hex(0b11110000000000001111100001010010)
def newtest(self): memory_ptrs = [] a = PPCBuilder() for (bytes, type, values) in memory: # alloc adr = lltype.malloc(rffi.CArray(char), bytes, flavor="raw") memory_ptrs.append(adr) address = adr for i,value in enumerate(values): rffi.cast(rffi.CArrayPtr(type), adr)[i] = rffi.cast(type, value) expected = test(self, a, *[rffi.cast(lltype.Signed, m) for m in memory_ptrs]) f = a.get_assembler_function() f() for expect, type, ptr in expected: value = rffi.cast(rffi.CArrayPtr(type), ptr)[0] assert value == expect while memory_ptrs: ptr = memory_ptrs.pop() lltype.free(ptr, flavor="raw")
def newtest(self): memory_ptrs = [] a = PPCBuilder() for (bytes, type, values) in memory: # alloc adr = lltype.malloc(rffi.CArray(char), bytes, flavor="raw") memory_ptrs.append(adr) address = adr for i, value in enumerate(values): rffi.cast(rffi.CArrayPtr(type), adr)[i] = rffi.cast(type, value) expected = test( self, a, *[rffi.cast(lltype.Signed, m) for m in memory_ptrs]) f = a.get_assembler_function() f() for expect, type, ptr in expected: value = rffi.cast(rffi.CArrayPtr(type), ptr)[0] assert value == expect while memory_ptrs: ptr = memory_ptrs.pop() lltype.free(ptr, flavor="raw")
def test_load_from(self): a = PPCBuilder() p = lltype.malloc(rffi.CArray(rffi.LONG), 1, flavor="raw") addr = rffi.cast(lltype.Signed, p) p[0] = rffi.cast(rffi.LONG, 200) a.load_from_addr(r3, SCRATCH2, addr) a.blr() f = a.get_assembler_function() assert f() == 200 p[0] = rffi.cast(rffi.LONG, 300) assert f() == 300 lltype.free(p, flavor="raw")
def test_load_from(self): a = PPCBuilder() p = lltype.malloc(rffi.CArray(rffi.LONG), 1, flavor="raw") addr = rffi.cast(lltype.Signed, p) p[0] = rffi.cast(rffi.LONG, 200) a.load_from_addr(r3, addr) a.blr() f = a.get_assembler_function() assert f() == 200 p[0] = rffi.cast(rffi.LONG, 300) assert f() == 300 lltype.free(p, flavor="raw")
def invalidate_loop(self, looptoken): """Activate all GUARD_NOT_INVALIDATED in the loop and its attached bridges. Before this call, all GUARD_NOT_INVALIDATED do nothing; after this call, they all fail. Note that afterwards, if one such guard fails often enough, it has a bridge attached to it; it is possible then to re-call invalidate_loop() on the same looptoken, which must invalidate all newer GUARD_NOT_INVALIDATED, but not the old one that already has a bridge attached to it.""" for jmp, tgt in looptoken.compiled_loop_token.invalidate_positions: mc = PPCBuilder() mc.b_offset(tgt) # a single instruction mc.copy_to_raw_memory(jmp) # positions invalidated looptoken.compiled_loop_token.invalidate_positions = []
def newtest(self): a = PPCBuilder() test(self, a) f = a.get_assembler_function() assert f() == expected
def test_load_and_store(self): a = PPCBuilder() word1 = 1000 word2 = 2000 p = lltype.malloc(rffi.CArray(lltype.Signed), 2, flavor="raw") a.load_imm(r10, word1) a.load_imm(r11, word2) a.load_imm(r8, rffi.cast(lltype.Signed, p)) a.load_imm(r9, rffi.cast(lltype.Signed, p) + WORD) a.stw(10, 8, 0) a.stw(11, 9, 0) a.lwz(4, 8, 0) a.lwz(5, 9, 0) a.add(3, 4, 5) a.blr() f = a.get_assembler_function() assert f() == word1 + word2 lltype.free(p, flavor="raw")
def test_call_function(self): functype = lltype.Ptr(lltype.FuncType([lltype.Signed], lltype.Signed)) call_addr = rffi.cast(lltype.Signed, llhelper(functype, func)) a = PPCBuilder() # NOW EXPLICITLY: # # - Load the address of the function to call into a register x # - Move the content of this register x into CTR # - Set the LR manually (or with bctrl) # - Do jump a.li(3, 50) if IS_PPC_32: a.load_imm(r10, call_addr) elif IS_BIG_ENDIAN: # load the 3-words descriptor a.load_from_addr(r10, call_addr) a.load_from_addr(r2, call_addr + WORD) a.load_from_addr(r11, call_addr + 2 * WORD) else: # no descriptor on little-endian, but the ABI says r12 must # contain the function pointer a.load_imm(r10, call_addr) a.mr(12, 10) a.mtctr(10) a.bctr() a.blr() f = a.get_assembler_function() assert f() == 65
def test_xx3_instr(self): a = PPCBuilder() def assign_to_self(v): self.last_value = v a.emit = assign_to_self a.xxspltdl(32, 32, 32) # tttttaaaaabbbbb abt assert hex(int( self.last_value)) == hex(0b11110000000000000000000001010111) a.xxspltdl(32, 2, 2) # tttttaaaaabbbbb abt assert hex(int( self.last_value)) == hex(0b11110000000000100001000001010001) a.xxspltdl(0, 63, 0) # tttttaaaaabbbbb abt assert hex(int( self.last_value)) == hex(0b11110000000111110000000001010100) a.xxspltdl(0, 0, 63) # tttttaaaaabbbbb abt assert hex(int( self.last_value)) == hex(0b11110000000000001111100001010010)
def test_call_function(self): functype = lltype.Ptr(lltype.FuncType([lltype.Signed], lltype.Signed)) call_addr = rffi.cast(lltype.Signed, llhelper(functype, func)) a = PPCBuilder() # NOW EXPLICITLY: # # - Load the address of the function to call into a register x # - Move the content of this register x into CTR # - Set the LR manually (or with bctrl) # - Do jump a.li(3, 50) if IS_PPC_32: a.load_imm(r10, call_addr) elif IS_BIG_ENDIAN: # load the 3-words descriptor a.load_from_addr(r10, SCRATCH2, call_addr) a.load_from_addr(r2, SCRATCH2, call_addr + WORD) a.load_from_addr(r11, SCRATCH2, call_addr + 2 * WORD) else: # no descriptor on little-endian, but the ABI says r12 must # contain the function pointer a.load_imm(r10, call_addr) a.mr(12, 10) a.mtctr(10) a.bctr() a.blr() f = a.get_assembler_function() assert f() == 65
def make_function_returning_stack_pointer(self): mc = PPCBuilder() mc.mr(r.r3.value, r.r1.value) mc.blr() return rffi.cast(lltype.Signed, mc.get_assembler_function())