def test_const(self): asm = FunctionAssembler('foo', ['a', 'b']) asm.ADDSD(asm.xmm0, asm.xmm1) asm.ADDSD(asm.xmm0, asm.const(100)) asm.RET() pyfn = self.load(asm) assert pyfn(3, 4) == 107
def test_pushsd_popsd(self): asm = FunctionAssembler('foo', ['a', 'b', 'c']) asm.pushsd(asm.xmm0) asm.pushsd(asm.xmm1) asm.pushsd(asm.xmm2) asm.PXOR(asm.xmm0, asm.xmm0) # xmm0 = 0 asm.popsd(asm.xmm1) asm.MULSD(asm.xmm1, asm.const(100)) # xmm0 += (xmm1*100) asm.ADDSD(asm.xmm0, asm.xmm1) asm.popsd(asm.xmm1) asm.MULSD(asm.xmm1, asm.const(10)) # xmm0 += (xmm1*10) asm.ADDSD(asm.xmm0, asm.xmm1) asm.popsd(asm.xmm1) asm.ADDSD(asm.xmm0, asm.xmm1) asm.RET() pyfn = self.load(asm) assert pyfn(1, 2, 3) == 321
def test_encode(self): asm = FunctionAssembler('foo', ['a', 'b']) asm.ADDSD(asm.xmm0, asm.xmm1) asm.RET() pyfn = self.load(asm) assert pyfn(3, 4) == 7
def test_opcode(self): asm = FunctionAssembler('foo', []) asm.ADDSD(asm.xmm0, asm.xmm1) assert len(asm._peachpy_fn._instructions) == 1 assert asm._peachpy_fn._instructions[0].__class__.__name__ == 'ADDSD'