This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Enable OPpTARGET_MY optimisation for cmp/<=>
authorFather Chrysostomos <sprout@cpan.org>
Mon, 29 Dec 2014 14:13:48 +0000 (06:13 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 30 Dec 2014 06:03:29 +0000 (22:03 -0800)
We can only do it for <=> under â€˜use integer’.

The non-integer <=> will push undef on to the stack.  Enabling
the optimisation for it would cause \($lexical = $x <=> "nan") to
leave $lexical with its previous value and return a reference to
&PL_sv_undef.

lib/B/Deparse.pm
lib/B/Op_private.pm
opcode.h
regen/op_private
regen/opcodes

index ed47097..703c1e0 100644 (file)
@@ -2833,7 +2833,7 @@ sub pp_i_lt { binop(@_, "<", 15) }
 sub pp_i_gt { binop(@_, ">", 15) }
 sub pp_i_ge { binop(@_, ">=", 15) }
 sub pp_i_le { binop(@_, "<=", 15) }
-sub pp_i_ncmp { binop(@_, "<=>", 14) }
+sub pp_i_ncmp { maybe_targmy(@_, \&binop, "<=>", 14) }
 
 sub pp_seq { binop(@_, "eq", 14) }
 sub pp_sne { binop(@_, "ne", 14) }
@@ -2841,7 +2841,7 @@ sub pp_slt { binop(@_, "lt", 15) }
 sub pp_sgt { binop(@_, "gt", 15) }
 sub pp_sge { binop(@_, "ge", 15) }
 sub pp_sle { binop(@_, "le", 15) }
-sub pp_scmp { binop(@_, "cmp", 14) }
+sub pp_scmp { maybe_targmy(@_, \&binop, "cmp", 14) }
 
 sub pp_sassign { binop(@_, "=", 7, SWAP_CHILDREN) }
 sub pp_aassign { binop(@_, "=", 7, SWAP_CHILDREN | LIST_CONTEXT) }
index b6d2f21..e9e9ec3 100644 (file)
@@ -150,7 +150,7 @@ $bits{$_}{7} = 'OPpPV_IS_UTF8' for qw(dump goto last next redo);
 $bits{$_}{6} = 'OPpREFCOUNTED' for qw(leave leaveeval leavesub leavesublv leavewrite);
 $bits{$_}{6} = 'OPpRUNTIME' for qw(match pushre qr subst substcont);
 $bits{$_}{2} = 'OPpSLICEWARNING' for qw(aslice hslice padav padhv rv2av rv2hv);
-$bits{$_}{4} = 'OPpTARGET_MY' for qw(abs add atan2 chdir chmod chomp chown chr chroot concat cos crypt divide exec exp flock getpgrp getppid getpriority hex i_add i_divide i_modulo i_multiply i_subtract index int kill left_shift length link log match mkdir modulo multiply oct ord pow push rand rename repeat right_shift rindex rmdir schomp setpgrp setpriority sin sleep split sqrt srand stringify subst subtract symlink system time trans transr unlink unshift utime vec wait waitpid);
+$bits{$_}{4} = 'OPpTARGET_MY' for qw(abs add atan2 chdir chmod chomp chown chr chroot concat cos crypt divide exec exp flock getpgrp getppid getpriority hex i_add i_divide i_modulo i_multiply i_ncmp i_subtract index int kill left_shift length link log match mkdir modulo multiply oct ord pow push rand rename repeat right_shift rindex rmdir schomp scmp setpgrp setpriority sin sleep split sqrt srand stringify subst subtract symlink system time trans transr unlink unshift utime vec wait waitpid);
 $bits{$_}{5} = 'OPpTRANS_COMPLEMENT' for qw(trans transr);
 $bits{$_}{7} = 'OPpTRANS_DELETE' for qw(trans transr);
 $bits{$_}{0} = 'OPpTRANS_FROM_UTF' for qw(trans transr);
@@ -781,7 +781,7 @@ our %ops_using = (
     OPpSORT_DESCEND          => [qw(sort)],
     OPpSPLIT_IMPLIM          => [qw(split)],
     OPpSUBSTR_REPL_FIRST     => [qw(substr)],
-    OPpTARGET_MY             => [qw(abs add atan2 chdir chmod chomp chown chr chroot concat cos crypt divide exec exp flock getpgrp getppid getpriority hex i_add i_divide i_modulo i_multiply i_subtract index int kill left_shift length link log match mkdir modulo multiply oct ord pow push rand rename repeat right_shift rindex rmdir schomp setpgrp setpriority sin sleep split sqrt srand stringify subst subtract symlink system time trans transr unlink unshift utime vec wait waitpid)],
+    OPpTARGET_MY             => [qw(abs add atan2 chdir chmod chomp chown chr chroot concat cos crypt divide exec exp flock getpgrp getppid getpriority hex i_add i_divide i_modulo i_multiply i_ncmp i_subtract index int kill left_shift length link log match mkdir modulo multiply oct ord pow push rand rename repeat right_shift rindex rmdir schomp scmp setpgrp setpriority sin sleep split sqrt srand stringify subst subtract symlink system time trans transr unlink unshift utime vec wait waitpid)],
     OPpTRANS_COMPLEMENT      => [qw(trans transr)],
 );
 
index d24dc18..0cbf277 100644 (file)
--- a/opcode.h
+++ b/opcode.h
@@ -1840,14 +1840,14 @@ EXTCONST U32 PL_opargs[] = {
        0x00011226,     /* ne */
        0x00011206,     /* i_ne */
        0x0001122e,     /* ncmp */
-       0x0001120e,     /* i_ncmp */
+       0x0001121e,     /* i_ncmp */
        0x00011206,     /* slt */
        0x00011206,     /* sgt */
        0x00011206,     /* sle */
        0x00011206,     /* sge */
        0x00011206,     /* seq */
        0x00011206,     /* sne */
-       0x0001120e,     /* scmp */
+       0x0001121e,     /* scmp */
        0x0001120e,     /* bit_and */
        0x0001120e,     /* bit_xor */
        0x0001120e,     /* bit_or */
@@ -2469,14 +2469,14 @@ EXTCONST I16  PL_op_private_bitdef_ix[] = {
       12, /* ne */
       12, /* i_ne */
       12, /* ncmp */
-      12, /* i_ncmp */
+      74, /* i_ncmp */
       12, /* slt */
       12, /* sgt */
       12, /* sle */
       12, /* sge */
       12, /* seq */
       12, /* sne */
-      12, /* scmp */
+      74, /* scmp */
       12, /* bit_and */
       12, /* bit_xor */
       12, /* bit_or */
@@ -2796,7 +2796,7 @@ EXTCONST U16  PL_op_private_bitdefs[] = {
     0x03b8, 0x1570, 0x3c8c, 0x3748, 0x2da5, /* const */
     0x29dc, 0x2ef9, /* gvsv */
     0x13d5, /* gv */
-    0x0067, /* gelem, lt, i_lt, gt, i_gt, le, i_le, ge, i_ge, eq, i_eq, ne, i_ne, ncmp, i_ncmp, slt, sgt, sle, sge, seq, sne, scmp, bit_and, bit_xor, bit_or, smartmatch, lslice, xor */
+    0x0067, /* gelem, lt, i_lt, gt, i_gt, le, i_le, ge, i_ge, eq, i_eq, ne, i_ne, ncmp, slt, sgt, sle, sge, seq, sne, bit_and, bit_xor, bit_or, smartmatch, lslice, xor */
     0x29dc, 0x3bd8, 0x0257, /* padsv */
     0x29dc, 0x3bd8, 0x2acc, 0x38c9, /* padav */
     0x29dc, 0x3bd8, 0x0534, 0x05d0, 0x2acc, 0x38c9, /* padhv */
@@ -2813,7 +2813,7 @@ EXTCONST U16  PL_op_private_bitdefs[] = {
     0x0adc, 0x0458, 0x0067, /* sassign */
     0x0758, 0x2acc, 0x0067, /* aassign */
     0x3ef0, 0x0003, /* chomp, schomp, sin, cos, exp, log, sqrt, int, hex, oct, abs, length, ord, chr, chroot, rmdir */
-    0x3ef0, 0x0067, /* pow, multiply, i_multiply, divide, i_divide, modulo, i_modulo, add, i_add, subtract, i_subtract, concat, left_shift, right_shift */
+    0x3ef0, 0x0067, /* pow, multiply, i_multiply, divide, i_divide, modulo, i_modulo, add, i_add, subtract, i_subtract, concat, left_shift, right_shift, i_ncmp, scmp */
     0x1058, 0x3ef0, 0x0067, /* repeat */
     0x3ef0, 0x012f, /* stringify, atan2, rand, srand, index, rindex, crypt, push, unshift, flock, chdir, chown, unlink, chmod, utime, rename, link, symlink, mkdir, waitpid, system, exec, kill, getpgrp, setpgrp, getpriority, setpriority, sleep */
     0x33f0, 0x2acc, 0x00cb, /* substr */
@@ -2947,14 +2947,14 @@ EXTCONST U8 PL_op_private_valid[] = {
     /* NE         */ (OPpARG2_MASK),
     /* I_NE       */ (OPpARG2_MASK),
     /* NCMP       */ (OPpARG2_MASK),
-    /* I_NCMP     */ (OPpARG2_MASK),
+    /* I_NCMP     */ (OPpARG2_MASK|OPpTARGET_MY),
     /* SLT        */ (OPpARG2_MASK),
     /* SGT        */ (OPpARG2_MASK),
     /* SLE        */ (OPpARG2_MASK),
     /* SGE        */ (OPpARG2_MASK),
     /* SEQ        */ (OPpARG2_MASK),
     /* SNE        */ (OPpARG2_MASK),
-    /* SCMP       */ (OPpARG2_MASK),
+    /* SCMP       */ (OPpARG2_MASK|OPpTARGET_MY),
     /* BIT_AND    */ (OPpARG2_MASK),
     /* BIT_XOR    */ (OPpARG2_MASK),
     /* BIT_OR     */ (OPpARG2_MASK),
index 4b7c425..68286a6 100644 (file)
@@ -327,7 +327,7 @@ addbits($_, 7 => qw(OPpLVAL_INTRO LVINTRO))
 # Only the code paths that handle scalar rvalue context matter.  If dTARG
 # or RETPUSHNO occurs only in list or lvalue paths, T is safe.
 #
-# lt and friends do SETs (including ncmp, but not scmp)
+# lt and friends do SETs (including ncmp, but not scmp or i_ncmp)
 #
 # Additional mode of failure: the opcode can modify TARG before it "used"
 # all the arguments (or may call an external function which does the same).
index 4d5770e..11df144 100644 (file)
@@ -152,7 +152,7 @@ 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<
+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
@@ -160,7 +160,7 @@ sle         string le               ck_null         ifs2    S S
 sge            string ge               ck_null         ifs2    S S
 seq            string eq               ck_null         ifs2    S S
 sne            string ne               ck_null         ifs2    S S
-scmp           string comparison (cmp) ck_null         ifst2   S S
+scmp           string comparison (cmp) ck_null         ifsT2   S S
 
 bit_and                bitwise and (&)         ck_bitop        fst2    S S
 bit_xor                bitwise xor (^)         ck_bitop        fst2    S S