Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.92k stars 548 forks source link

add OP_IS_DIRHOP, OP_IS_NUMCOMPARE macros #11645

Closed p5pRT closed 13 years ago

p5pRT commented 13 years ago

Migrated from rt.perl.org#98810 (status was 'resolved')

Searchable as RT98810$

p5pRT commented 13 years ago

From @jimc

Created by @jimc

pair of patches generate 2 more OP_IS_* macros​:

  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 D operand type to DF.   This yields a micro-optimization.

  implement OP_IS_NUMCOMPARE like other OP_IS macros

  other macros are written by regen/opcode.pl into opnames.h   Generate OP_IS_NUMCOMPARE the same way\, and get a micro-optimization.   Adds a new 'S\<' operand type for the numeric comparison ops.   Needs make regen.

Perl Info ``` Flags: category=core severity=low This perlbug was built using Perl 5.12.3 in the Fedora build system. It is being executed now by Perl 5.15.2 - Wed Sep 7 12:17:39 MDT 2011. Site configuration information for perl 5.15.2: Configured by jimc at Wed Sep 7 12:17:39 MDT 2011. Summary of my perl5 (revision 5 version 15 subversion 2) configuration: Commit id: d39de89300b9384bad8b2cf88917ce9f104ae8b2 Platform: osname=linux, osvers=2.6.35.14-95.fc14.x86_64, archname=x86_64-linux uname='linux groucho.jimc.earth 2.6.35.14-95.fc14.x86_64 #1 smp tue aug 16 21:01:58 utc 2011 x86_64 x86_64 x86_64 gnulinux ' config_args='-des -Dusedevel -DDEBUGGING=both' hint=recommended, useposix=true, d_sigaction=define useithreads=undef, usemultiplicity=undef useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef use64bitint=define, use64bitall=define, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2 -g', cppflags='-DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include' ccversion='', gccversion='4.5.1 20100924 (Red Hat 4.5.1-4)', gccosandvers='' intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16 ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='cc', ldflags =' -fstack-protector -L/usr/local/lib' libpth=/usr/local/lib /lib/../lib64 /usr/lib/../lib64 /lib /usr/lib /lib64 /usr/lib64 /usr/local/lib64 libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc libc=/lib/libc-2.13.so, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.13' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fPIC', lddlflags='-shared -O2 -g -L/usr/local/lib -fstack-protector' Locally applied patches: @INC for perl 5.15.2: lib /usr/local/lib/perl5/site_perl/5.15.2/x86_64-linux /usr/local/lib/perl5/site_perl/5.15.2 /usr/local/lib/perl5/5.15.2/x86_64-linux /usr/local/lib/perl5/5.15.2 /usr/local/lib/perl5/site_perl . Environment for perl 5.15.2: HOME=/home/jimc LANG=en_US.utf8 LANGUAGE (unset) LD_LIBRARY_PATH=/usr/lib64/mpich2/lib:/usr/lib64/alliance/lib:/usr/lib64/alliance/lib LOGDIR (unset) PATH=/usr/lib64/qt-3.3/bin:/usr/lib64/mpich2/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/lib64/alli ance/bin:/usr/libexec/sdcc:/home/jimc/bin:./bin:.:/usr/lib64/alliance/bin:/usr/libexec/sdcc PERL_BADLANG (unset) SHELL=/bin/bash ```
p5pRT commented 13 years ago

From @jimc

pair of patches generate 2 more OP_IS_* macros​:

   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 D operand type to DF.    This yields a micro-optimization.

   implement OP_IS_NUMCOMPARE like other OP_IS macros

   other macros are written by regen/opcode.pl into opnames.h    Generate OP_IS_NUMCOMPARE the same way\, and get a micro-optimization.    Adds a new 'S\<' operand type for the numeric comparison ops.    Needs make regen.

and here they are​:

p5pRT commented 13 years ago

From @jimc

