develooper Front page | perl.perl5.porters | Postings from August 2010

Re: [perl #77536] [PATCH] Support B::Generate and B::C

Thread Previous | Thread Next
From:
Reini Urban
Date:
August 31, 2010 14:49
Subject:
Re: [perl #77536] [PATCH] Support B::Generate and B::C
Message ID:
4C7D78FC.30705@x-ray.at
Jim Cromie (via RT) schrieb:
> # New Ticket Created by  Jim Cromie
> # Please include the string:  [perl #77536]
>> e: implements 'use integer';
> can you suggest perl statements that trigger these particular cases ?

I already posted a similar example with and without.
Just look for i_add vs add, and i_modulo vs modulo.

 From worse to better, so you see how bad the optimiser really is.
I wouldn't really test this, because it should be kept
implementation dependent how "good" our optimizer is.

Do almost nothing, slow: ($n is not detected as constant)

$ perl -MO=Terse -e '$n=1127;$result=($n%1000)+167772160;'
LISTOP (0x16b22a0) leave [1]
     OP (0x16b2458) enter
     COP (0x16b2258) nextstate
     BINOP (0x16b2230) sassign
         SVOP (0x16b2210) const [6] IV (0x15a2138) 1127
         UNOP (0x16b21f0) null [15]
             PADOP (0x16b21d0) gvsv  GV (0x15a2150) *n
     COP (0x16b2400) nextstate
     BINOP (0x16b23d8) sassign
         BINOP (0x16b23b0) add [5]
             BINOP (0x16b2368) modulo [4]
                 UNOP (0x16b2328) null [15]
                     PADOP (0x16b2308) gvsv  GV (0x15a2150) *n
                 SVOP (0x16b2348) const [7] IV (0x15a2180) 1000
             SVOP (0x16b2390) const [8] IV (0x1543bf8) 167772160
         UNOP (0x16b22e8) null [15]
             PADOP (0x16b22c8) gvsv  GV (0x15a22b8) *result

Use at least intops:

$ perl -MO=Terse -Minteger -e '$n=1127;$result=($n%1000)+167772160;'
LISTOP (0x16b2998) leave [1]
     OP (0x16b2b50) enter
     COP (0x16b2940) nextstate
     BINOP (0x16b2918) sassign
         SVOP (0x16b2340) const [6] IV (0x15a2210) 1127
         UNOP (0x16b2400) null [15]
             PADOP (0x16b21f0) gvsv  GV (0x15a2288) *n
     COP (0x16b2af8) nextstate
     BINOP (0x16b2ad0) sassign
         BINOP (0x16b2aa8) i_add [5]
             BINOP (0x16b2a60) i_modulo [4]
                 UNOP (0x16b2a20) null [15]
                     PADOP (0x16b2a00) gvsv  GV (0x15a2288) *n
                 SVOP (0x16b2a40) const [7] IV (0x15a2198) 1000
             SVOP (0x16b2a88) const [8] IV (0x16c2aa0) 167772160
         UNOP (0x16b29e0) null [15]
             PADOP (0x16b29c0) gvsv  GV (0x1543be0) *result

Do some simple minor folding:

$ perl -MO=Terse -e '$result=(1127%1000)+167772160;'
LISTOP (0x16b2370) leave [1]
     OP (0x16b2398) enter
     COP (0x16b2328) nextstate
     BINOP (0x16b2300) sassign
         SVOP (0x16b22e0) const [4] IV (0x15a2270) 167772287
         UNOP (0x16b21f0) null [15]
             PADOP (0x16b21d0) gvsv  GV (0x15a2150) *result

And finally constant fold with symbols:

$ perl -MO=Terse -Minteger -e 'use constant n=>1127; 
$result=(n%1000)+167772160;'
LISTOP (0x13a0520) leave [1]
     OP (0x13786c0) enter
     COP (0x13a04c0) nextstate
     BINOP (0x13a0498) sassign
         SVOP (0x1378448) const [4] IV (0x13816a8) 167772287
         UNOP (0x1396920) null [15]
             PADOP (0x1396730) gvsv  GV (0x13b09b8) *result
-- 
Reini Urban

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About