G'day all.

This patch introduces a new op parameter type "inconst", which is like
"in" except that it only produces const versions of the op (i.e. it
will not take values from registers).

This is mostly for the benefit of branch targets.  The "feature" of
using register values as branch targets can safely be eliminated
because:

        - Nobody uses it.
        - Nobody is likely to use it any time soon.
        - In the rare event that you may want to use it, you could
          always branch to a jump_i op.
        - None of the JIT ports implement it.  This will save work.
        - It is in general impossible for an optimizer to determine
          where the branch targets are if you allow registers as
          branch targets.  Even when it's possible, it's too hard.
        - Eliminating it speeds up life.pasm by about 5-10% according
          to my highly unscientific benchmark.

There's probably an argument for implementing "inreg" as well, for
the benefit of jump and jsr.  Is "inreg" a good name?

Cheers,
Andrew Bromage

Index: core.ops
===================================================================
RCS file: /cvs/public/parrot/core.ops,v
retrieving revision 1.123
diff -u -r1.123 core.ops
--- core.ops    17 Apr 2002 20:58:18 -0000      1.123
+++ core.ops    18 Apr 2002 03:52:21 -0000
@@ -792,11 +792,11 @@
 
 =item B<eq>(in STR, in STR)
 
-=item B<eq>(in INT, in INT, in INT)
+=item B<eq>(in INT, in INT, inconst INT)
 
-=item B<eq>(in NUM, in NUM, in INT)
+=item B<eq>(in NUM, in NUM, inconst INT)
 
-=item B<eq>(in STR, in STR, in INT)
+=item B<eq>(in STR, in STR, inconst INT)
 
 Branch if $1 is equal to $2.
 
@@ -825,21 +825,21 @@
   goto NEXT();
 }
 