0001-implement-OP_IS_NUMCOMPARE-like-other-OP_IS-macros.patch ```diff From 4b04e199603b307533a65ecada9e73dfac198fc3 Mon Sep 17 00:00:00 2001 From: Jim Cromie Date: Mon, 18 Apr 2011 14:05:35 -0600 Subject: [PATCH 1/2] implement OP_IS_NUMCOMPARE like other OP_IS macros other macros are written by regen/opcode.pl into opnames.h Generate OP_IS_NUMCOMPARE the same way, and get a micro-optimization. Adds a new 'S<' operand type for the numeric comparison ops. Needs make regen. --- op.c | 8 -------- opnames.h | 3 +++ regen/opcode.pl | 19 ++++++++++++------- regen/opcodes | 29 +++++++++++++++-------------- 4 files changed, 30 insertions(+), 29 deletions(-) diff --git a/op.c b/op.c index 2ff179e..d2cb4f0 100644 --- a/op.c +++ b/op.c @@ -7215,14 +7215,6 @@ Perl_ck_bitop(pTHX_ OP *o) PERL_ARGS_ASSERT_CK_BITOP; -#define OP_IS_NUMCOMPARE(op) \ - ((op) == OP_LT || (op) == OP_I_LT || \ - (op) == OP_GT || (op) == OP_I_GT || \ - (op) == OP_LE || (op) == OP_I_LE || \ - (op) == OP_GE || (op) == OP_I_GE || \ - (op) == OP_EQ || (op) == OP_I_EQ || \ - (op) == OP_NE || (op) == OP_I_NE || \ - (op) == OP_NCMP || (op) == OP_I_NCMP) o->op_private = (U8)(PL_hints & HINT_INTEGER); if (!(o->op_flags & OPf_STACKED) /* Not an assignment */ && (o->op_type == OP_BIT_OR diff --git a/opnames.h b/opnames.h index 0bb9d81..b55cda2 100644 --- a/opnames.h +++ b/opnames.h @@ -404,4 +404,7 @@ typedef enum opcode { #define OP_IS_FILETEST_ACCESS(op) \ ((op) >= OP_FTRREAD && (op) <= OP_FTEEXEC) +#define OP_IS_NUMCOMPARE(op) \ + ((op) >= OP_LT && (op) <= OP_I_NCMP) + /* ex: set ro: */ diff --git a/regen/opcode.pl b/regen/opcode.pl index 791de9f..5e1cf62 100755 --- a/regen/opcode.pl +++ b/regen/opcode.pl @@ -349,9 +349,10 @@ my %opflags = ( 'u' => 128, # defaults to $_ ); -my %OP_IS_SOCKET; -my %OP_IS_FILETEST; -my %OP_IS_FT_ACCESS; +my %OP_IS_SOCKET; # /Fs/ +my %OP_IS_FILETEST; # /F-/ +my %OP_IS_FT_ACCESS; # /F-+/ +my %OP_IS_NUMCOMPARE; # /S{$last} - $op_is->{$first} == scalar @rest + 1) { # contiguous ops -> optimized version - print $on "(op) >= OP_" . uc($first) . " && (op) <= OP_" . uc($last); - print $on ")\n"; + print $on "(op) >= OP_" . uc($first) + . " && (op) <= OP_" . uc($last); } else { print $on join(" || \\\n\t ", - map { "(op) == OP_" . uc() } sort keys %$op_is); - print $on ")\n"; + map { "(op) == OP_" . uc() } sort keys %$op_is); } + print $on ")\n"; } } diff --git a/regen/opcodes b/regen/opcodes index d6720c3..7b871db 100644 --- a/regen/opcodes +++ b/regen/opcodes @@ -30,6 +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< # reference - R # "?" denotes an optional operand. @@ -137,20 +138,20 @@ stringify string ck_fun fsT@ S left_shift left bitshift (<<) ck_bitop fsT2 S S right_shift right bitshift (>>) ck_bitop fsT2 S S -lt numeric lt (<) ck_null Iifs2 S S -i_lt integer lt (<) ck_null ifs2 S S -gt numeric gt (>) ck_null Iifs2 S S -i_gt integer gt (>) ck_null ifs2 S S -le numeric le (<=) ck_null Iifs2 S S -i_le integer le (<=) ck_null ifs2 S S -ge numeric ge (>=) ck_null Iifs2 S S -i_ge integer ge (>=) ck_null ifs2 S S -eq numeric eq (==) ck_null Iifs2 S S -i_eq integer eq (==) ck_null ifs2 S S -ne numeric ne (!=) ck_null Iifs2 S S -i_ne integer ne (!=) ck_null ifs2 S S -ncmp numeric comparison (<=>) ck_null Iifst2 S S -i_ncmp integer comparison (<=>) ck_null ifst2 S S +lt numeric lt (<) ck_null Iifs2 S S< +i_lt integer lt (<) ck_null ifs2 S S< +gt numeric gt (>) ck_null Iifs2 S S< +i_gt integer gt (>) ck_null ifs2 S S< +le numeric le (<=) ck_null Iifs2 S S< +i_le integer le (<=) ck_null ifs2 S S< +ge numeric ge (>=) ck_null Iifs2 S S< +i_ge integer ge (>=) ck_null ifs2 S S< +eq numeric eq (==) ck_null Iifs2 S S< +i_eq integer eq (==) ck_null ifs2 S S< +ne numeric ne (!=) ck_null Iifs2 S S< +i_ne integer ne (!=) ck_null ifs2 S S< +ncmp numeric comparison (<=>) ck_null Iifst2 S S< +i_ncmp integer comparison (<=>) ck_null ifst2 S S< slt string lt ck_null ifs2 S S sgt string gt ck_null ifs2 S S -- 1.7.4.4 ```
p5pRT commented 13 years ago

