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_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_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 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")