[pypy-svn] r58217 - in pypy/branch/oo-jit/pypy/jit/codegen/x86_64: . test

witulski at codespeak.net witulski at codespeak.net
Thu Sep 18 10:13:50 CEST 2008


Author: witulski
Date: Thu Sep 18 10:13:48 2008
New Revision: 58217

Modified:
   pypy/branch/oo-jit/pypy/jit/codegen/x86_64/assembler.py
   pypy/branch/oo-jit/pypy/jit/codegen/x86_64/rgenop.py
   pypy/branch/oo-jit/pypy/jit/codegen/x86_64/test/test_rgenop.py
Log:
Added some boolfunc. (XOR,OR,AND) New Bool-Tests pass


Modified: pypy/branch/oo-jit/pypy/jit/codegen/x86_64/assembler.py
==============================================================================
--- pypy/branch/oo-jit/pypy/jit/codegen/x86_64/assembler.py	(original)
+++ pypy/branch/oo-jit/pypy/jit/codegen/x86_64/assembler.py	Thu Sep 18 10:13:48 2008
@@ -149,6 +149,8 @@
     _ADD_QWREG_IMM32 = make_two_operand_instr(   1,    0,    0,    0, "\x81", 3, None, 2)  
     _ADD_QWREG_QWREG = make_two_operand_instr(   1, None,    0, None, "\x00", 3, None, None)
     
+    _AND_QWREG_QWREG = make_two_operand_instr(   1, None,    0, None, "\x21", 3, None, None)
+    
     # FIXME: rexB is set
     _CMP_QWREG_IMM32 = make_two_operand_instr(   1,    0,    0,    1, "\x81", 3, None, 7)
     _CMP_QWREG_QWREG = make_two_operand_instr(   1, None,    0, None, "\x39", 3, None, None)
@@ -167,6 +169,8 @@
     _IMUL_QWREG_IMM32 = make_two_operand_instr(  1, None,    0, None, "\x69", 3, None, "sameReg")
     
     _JMP_QWREG       = make_one_operand_instr(   1,    0,    0, None, "\xFF", 3, None, 4)
+    
+    _OR_QWREG_QWREG  = make_two_operand_instr(   1, None,    0, None, "\x09", 3, None, None)
 
     # FIXME: rexW is set 
     _POP_QWREG       = make_one_operand_instr(   1,    0,    0, None, "\x8F", 3, None, 0)
@@ -182,11 +186,17 @@
     _SUB_QWREG_QWREG = make_two_operand_instr(   1, None,    0, None, "\x28", 3, None, None)    
     _SUB_QWREG_IMM32 = make_two_operand_instr(   1,    0,    0,    0, "\x81", 3, None, 5)
     
+    _XOR_QWREG_QWREG = make_two_operand_instr(   1, None,    0, None, "\x31", 3, None, None)
+    
     # TODO: maybe a problem with more ore less than two arg.
     def ADD(self, op1, op2):
         method = getattr(self, "_ADD"+op1.to_string()+op2.to_string())
         method(op1, op2)
         
+    def AND(self, op1, op2):
+        method = getattr(self, "_AND"+op1.to_string()+op2.to_string())
+        method(op1, op2)
+        
     def CMP(self, op1, op2):
         method = getattr(self, "_CMP"+op1.to_string()+op2.to_string())
         method(op1, op2)
@@ -213,6 +223,10 @@
         self.writeImm32(op1)   
         print self.tell(),": JNE to",op1
         
+    def OR(self, op1, op2):
+        method = getattr(self, "_OR"+op1.to_string()+op2.to_string())
+        method(op1, op2)
+        
     def POP(self, op1):
         method = getattr(self, "_POP"+op1.to_string())
         method(op1)
@@ -265,6 +279,10 @@
         method = getattr(self, "_SUB"+op1.to_string()+op2.to_string())
         method(op1, op2)
         
+    def XOR(self, op1, op2):
+        method = getattr(self, "_XOR"+op1.to_string()+op2.to_string())
+        method(op1, op2)
+        
     def get_register_bits(self, register):
         return REGISTER_MAP[register]
     

