Skip to content
Browse files

regen/opcode.pl: generate OP_IS_DIRHOP, use in gv.c

Generate OP_IS_DIRHOP like other OP_IS_* macros,
use in gv.c:Perl_gv_add_by_type().
Modifies 'F' operand type to 'DF'.
This yields a micro-optimization.
  • Loading branch information...
1 parent 2b420b6 commit 332c2eacbbe33d99076d34256aa32351d41421c9 @jimc jimc committed with Father Chrysostomos Jun 2, 2011
Showing with 25 additions and 17 deletions.
  1. +1 −5 gv.c
  2. +7 −3 opnames.h
  3. +11 −3 regen/opcode.pl
  4. +6 −6 regen/opcodes
View
6 gv.c
@@ -59,11 +59,7 @@ Perl_gv_add_by_type(pTHX_ GV *gv, svtype type)
* if it walks like a dirhandle, then let's assume that
* this is a dirhandle.
*/
- what = PL_op->op_type == OP_READDIR ||
- PL_op->op_type == OP_TELLDIR ||
- PL_op->op_type == OP_SEEKDIR ||
- PL_op->op_type == OP_REWINDDIR ||
- PL_op->op_type == OP_CLOSEDIR ?
+ what = OP_IS_DIRHOP(PL_op->op_type) ?
"dirhandle" : "filehandle";
/* diag_listed_as: Bad symbol for filehandle */
} else if (type == SVt_PVHV) {
View
10 opnames.h
@@ -391,9 +391,10 @@ typedef enum opcode {
#define MAXO 372
-/* the OP_IS_(SOCKET|FILETEST) macros are optimized to a simple range
- check because all the member OPs are contiguous in opcode.pl
- <OPS> table. opcode.pl verifies the range contiguity. */
+/* the OP_IS_* macros are optimized to a simple range check because
+ all the member OPs are contiguous in regen/opcodes table.
+ opcode.pl verifies the range contiguity, or generates an OR-equals
+ expression */
#define OP_IS_SOCKET(op) \
((op) >= OP_SEND && (op) <= OP_GETPEERNAME)
@@ -407,4 +408,7 @@ typedef enum opcode {
#define OP_IS_NUMCOMPARE(op) \
((op) >= OP_LT && (op) <= OP_I_NCMP)
+#define OP_IS_DIRHOP(op) \
+ ((op) >= OP_READDIR && (op) <= OP_CLOSEDIR)
+
/* ex: set ro: */
View
14 regen/opcode.pl
@@ -353,6 +353,8 @@ END
my %OP_IS_FILETEST; # /F-/
my %OP_IS_FT_ACCESS; # /F-+/
my %OP_IS_NUMCOMPARE; # /S</
+my %OP_IS_DIRHOP; # /Fd/
+
my $OCSHIFT = 8;
my $OASHIFT = 12;
@@ -371,6 +373,10 @@ END
$argsum |= $opclass{$flags} << $OCSHIFT;
my $argshift = $OASHIFT;
for my $arg (split(' ',$args{$op})) {
+ if ($arg =~ s/^D//) {
+ # handle 1st, just to put D 1st.
+ $OP_IS_DIRHOP{$op} = $opnum{$op};
+ }
if ($arg =~ /^F/) {
# record opnums of these opnames
$OP_IS_SOCKET{$op} = $opnum{$op} if $arg =~ s/s//;
@@ -407,15 +413,17 @@ END
print $on <<'EO_OP_IS_COMMENT';
-/* the OP_IS_(SOCKET|FILETEST) macros are optimized to a simple range
- check because all the member OPs are contiguous in opcode.pl
- <OPS> table. opcode.pl verifies the range contiguity. */
+/* the OP_IS_* macros are optimized to a simple range check because
+ all the member OPs are contiguous in regen/opcodes table.
+ opcode.pl verifies the range contiguity, or generates an OR-equals
+ expression */
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');
gen_op_is_macro( \%OP_IS_NUMCOMPARE, 'OP_IS_NUMCOMPARE');
+gen_op_is_macro( \%OP_IS_DIRHOP, 'OP_IS_DIRHOP');
sub gen_op_is_macro {
my ($op_is, $macname) = @_;
View
12 regen/opcodes
@@ -30,7 +30,7 @@
# scalar - S list - L array - A
# hash - H sub (CV) - C file - F
# socket - Fs filetest - F- filetest_access - F-+
-# num-compare - S<
+# num-compare - S< dirhandle - DF
# reference - R
# "?" denotes an optional operand.
@@ -429,11 +429,11 @@ rmdir rmdir ck_fun isTu% S?
# Directory calls.
open_dir opendir ck_fun is@ F S
-readdir readdir ck_fun % F
-telldir telldir ck_fun st% F
-seekdir seekdir ck_fun s@ F S
-rewinddir rewinddir ck_fun s% F
-closedir closedir ck_fun is% F
+readdir readdir ck_fun % DF
+telldir telldir ck_fun st% DF
+seekdir seekdir ck_fun s@ DF S
+rewinddir rewinddir ck_fun s% DF
+closedir closedir ck_fun is% DF
# Process control.

0 comments on commit 332c2ea

Please sign in to comment.
Something went wrong with that request. Please try again.