From @jimc

0002-regen-opcode.pl-generate-OP_IS_DIRHOP-use-in-gv.c.patch ```diff From 51070284f751333c554388e04d4129e728914525 Mon Sep 17 00:00:00 2001 From: Jim Cromie Date: Thu, 2 Jun 2011 00:27:49 -0600 Subject: [PATCH 2/2] 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. --- gv.c | 6 +----- opnames.h | 10 +++++++--- regen/opcode.pl | 14 +++++++++++--- regen/opcodes | 12 ++++++------ 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/gv.c b/gv.c index c274065..116d391 100644 --- a/gv.c +++ b/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) { diff --git a/opnames.h b/opnames.h index b55cda2..26dfbaa 100644 --- a/opnames.h +++ b/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 - 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: */ diff --git a/regen/opcode.pl b/regen/opcode.pl index 5e1cf62..b4576da 100755 --- a/regen/opcode.pl +++ b/regen/opcode.pl @@ -353,6 +353,8 @@ my %OP_IS_SOCKET; # /Fs/ my %OP_IS_FILETEST; # /F-/ my %OP_IS_FT_ACCESS; # /F-+/ my %OP_IS_NUMCOMPARE; # /S 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) = @_; diff --git a/regen/opcodes b/regen/opcodes index 7b871db..688f166 100644 --- a/regen/opcodes +++ b/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. -- 1.7.4.4 ```
p5pRT commented 13 years ago

From @cpansprout

On Fri Sep 09 22​:26​:53 2011\, yoduh wrote​:

pair of patches generate 2 more OP_IS_* macros​:

� �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 D operand type to DF. � �This yields a micro-optimization.

� �implement OP_IS_NUMCOMPARE like other OP_IS macros

� �other macros are written by regen/opcode.pl into opnames.h � �Generate OP_IS_NUMCOMPARE the same way\, and get a micro-optimization. � �Adds a new 'S\<' operand type for the numeric comparison ops. � �Needs make regen.

and here they are​:

Thank you. Applied as 2b420b63 and 332c2eacbb.

p5pRT commented 13 years ago

The RT System itself - Status changed from 'new' to 'open'

p5pRT commented 13 years ago

@cpansprout - Status changed from 'open' to 'resolved'