Change 33364 by [EMAIL PROTECTED] on 2008/02/25 08:02:50

        Subject: Re: [patch] optimize OP_IS_(FILETEST|SOCKET) macros
        From: "Jim Cromie" <[EMAIL PROTECTED]>
        Date: Sun, 10 Feb 2008 12:52:59 -0700
        Message-ID: <[EMAIL PROTECTED]>

Affected files ...

... //depot/perl/dump.c#303 edit
... //depot/perl/op.c#993 edit
... //depot/perl/op.h#209 edit
... //depot/perl/opcode.pl#175 edit
... //depot/perl/opnames.h#30 edit

Differences ...

==== //depot/perl/dump.c#303 (text) ====
Index: perl/dump.c
--- perl/dump.c#302~33356~      2008-02-23 00:19:00.000000000 -0800
+++ perl/dump.c 2008-02-25 00:02:50.000000000 -0800
@@ -982,7 +982,7 @@
                sv_catpv(tmpsv, ",HUSH_VMSISH");
        }
        else if (PL_check[optype] != MEMBER_TO_FPTR(Perl_ck_ftst)) {
-           if (OP_IS_FILETEST_ACCESS(o) && o->op_private & OPpFT_ACCESS)
+           if (OP_IS_FILETEST_ACCESS(o->op_type) && o->op_private & 
OPpFT_ACCESS)
                sv_catpv(tmpsv, ",FT_ACCESS");
            if (o->op_private & OPpFT_STACKED)
                sv_catpv(tmpsv, ",FT_STACKED");
@@ -2800,7 +2800,7 @@
                sv_catpv(tmpsv, ",HUSH_VMSISH");
        }
        else if (PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst)) {
-           if (OP_IS_FILETEST_ACCESS(o) && o->op_private & OPpFT_ACCESS)
+           if (OP_IS_FILETEST_ACCESS(o->op_type) && o->op_private & 
OPpFT_ACCESS)
                sv_catpv(tmpsv, ",FT_ACCESS");
            if (o->op_private & OPpFT_STACKED)
                sv_catpv(tmpsv, ",FT_STACKED");

==== //depot/perl/op.c#993 (text) ====
Index: perl/op.c
--- perl/op.c#992~33356~        2008-02-23 00:19:00.000000000 -0800
+++ perl/op.c   2008-02-25 00:02:50.000000000 -0800
@@ -6683,7 +6683,7 @@
 #endif
            return newop;
        }
-       if ((PL_hints & HINT_FILETEST_ACCESS) && OP_IS_FILETEST_ACCESS(o))
+       if ((PL_hints & HINT_FILETEST_ACCESS) && 
OP_IS_FILETEST_ACCESS(o->op_type))
            o->op_private |= OPpFT_ACCESS;
        if (PL_check[kidtype] == MEMBER_TO_FPTR(Perl_ck_ftst)
                && kidtype != OP_STAT && kidtype != OP_LSTAT)

==== //depot/perl/op.h#209 (text) ====
Index: perl/op.h
--- perl/op.h#208~33356~        2008-02-23 00:19:00.000000000 -0800
+++ perl/op.h   2008-02-25 00:02:50.000000000 -0800
@@ -266,13 +266,6 @@
 /* Private for OP_FTXXX */
 #define OPpFT_ACCESS           2       /* use filetest 'access' */
 #define OPpFT_STACKED          4       /* stacked filetest, as in "-f -x $f" */
-#define OP_IS_FILETEST_ACCESS(op)              \
-       (((op)->op_type) == OP_FTRREAD  ||      \
-        ((op)->op_type) == OP_FTRWRITE ||      \
-        ((op)->op_type) == OP_FTREXEC  ||      \
-        ((op)->op_type) == OP_FTEREAD  ||      \
-        ((op)->op_type) == OP_FTEWRITE ||      \
-        ((op)->op_type) == OP_FTEEXEC)
 
 /* Private for OP_(MAP|GREP)(WHILE|START) */
 #define OPpGREP_LEX            2       /* iterate over lexical $_ */

==== //depot/perl/opcode.pl#175 (xtext) ====
Index: perl/opcode.pl
--- perl/opcode.pl#174~33356~   2008-02-23 00:19:00.000000000 -0800
+++ perl/opcode.pl      2008-02-25 00:02:50.000000000 -0800
@@ -344,6 +344,7 @@
 
 my %OP_IS_SOCKET;
 my %OP_IS_FILETEST;
