The fact.pasm and substr.pasm examples can be changed to use more
intelligent branching. (Can you say hand-optimized assembler?)
If you apply this patch, you might have to write test cases again
for the missing instructions. :-)


Now to my real problem:
Some pasm examples have problems with the jit compiler on i386 wrt
branching. I suspect some problem to generate "near" jumps??

Please do not apply the change for jit/i386/core.jit. The current code
looks bogus to make a "jmp()". Funny thing is leaving that code away
does not work, but that "cmp/jne" code seems to make some examples
work. Probably "JUMP" is completely wrong here??

I am running on a current Red Hat Linux machine here.

thanks,

Florian La Roche


--- examples/assembly/fact.pasm
+++ examples/assembly/fact.pasm
@@ -22,14 +22,12 @@ $loop:
        print   I0
        print   "\n"
        inc     I1,1
-       eq      I1,7,$done
-       branch  $loop
-$done:
+       ne      I1,7,$loop
        end
 
 # I0 is the number to compute
 fact:
-       clonei
+       pushi
        lt      I0,2,$is_one
        set     I1,I0
        dec     I0,1    
--- examples/assembly/substr.pasm
+++ examples/assembly/substr.pasm
@@ -18,12 +18,10 @@ WAX:    substr S2, S1, I3, I4
         print  S2
         print  "\n"
         add    I4, I4, I2
-        eq     I4, I5, WANE
-       branch WAX
+        ne     I4, I5, WAX
 WANE:   length I1, S1
         print  S1
         print  "\n"
         chopn  S1, 1
-        eq     I1, I3, DONE
-       branch WANE
-DONE:   end
+        ne     I1, I3, WANE
+        end
--- jit/i386/core.jit
+++ jit/i386/core.jit
@@ -83,7 +83,9 @@ Parrot_if_i_ic {
 }
 
 Parrot_branch_ic {
-    jmp ($0x0)
+    cmp %eax,%eax
+    jne ($0x0)
+;   jmp ($0x0)
     JUMP(INT_CONST[1])
 }
 

Reply via email to