Improve the assembly code for power function with integer exponential on x64 (issue 10939013)

67 views
Skip to first unread message

xi....@intel.com

unread,
Sep 18, 2012, 2:35:07 AM9/18/12
to yan...@chromium.org, kas...@chromium.org, yuqian...@intel.com, veg...@chromium.org, v8-...@googlegroups.com
Reviewers: Yang, Kasper Lund, yuqiang.xian, Vyacheslav Egorov,

Message:
Hi, Yang, Kasper, Yuqiang and Vyacheslav

This is a port for patch of issue 10916311. It can gain similar performance
improvement on x64. Would you please review it?

Thanks,
-Xi

Description:
Improve the assembly code for power function with integer exponential on x64

The change removes one unused multiply and reschedules
the shift, multiply and jump instructions to reduce
stall. Experiment shows it improve about 20% performance
on x64 for exponetials from about 100 to 2000.


Please review this at https://codereview.chromium.org/10939013/

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
M src/x64/code-stubs-x64.cc


Index: src/x64/code-stubs-x64.cc
===================================================================
--- src/x64/code-stubs-x64.cc (revision 12493)
+++ src/x64/code-stubs-x64.cc (working copy)
@@ -2262,21 +2262,28 @@
__ movsd(double_scratch2, double_result); // Load double_exponent with
1.

// Get absolute value of exponent.
- Label no_neg, while_true, no_multiply;
+ Label no_neg, while_true, while_false;
__ testl(scratch, scratch);
__ j(positive, &no_neg, Label::kNear);
__ negl(scratch);
__ bind(&no_neg);

+ __ j(zero, &while_false, Label::kNear);
+ __ shrl(scratch, Immediate(1));
+ // Above condition means CF=0 && ZF =0.
+ // So the last shifted bit is 0 and the rest is not 0.
+ __ j(above, &while_true, Label::kNear);
+ __ movsd(double_result, double_scratch);
+ __ j(zero, &while_false, Label::kNear);
+
__ bind(&while_true);
__ shrl(scratch, Immediate(1));
- __ j(not_carry, &no_multiply, Label::kNear);
+ __ mulsd(double_scratch, double_scratch);
+ __ j(above, &while_true, Label::kNear);
__ mulsd(double_result, double_scratch);
- __ bind(&no_multiply);
-
- __ mulsd(double_scratch, double_scratch);
__ j(not_zero, &while_true);

+ __ bind(&while_false);
// If the exponent is negative, return 1/result.
__ testl(exponent, exponent);
__ j(greater, &done);


yan...@chromium.org

unread,
Sep 18, 2012, 3:59:09 AM9/18/12
to xi....@intel.com, kas...@chromium.org, yuqian...@intel.com, veg...@chromium.org, v8-...@googlegroups.com
On 2012/09/18 06:35:07, xqian wrote:
> Hi, Yang, Kasper, Yuqiang and Vyacheslav

> This is a port for patch of issue 10916311. It can gain similar
> performance
> improvement on x64. Would you please review it?

> Thanks,
> -Xi

LGTM. Landing.

https://codereview.chromium.org/10939013/

xi....@intel.com

unread,
Sep 18, 2012, 6:02:30 AM9/18/12
to yan...@chromium.org, kas...@chromium.org, yuqian...@intel.com, veg...@chromium.org, v8-...@googlegroups.com
On 2012/09/18 07:59:09, Yang wrote:
> On 2012/09/18 06:35:07, xqian wrote:
> > Hi, Yang, Kasper, Yuqiang and Vyacheslav
> >
> > This is a port for patch of issue 10916311. It can gain similar
> performance
> > improvement on x64. Would you please review it?
> >
> > Thanks,
> > -Xi

> LGTM. Landing.

Thank you!
-Xi

https://codereview.chromium.org/10939013/
Reply all
Reply to author
Forward
0 new messages