Modified: pypy/branch/oo-jit/pypy/jit/codegen/x86_64/rgenop.py
==============================================================================
--- pypy/branch/oo-jit/pypy/jit/codegen/x86_64/rgenop.py	(original)
+++ pypy/branch/oo-jit/pypy/jit/codegen/x86_64/rgenop.py	Thu Sep 18 10:13:48 2008
@@ -98,12 +98,15 @@
         return genmethod(gv_arg1, gv_arg2)
     
     op_int_add  = make_two_argument_method("ADD")
+    op_int_and  = make_two_argument_method("AND")
     op_int_dec  = make_one_argument_method("DEC")
     op_int_inc  = make_one_argument_method("INC")
     op_int_mul  = make_two_argument_method("IMUL")
+    op_int_or   = make_two_argument_method("OR")
     op_int_push = make_one_argument_method("PUSH")
     op_int_pop  = make_one_argument_method("POP")
     op_int_sub  = make_two_argument_method("SUB")
+    op_int_xor   = make_two_argument_method("XOR")
 
     #FIXME: can only jump 32bit
     def jump_if_true(self, gv_condition, args_for_jump_gv):

Modified: pypy/branch/oo-jit/pypy/jit/codegen/x86_64/test/test_rgenop.py
==============================================================================
--- pypy/branch/oo-jit/pypy/jit/codegen/x86_64/test/test_rgenop.py	(original)
+++ pypy/branch/oo-jit/pypy/jit/codegen/x86_64/test/test_rgenop.py	Thu Sep 18 10:13:48 2008
@@ -10,6 +10,16 @@
 def skip(self):
     py.test.skip("not implemented yet")
 
+def make_bool_op(rgenop, which_bool_op):
+    sigtoken = rgenop.sigToken(lltype.FuncType([lltype.Signed, lltype.Signed], lltype.Signed))
+    builder, gv_bool_op, [gv_x, gv_y] = rgenop.newgraph(sigtoken, "bool_op")
+    builder.start_writing()
+    
+    gv_result = builder.genop2(which_bool_op, gv_x, gv_y)
+    builder.finish_and_return(sigtoken, gv_result)
+    builder.end()
+    return gv_bool_op
+
 def make_cmp(rgenop, which_cmp):
     sigtoken = rgenop.sigToken(lltype.FuncType([lltype.Signed, lltype.Signed], lltype.Signed))
     builder, gv_cmp, [gv_x, gv_y] = rgenop.newgraph(sigtoken, "cmp")
@@ -205,6 +215,61 @@
         res = fnptr(-4,0)
         assert res == 1
         
+    def test_int_and(self):
+        rgenop = self.RGenOp()
+        bool_function = make_bool_op(rgenop,"int_and")
+        fnptr = self.cast(bool_function,2)
+        result = fnptr(1,1)
+        assert result == 1
+        result = fnptr(1,0)
+        assert result == 0
+        result = fnptr(0,1)
+        assert result == 0
+        result = fnptr(0,0)
+        assert result == 0
+        # AND 010101
+        #     101010
+        #   = 000000
+        result = fnptr(42,21) 
+        assert result == 0
+        
+    def test_int_or(self):
+        rgenop = self.RGenOp()
+        bool_function = make_bool_op(rgenop,"int_or")
+        fnptr = self.cast(bool_function,2)
+        result = fnptr(1,1)
+        assert result == 1
+        result = fnptr(1,0)
+        assert result == 1
+        result = fnptr(0,1)
+        assert result == 1
+        result = fnptr(0,0)
+        assert result == 0
+        # or  010101
+        #     101010
+        #   = 111111
+        result = fnptr(42,21) 
+        assert result == 63
+        
+    def test_int_xor(self):
+        rgenop = self.RGenOp()
+        bool_function = make_bool_op(rgenop,"int_xor")
+        fnptr = self.cast(bool_function,2)
+        result = fnptr(1,1)
+        assert result == 0
+        result = fnptr(1,0)
+        assert result == 1
+        result = fnptr(0,1)
+        assert result == 1
+        result = fnptr(0,0)
+        assert result == 0
+        # xor 010101
+        #     101010
+        #   = 111111
+        result = fnptr(42,21) 
+        assert result == 63
+    
+        
    # def test_push_and_pop(self):
    #     rgenop = self.RGenOp()
    #     push_result = make_push(rgenop)



More information about the Pypy-commit mailing list