+my %OP_IS_FT_ACCESS;
 my $OCSHIFT = 9;
 my $OASHIFT = 13;
 
@@ -366,6 +367,7 @@
            # record opnums of these opnames
            $OP_IS_SOCKET{$op}   = $opnum{$op} if $arg =~ s/s//;
            $OP_IS_FILETEST{$op} = $opnum{$op} if $arg =~ s/-//;
+           $OP_IS_FT_ACCESS{$op} = $opnum{$op} if $arg =~ s/\+//;
         }
        my $argnum = ($arg =~ s/\?//) ? 8 : 0;
         die "op = $op, arg = $arg\n"
@@ -403,6 +405,7 @@
 
 gen_op_is_macro( \%OP_IS_SOCKET, 'OP_IS_SOCKET');
 gen_op_is_macro( \%OP_IS_FILETEST, 'OP_IS_FILETEST');
+gen_op_is_macro( \%OP_IS_FT_ACCESS, 'OP_IS_FILETEST_ACCESS');
 
 sub gen_op_is_macro {
     my ($op_is, $macname) = @_;
@@ -414,20 +417,21 @@
        } keys %$op_is;
        
        my $last = pop @rest;   # @rest slurped, get its last
-       
+       die "invalid range of ops: $first .. $last" unless $last;
+
+       print ON "#define $macname(op)  \\\n\t(";
+
        # verify that op-ct matches 1st..last range (and fencepost)
        # (we know there are no dups)
        if ( $op_is->{$last} - $op_is->{$first} == scalar @rest + 1) {
            
            # contiguous ops -> optimized version
-           print ON "#define $macname(op)      \\\n\t(";
            print ON "(op) >= OP_" . uc($first) . " && (op) <= OP_" . uc($last);
            print ON ")\n\n";
        }
        else {
-           print ON "\n#define $macname(op)    \\\n\t(";
            print ON join(" || \\\n\t ",
-                         map { "(op) == OP_" . uc() } sort keys %OP_IS_SOCKET);
+                         map { "(op) == OP_" . uc() } sort keys %$op_is);
            print ON ")\n\n";
        }
     }
@@ -602,7 +606,9 @@
 # Values for the operands are:
 # scalar      - S            list     - L            array     - A
 # hash        - H            sub (CV) - C            file      - F
-# socket      - Fs           filetest - F-           reference - R
+# socket      - Fs           filetest - F-           filetest_access - F-+
+
+# reference - R
 # "?" denotes an optional operand.
 
 # Nothing.
@@ -948,12 +954,12 @@
 
 lstat          lstat                   ck_ftst         u-      F
 stat           stat                    ck_ftst         u-      F
-ftrread                -R                      ck_ftst         isu-    F-
-ftrwrite       -W                      ck_ftst         isu-    F-
-ftrexec                -X                      ck_ftst         isu-    F-
-fteread                -r                      ck_ftst         isu-    F-
-ftewrite       -w                      ck_ftst         isu-    F-
-fteexec                -x                      ck_ftst         isu-    F-
+ftrread                -R                      ck_ftst         isu-    F-+
+ftrwrite       -W                      ck_ftst         isu-    F-+
+ftrexec                -X                      ck_ftst         isu-    F-+
+fteread                -r                      ck_ftst         isu-    F-+
+ftewrite       -w                      ck_ftst         isu-    F-+
+fteexec                -x                      ck_ftst         isu-    F-+
 ftis           -e                      ck_ftst         isu-    F-
 ftsize         -s                      ck_ftst         istu-   F-
 ftmtime                -M                      ck_ftst         stu-    F-

==== //depot/perl/opnames.h#30 (text+w) ====
Index: perl/opnames.h
--- perl/opnames.h#29~33356~    2008-02-23 00:19:00.000000000 -0800
+++ perl/opnames.h      2008-02-25 00:02:50.000000000 -0800
@@ -398,4 +398,7 @@
 #define OP_IS_FILETEST(op)     \
        ((op) >= OP_FTRREAD && (op) <= OP_FTBINARY)
 
+#define OP_IS_FILETEST_ACCESS(op)      \
+       ((op) >= OP_FTRREAD && (op) <= OP_FTEEXEC)
+
 /* ex: set ro: */
End of Patch.

Reply via email to