Skip to content

Commit

Permalink
OP_AELEMFASTLEX_STORE - combined sassign/aelemfast_lex
Browse files Browse the repository at this point in the history
This commit introduces a new OP to replace simple cases of OP_SASSIGN
and OP_AELEMFAST_LEX. (Similar concept to GH Perl#19943)

For example, `my @ary; $ary[0] = "boo"` is currently implemented as:
    7     <2> sassign vKS/2 ->8
    5        <$> const[PV "boo"] s ->6
    -        <1> ex-aelem sKRM*/2 ->7
    6           <0> aelemfast_lex[@ary:1,2] sRM ->7
    -           <0> ex-const s ->-

But now will be turned into:
    6     <1> aelemfastlex_store[@ary:1,2] vKS ->7
    5        <$> const(PV "boo") s ->6
    -        <1> ex-aelem sKRM*/2 ->6
    -           <0> ex-aelemfast_lex sRM ->6
    -           <0> ex-const s ->-

This is intended to be a transparent performance optimization.
It should be applicable for RHS optrees of varying complexity.
  • Loading branch information
richardleach committed Sep 7, 2022
1 parent ec18fac commit aafefcb
Show file tree
Hide file tree
Showing 12 changed files with 451 additions and 282 deletions.
2 changes: 1 addition & 1 deletion ext/Opcode/Opcode.pm
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ invert_opset function.
rv2sv sassign padsv_store
rv2av aassign aelem aelemfast aelemfast_lex aslice kvaslice
av2arylen
av2arylen aelemfastlex_store
rv2hv helem hslice kvhslice each values keys exists delete
aeach akeys avalues multideref argelem argdefelem argcheck
Expand Down
11 changes: 11 additions & 0 deletions lib/B/Deparse.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4305,6 +4305,17 @@ sub pp_gv {
return $self->maybe_qualify("", $self->gv_name($gv));
}

sub pp_aelemfastlex_store {
my $self = shift;
my($op, $cx) = @_;
my $name = $self->padname($op->targ);
$name =~ s/^@/\$/;
my $i = $op->private;
$i -= 256 if $i > 127;
my $val = $self->deparse($op->first, 7);
return $self->maybe_parens("${name}[$i] = $val", $cx, 7);
}

sub pp_aelemfast_lex {
my $self = shift;
my($op, $cx) = @_;
Expand Down
1 change: 1 addition & 0 deletions lib/B/Op_private.pm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit aafefcb

Please sign in to comment.