Skip to content

Commit

Permalink
Make the for ^100 loop optimization about 2% faster
Browse files Browse the repository at this point in the history
By moving the update of the index to the condition and using a 2 parameter
nqp::while instead of the 3 parameter one.
  • Loading branch information
lizmat committed Jul 31, 2018
1 parent d69fd2f commit 9b07e7b
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/Perl6/Optimizer.nqp
Expand Up @@ -2196,15 +2196,18 @@ class Perl6::Optimizer {
$op.op('stmts');
$op.push(QAST::Stmts.new(

# my int $it = @bounds[0]
# my int $it := @bounds[0] - 1
QAST::Op.new( :op<bind>,
QAST::Var.new(
:name($it_var), :scope<local>, :decl<var>, :returns(int)
),
@bounds[0]
QAST::Op.new( :op<sub_i>,
@bounds[0],
QAST::IVal.new( :value(1))
)
),

# my int $max = @bounds[1]
# my int $max := @bounds[1]
QAST::Op.new( :op<bind>,
QAST::Var.new(
:name($max_var), :scope<local>, :decl<var>, :returns(int)
Expand All @@ -2219,26 +2222,26 @@ class Perl6::Optimizer {
),

# nqp::while(
# nqp::isle_i($it,$max),
# nqp::isle_i(
# nqp::bind($it,nqp::add_i($it,1)),
# $max
# )
QAST::Op.new( :op<while>,
QAST::Op.new( :op<isle_i>,
QAST::Var.new(:name($it_var), :scope<local>, :returns(int)),
QAST::Op.new( :op<bind>,
QAST::Var.new(:name($it_var), :scope<local>, :returns(int)),
QAST::Op.new( :op<add_i>,
QAST::Var.new(:name($it_var),:scope<local>,:returns(int)),
QAST::IVal.new( :value(1) )
)
),
QAST::Var.new(:name($max_var), :scope<local>, :returns(int))
),

# nqp::call($callee, $it)
QAST::Op.new( :op<call>,
QAST::Var.new(:name($callee_var), :scope<local> ),
QAST::Var.new(:name($it_var), :scope<local>, :returns(int))
),

# nqp::bind($it,nqp::add_i($it,1))
QAST::Op.new( :op<bind>,
QAST::Var.new(:name($it_var), :scope<local>, :returns(int)),
QAST::Op.new( :op<add_i>,
QAST::Var.new(:name($it_var), :scope<local>, :returns(int)),
QAST::IVal.new( :value(1) )
)
)
),

Expand Down

0 comments on commit 9b07e7b

Please sign in to comment.