Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[patch] optimize OP_IS_(FILETEST|SOCKET) macros

1 view
Skip to first unread message

Jim Cromie

unread,
Feb 9, 2008, 9:56:59 AM2/9/08
to Perl 5 Porters

attached patch to opcode.pl generates faster/smaller versions
of 2 macros written to opcode.h

IE:

/* the OP_IS_(SOCKET|FILETEST) macros are optimized to a simple range
check because all the member OPs are contiguous in opcode.pl
<DATA> table. opcode.pl verifies the range contiguity. */

#define OP_IS_SOCKET(op) \
((op) >= OP_SEND && (op) <= OP_GETPEERNAME)

#define OP_IS_FILETEST(op) \
((op) >= OP_FTRREAD && (op) <= OP_FTBINARY)


This optimized form is generated automatically when
the set of OPs have consecutive opnumbers, otherwize
the traditional form is generated.

I moved send & recv ops down in opcode.pl <DATA>
so that theyre contiguous with the others.
the OP_FT* ops were already consecutive.

Also, 1 unrelated touch to change enum opcode syntax
to explicitly number the enum symbols.

typedef enum opcode {
OP_NULL = 0,
OP_STUB = 1,
OP_SCALAR = 2,
OP_PUSHMARK = 3,
OP_WANTARRAY = 4,


diff.op-is.20080209.073114

Nicholas Clark

unread,
Feb 10, 2008, 2:37:08 AM2/10/08
to Jim Cromie, Perl 5 Porters
On Sat, Feb 09, 2008 at 07:56:59AM -0700, Jim Cromie wrote:
>
> attached patch to opcode.pl generates faster/smaller versions
> of 2 macros written to opcode.h

Oooh, util.o gets 1% smaller:

util.o.orig : 35352 1.010
util.o : 35016 1.000

Thanks, applied (change 33267)

Nicholas Clark

Jim Cromie

unread,
Feb 10, 2008, 2:32:58 PM2/10/08
to Perl 5 Porters
> > attached patch to opcode.pl generates faster/smaller versions
> > of 2 macros written to opcode.h
>
> Oooh, util.o gets 1% smaller:
>
> util.o.orig : 35352 1.010
> util.o : 35016 1.000
>
> Thanks, applied (change 33267)
>
> Nicholas Clark
>

cool - heres an add-on.

1 - fix bug in gen_op_is_macro()

I missed a variable change, so unoptimized macros would be wrong.
while there, hoisted print "#define $macname" out of if/else,
added paranoid check (if range was ill-def'd)

Obviously, this (4th) chunk is needed, please take it, whether or not
you like the rest. Or ask, and I'll resend.


2 - remove OP_IS_FILETEST_ACCESS from op.h

3 - add it into opcode.pl

RFC - I tweak the DATA by adding a '+' flag to
the filetest-access OPs so that opcode.pl could handle the
macro-gen the same way as the previous patch did.

I had misgivings about this approach, since it crams yet another
crypto-spec into the DATA, but its simpler (and clearer) than populating
%OP_IS_FT_ACCESS purely with code.

this is a truly tiny shrink.

125018 0 0 125018 1e85a fta/op.o
125034 0 0 125034 1e86a blead/op.o

Rafael Garcia-Suarez

unread,
Feb 25, 2008, 3:03:09 AM2/25/08
to Jim Cromie, Perl 5 Porters
On 10/02/2008, Jim Cromie <jim.c...@gmail.com> wrote:
> and heres that patch :-/

Thanks, applied as #33364. I also fixed the calls to the
OP_IS_FILETEST_ACCESS macro, that was expecting an OP*, and now
expects an integer.

0 new messages