-inline op eq(in INT, in INT, in INT) {
+inline op eq(in INT, in INT, inconst INT) {
   if ($1 == $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-inline op eq(in NUM, in NUM, in INT) {
+inline op eq(in NUM, in NUM, inconst INT) {
   if ($1 == $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-op eq(in STR, in STR, in INT) {
+op eq(in STR, in STR, inconst INT) {
   if (string_compare(interpreter, $1, $2) == 0) {
     goto OFFSET($3);
   }
@@ -855,11 +855,11 @@
 
 =item B<ne>(in STR, in STR)
 
-=item B<ne>(in INT, in INT, in INT)
+=item B<ne>(in INT, in INT, inconst INT)
 
-=item B<ne>(in NUM, in NUM, in INT)
+=item B<ne>(in NUM, in NUM, inconst INT)
 
-=item B<ne>(in STR, in STR, in INT)
+=item B<ne>(in STR, in STR, inconst INT)
 
 Branch if $1 is not equal to $2.
 
@@ -888,21 +888,21 @@
   goto NEXT();
 }
 
-inline op ne(in INT, in INT, in INT) {
+inline op ne(in INT, in INT, inconst INT) {
   if ($1 != $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-inline op ne(in NUM, in NUM, in INT) {
+inline op ne(in NUM, in NUM, inconst INT) {
   if ($1 != $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-op ne(in STR, in STR, in INT) {
+op ne(in STR, in STR, inconst INT) {
   if (string_compare(interpreter, $1, $2) != 0) {
     goto OFFSET($3);
   }
@@ -912,33 +912,33 @@
 
 ########################################
 
-=item B<lt>(in INT, in INT, in INT)
+=item B<lt>(in INT, in INT, inconst INT)
 
-=item B<lt>(in NUM, in NUM, in INT)
+=item B<lt>(in NUM, in NUM, inconst INT)
 
-=item B<lt>(in PMC, in PMC, in INT)
+=item B<lt>(in PMC, in PMC, inconst INT)
 
-=item B<lt>(in STR, in STR, in INT)
+=item B<lt>(in STR, in STR, inconst INT)
 
 Branch if $1 is less than $2.
 
 =cut
 
-inline op lt(in INT, in INT, in INT) {
+inline op lt(in INT, in INT, inconst INT) {
   if ($1 < $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-inline op lt(in NUM, in NUM, in INT) {
+inline op lt(in NUM, in NUM, inconst INT) {
   if ($1 < $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-op lt(in STR, in STR, in INT) {
+op lt(in STR, in STR, inconst INT) {
   if (string_compare(interpreter, $1, $2) < 0) {
     goto OFFSET($3);
   }
@@ -948,31 +948,31 @@
 
 ########################################
 
-=item B<le>(in INT, in INT, in INT)
+=item B<le>(in INT, in INT, inconst INT)
 
-=item B<le>(in NUM, in NUM, in INT)
+=item B<le>(in NUM, in NUM, inconst INT)
 
-=item B<le>(in STR, in STR, in INT)
+=item B<le>(in STR, in STR, inconst INT)
 
 Branch if $1 is less than or equal to $2.
 
 =cut
 
-inline op le(in INT, in INT, in INT) {
+inline op le(in INT, in INT, inconst INT) {
   if ($1 <= $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-inline op le(in NUM, in NUM, in INT) {
+inline op le(in NUM, in NUM, inconst INT) {
   if ($1 <= $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-op le(in STR, in STR, in INT) {
+op le(in STR, in STR, inconst INT) {
   if (string_compare(interpreter, $1, $2) <= 0) {
     goto OFFSET($3);
   }
@@ -982,31 +982,31 @@
 
 ########################################
 
-=item B<gt>(in INT, in INT, in INT)
+=item B<gt>(in INT, in INT, inconst INT)
 
-=item B<gt>(in NUM, in NUM, in INT)
+=item B<gt>(in NUM, in NUM, inconst INT)
 
-=item B<gt>(in STR, in STR, in INT)
+=item B<gt>(in STR, in STR, inconst INT)
 
 Branch if $1 is greater than $2.
 
 =cut
 
-inline op gt(in INT, in INT, in INT) {
+inline op gt(in INT, in INT, inconst INT) {
   if ($1 > $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-inline op gt(in NUM, in NUM, in INT) {
+inline op gt(in NUM, in NUM, inconst INT) {
   if ($1 > $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-op gt(in STR, in STR, in INT) {
+op gt(in STR, in STR, inconst INT) {
   if (string_compare(interpreter, $1, $2) > 0) {
     goto OFFSET($3);
   }
@@ -1016,31 +1016,31 @@
 
 ########################################
 
-=item B<ge>(in INT, in INT, in INT)
+=item B<ge>(in INT, in INT, inconst INT)
 
-=item B<ge>(in NUM, in NUM, in INT)
+=item B<ge>(in NUM, in NUM, inconst INT)
 
-=item B<ge>(in STR, in STR, in INT)
+=item B<ge>(in STR, in STR, inconst INT)
 
 Branch if $1 is greater than or equal to $2.
 
 =cut
 
-inline op ge(in INT, in INT, in INT) {
+inline op ge(in INT, in INT, inconst INT) {
   if ($1 >= $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-inline op ge(in NUM, in NUM, in INT) {
+inline op ge(in NUM, in NUM, inconst INT) {
   if ($1 >= $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-op ge(in STR, in STR, in INT) {
+op ge(in STR, in STR, inconst INT) {
   if (string_compare(interpreter, $1, $2) >= 0) {
     goto OFFSET($3);
   }
@@ -1049,40 +1049,40 @@
 
 ########################################
 
-=item B<if>(in INT, in INT)
+=item B<if>(in INT, inconst INT)
 
-=item B<if>(in NUM, in INT)
+=item B<if>(in NUM, inconst INT)
 
-=item B<if>(in PMC, in INT)
+=item B<if>(in PMC, inconst INT)
 
-=item B<if>(in STR, in INT)
+=item B<if>(in STR, inconst INT)
 
 Check register $1. If true, branch by $2.
 
 =cut
 
-inline op if(in INT, in INT) {
+inline op if(in INT, inconst INT) {
   if ($1 != 0) {
     goto OFFSET($2);
   }
   goto NEXT();
 }
 
-inline op if(in NUM, in INT) {
+inline op if(in NUM, inconst INT) {
   if ($1 != 0.0) {
     goto OFFSET($2);
   }
   goto NEXT();
 }
 
-op if (in STR, in INT) {
+op if (in STR, inconst INT) {
   if (string_bool($1)) {
     goto OFFSET($2);
   }
   goto NEXT();
 }
 
-op if(in PMC, in INT) {
+op if(in PMC, inconst INT) {
   if ($1->vtable->get_bool(interpreter, $1)) {
     goto OFFSET($2);
   }
@@ -1096,40 +1096,40 @@
 
 ###############################################################################
 
-=item B<unless>(in INT, in INT)
+=item B<unless>(in INT, inconst INT)
 
-=item B<unless>(in NUM, in INT)
+=item B<unless>(in NUM, inconst INT)
 
-=item B<unless>(in PMC, in INT)
+=item B<unless>(in PMC, inconst INT)
 
-=item B<unless>(in STR, in INT)
+=item B<unless>(in STR, inconst INT)
 
 Check register $1. If false, branch by $2.
 
 =cut
 
-inline op unless(in INT, in INT) {
+inline op unless(in INT, inconst INT) {
   if ($1 == 0) {
     goto OFFSET($2);
   }
   goto NEXT();
 }
 
-inline op unless(in NUM, in INT) {
+inline op unless(in NUM, inconst INT) {
   if ($1 == 0.0) {
     goto OFFSET($2);
   }
   goto NEXT();
 }
 
-op unless (in STR, in INT) {
+op unless (in STR, inconst INT) {
   if (!string_bool($1)) {
     goto OFFSET($2);
   }
   goto NEXT();
 }
 
-op unless(in PMC, in INT) {
+op unless(in PMC, inconst INT) {
   if (!$1->vtable->get_bool(interpreter, $1)) {
     goto OFFSET($2);
   }
@@ -2586,27 +2586,27 @@
 
 ########################################
 
-=item B<branch>(in INT)
+=item B<branch>(inconst INT)
 
 Branch forward or backward by the amount in $1.
 
 =cut
 
-inline op branch (in INT) {
+inline op branch (inconst INT) {
   goto OFFSET($1);
 }
 
 
 ########################################
 
-=item B<bsr>(in INT)
+=item B<bsr>(inconst INT)
 
 Branch to the location specified by $1. Push the current location onto the call
 stack for later returning.
 
 =cut
 
-inline op bsr (in INT) {
+inline op bsr (inconst INT) {
   stack_push(interpreter, interpreter->control_stack, expr NEXT(),  
STACK_ENTRY_DESTINATION, STACK_CLEANUP_NULL);
   goto OFFSET($1);
 }
Index: rx.ops
===================================================================
RCS file: /cvs/public/parrot/rx.ops,v
retrieving revision 1.17
diff -u -r1.17 rx.ops
--- rx.ops      2 Apr 2002 20:35:52 -0000       1.17
+++ rx.ops      18 Apr 2002 03:52:22 -0000
@@ -428,14 +428,14 @@
 
 ########################################
 
-=item C<rx_popindex>(in pmc, in int)
+=item C<rx_popindex>(in pmc, inconst int)
 
 Pops an index off the stack.  If it pops a mark off instead, it branches to the 
 second parameter.
 
 =cut
 
-op rx_popindex(in pmc, in int) {
+op rx_popindex(in pmc, inconst int) {
        RX_dUNPACK($1);
        INTVAL i;
        
@@ -507,14 +507,14 @@
 
 ########################################
 
-=item C<rx_advance>(in pmc, in int)
+=item C<rx_advance>(in pmc, inconst int)
 
 Increments (or decrements, if the C<r> modifier is used) the start index one
 character.  Branches to the second parameter if it goes past the end of the string.
 
 =cut
 
-op rx_advance(in pmc, in int) {
+op rx_advance(in pmc, inconst int) {
        RX_dUNPACK($1);
 
        if(!RxReverse_test(rx)) {
@@ -668,7 +668,7 @@
 
 ########################################
 
-=item C<rx_literal>(in pmc, in str, in int)
+=item C<rx_literal>(in pmc, in str, inconst int)
 
 Matches the exact string (sensitive to the C<i> modifier) passed in the second
 parameter.
@@ -677,7 +677,7 @@
 
 =cut
 
-op rx_literal(in pmc, in str, in int) {
+op rx_literal(in pmc, in str, inconst int) {
        UINTVAL i;
        RX_dUNPACK($1);
 
@@ -698,13 +698,13 @@
 
 ########################################
 
-=item C<rx_is_w>(in pmc, in int)
+=item C<rx_is_w>(in pmc, inconst int)
 
 Matches a word character (usually C<\w>).
 
 =cut
 
-op rx_is_w(in pmc, in int) {
+op rx_is_w(in pmc, inconst int) {
        RX_dUNPACK($1);
 
        RxAssertMore(rx, $2);
@@ -721,13 +721,13 @@
 
 ########################################
 
-=item C<rx_is_d>(in pmc, in int)
+=item C<rx_is_d>(in pmc, inconst int)
 
 Matches a number character (usually C<\d>).
 
 =cut
 
-op rx_is_d(in pmc, in int) {
+op rx_is_d(in pmc, inconst int) {
        RX_dUNPACK($1);
 
        RxAssertMore(rx, $2);
@@ -743,13 +743,13 @@
 
 ########################################
 
-=item C<rx_is_s>(in pmc, in int)
+=item C<rx_is_s>(in pmc, inconst int)
 
 Matches a whitespace character (usually C<\s>).
 
 =cut
 
-op rx_is_s(in pmc, in int) {
+op rx_is_s(in pmc, inconst int) {
        RX_dUNPACK($1);
 
        RxAssertMore(rx, $2);
@@ -766,7 +766,7 @@
 
 ########################################
 
-=item C<rx_oneof>(in pmc, in str, in int)
+=item C<rx_oneof>(in pmc, in str, inconst int)
 
 Matches if the current character is one of the characters in the second parameter.
 Sensitive to the C<i> modifier.
@@ -778,7 +778,7 @@
 
 =cut
 
-op rx_oneof(in pmc, in str, in int) {
+op rx_oneof(in pmc, in str, inconst int) {
        RX_dUNPACK($1);
        Bitmap bitmap;
 
@@ -801,14 +801,14 @@
 
 ########################################
 
-=item C<rx_oneof_bmp>(in pmc, in pmc, in int)
+=item C<rx_oneof_bmp>(in pmc, in pmc, inconst int)
 
 This op has the exact same behavior as C<rx_oneof>, except that the second parameter 
 is a ParrotPointer to a bitmap generated by C<rx_makebmp>.
 
 =cut
 
-op rx_oneof_bmp(in pmc, in pmc, in int) {
+op rx_oneof_bmp(in pmc, in pmc, inconst int) {
        RX_dUNPACK($1);
        
        RxAssertMore(rx, $3);
@@ -844,14 +844,14 @@
 
 ########################################
 
-=item C<rx_dot>(in pmc, in int)
+=item C<rx_dot>(in pmc, inconst int)
 
 Matches any character except a newline (C<\n>).  (If the C<s> modifier is used, 
 matches any character at all.)
 
 =cut
 
-op rx_dot(in pmc, in int) {
+op rx_dot(in pmc, inconst int) {
        RX_dUNPACK($1);
 
        RxAssertMore(rx, $2);
@@ -873,14 +873,14 @@
 
 ########################################
 
-=item C<rx_zwa_boundary>(in pmc, in int)
+=item C<rx_zwa_boundary>(in pmc, inconst int)
 
 Matches if the one of the previous character and the next character is a word
 character, and the other one is not (usually C<\b>).
 
 =cut
 
-op rx_zwa_boundary(in pmc, in int) {
+op rx_zwa_boundary(in pmc, inconst int) {
        RX_dUNPACK($1);
        BOOLVAL one, two;
 
@@ -898,7 +898,7 @@
 
 ########################################
 
-=item C<rx_zwa_atbeginning>(in pmc, in int)
+=item C<rx_zwa_atbeginning>(in pmc, inconst int)
 
 Matches at the beginning of the string.  If the C<m> modifier is used, matches at the
 beginning of any line.
@@ -907,7 +907,7 @@
 
 =cut
 
-op rx_zwa_atbeginning(in pmc, in int) {
+op rx_zwa_atbeginning(in pmc, inconst int) {
        RX_dUNPACK($1);
        
        if(RxMultiline_test(rx)) {
@@ -926,7 +926,7 @@
 
 ########################################
 
-=item C<rx_zwa_atend>(in pmc, in int)
+=item C<rx_zwa_atend>(in pmc, inconst int)
 
 Matches at the end of the string.  If the C<m> modifier is used, matches at the
 end of any line.
@@ -935,7 +935,7 @@
 
 =cut
 
-op rx_zwa_atend(in pmc, in int) {
+op rx_zwa_atend(in pmc, inconst int) {
        RX_dUNPACK($1);
 
        if(RxMultiline_test(rx)) {
Index: lib/Parrot/OpsFile.pm
===================================================================
RCS file: /cvs/public/parrot/lib/Parrot/OpsFile.pm,v
retrieving revision 1.17
diff -u -r1.17 OpsFile.pm
--- lib/Parrot/OpsFile.pm       15 Feb 2002 03:24:57 -0000      1.17
+++ lib/Parrot/OpsFile.pm       18 Apr 2002 03:52:22 -0000
@@ -171,7 +171,7 @@
       my @temp = ();
 
       foreach my $arg (@args) {
-       my ($use, $type) = $arg =~ m/^(in|out|inout)\s+(INT|NUM|STR|PMC)$/i;
+       my ($use, $type) = $arg =~ m/^(in|out|inout|inconst)\s+(INT|NUM|STR|PMC)$/i;
 
         die "Unrecognized arg format '$arg' in '$_'!" unless defined($use) and 
defined($type);
 
@@ -179,6 +179,11 @@
 
         if ($use eq 'in') {
           push @temp, ($type eq 'p') ? 'p' : "$type|${type}c";
+        }
+        elsif ($use eq 'inconst') {
+         die "Parrot::OpsFile: Arg format 'inconst PMC' is not allowed!"
+               if $type eq 'p';
+          push @temp, "${type}c";
         }
         elsif ($use eq 'inout') {
           push @temp, $type;

Reply via email to