Re: [patch] optimize OP_IS_(FILETEST|SOCKET) macros
authorJim Cromie <jcromie@cpan.org>
Sun, 10 Feb 2008 12:52:59 +0000 (05:52 -0700)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Mon, 25 Feb 2008 08:02:50 +0000 (08:02 +0000)
From: "Jim Cromie" <jim.cromie@gmail.com>
Message-ID: <cfe85dfa0802101152n4e1b9e07pc7fb7ad9241a9794@mail.gmail.com>

p4raw-id: //depot/perl@33364

dump.c
op.c
op.h
opcode.pl
opnames.h

diff --git a/dump.c b/dump.c
index bd11207..7ad09b1 100644 (file)
--- a/dump.c
+++ b/dump.c
@@ -982,7 +982,7 @@ Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, const OP *o)
                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 @@ Perl_do_op_xmldump(pTHX_ I32 level, PerlIO *file, const OP *o)
                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");
diff --git a/op.c b/op.c
index 4e0695f..0e78eb1 100644 (file)
--- a/op.c
+++ b/op.c
@@ -6683,7 +6683,7 @@ Perl_ck_ftst(pTHX_ OP *o)
 #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)
diff --git a/op.h b/op.h
index e128ec9..4ad2a2b 100644 (file)
--- a/op.h
+++ b/op.h
@@ -266,13 +266,6 @@ Deprecated.  Use C<GIMME_V> instead.
 /* 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 $_ */
index e8c43dd..a5dfa57 100755 (executable)
--- a/opcode.pl
+++ b/opcode.pl
@@ -344,6 +344,7 @@ my %opflags = (
 
 my %OP_IS_SOCKET;
 my %OP_IS_FILETEST;
+my %OP_IS_FT_ACCESS;
 my $OCSHIFT = 9;
 my $OASHIFT = 13;
 
@@ -366,6 +367,7 @@ for my $op (@ops) {
            # 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 @@ EO_OP_IS_COMMENT
 
 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 @@ sub gen_op_is_macro {
        } 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 @@ __END__
 # 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 @@ getpeername       getpeername             ck_fun          is%     Fs
 
 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-
index ac6d259..e0012ed 100644 (file)
--- a/opnames.h
+++ b/opnames.h
@@ -398,4 +398,7 @@ typedef enum opcode {
 #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: */