Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Issue 660072: Added fast support for Math.pow. This simply calculates the result using the... (Closed)

Created:
10 years, 10 months ago by Rico
Modified:
9 years, 6 months ago
Reviewers:
Lasse Reichstein
CC:
v8-dev
Visibility:
Public.

Description

Added fast support for Math.pow. This simply calculates the result using the same method as the old powi version in runtime.cc and also checks if the exponent is 0.5 or -0.5 in which case we calculate the square root or reciprocal value of the square root. Committed: http://code.google.com/p/v8/source/detail?r=3964

Patch Set 1 #

Patch Set 2 : '' #

Total comments: 40

Patch Set 3 : '' #

Patch Set 4 : '' #

Total comments: 24
Unified diffs Side-by-side diffs Delta from patch set Stats (+307 lines, -2 lines) Patch
M src/arm/codegen-arm.h View 1 chunk +3 lines, -0 lines 0 comments Download
M src/arm/codegen-arm.cc View 1 chunk +9 lines, -0 lines 0 comments Download
M src/codegen.cc View 1 chunk +1 line, -0 lines 0 comments Download
M src/ia32/assembler-ia32.h View 1 2 3 4 chunks +10 lines, -1 line 0 comments Download
M src/ia32/assembler-ia32.cc View 1 2 3 3 chunks +65 lines, -0 lines 0 comments Download
M src/ia32/codegen-ia32.h View 1 chunk +3 lines, -0 lines 0 comments Download
M src/ia32/codegen-ia32.cc View 1 2 1 chunk +178 lines, -0 lines 24 comments Download
M src/math.js View 1 chunk +1 line, -1 line 0 comments Download
M src/mips/codegen-mips.h View 1 chunk +2 lines, -0 lines 0 comments Download
M src/mips/codegen-mips.cc View 1 chunk +5 lines, -0 lines 0 comments Download
M src/runtime.h View 1 chunk +1 line, -0 lines 0 comments Download
M src/runtime.cc View 1 2 1 chunk +16 lines, -0 lines 0 comments Download
M src/x64/codegen-x64.h View 1 chunk +3 lines, -0 lines 0 comments Download
M src/x64/codegen-x64.cc View 1 chunk +10 lines, -0 lines 0 comments Download

Messages

Total messages: 5 (0 generated)
Rico
Please look at this. A few notes: I had to update the amount of available ...
10 years, 10 months ago (2010-02-25 07:48:19 UTC) #1
Lasse Reichstein
LGTM if bugs fixed. http://codereview.chromium.org/660072/diff/1028/1032 File src/ia32/assembler-ia32.h (right): http://codereview.chromium.org/660072/diff/1028/1032#newcode96 src/ia32/assembler-ia32.h:96: bool is_valid() const { return ...
10 years, 10 months ago (2010-02-25 10:36:33 UTC) #2
Rico
I addressed the issues and made a few extra adjustments making it more simple - ...
10 years, 10 months ago (2010-02-26 08:01:36 UTC) #3
Lasse Reichstein
LGTM with suggestions. http://codereview.chromium.org/660072/diff/1062/1063 File src/ia32/codegen-ia32.cc (right): http://codereview.chromium.org/660072/diff/1062/1063#newcode5345 src/ia32/codegen-ia32.cc:5345: __ test(y.reg(), Immediate(1)); If you shr(y.reg(),1) ...
10 years, 10 months ago (2010-02-26 09:06:19 UTC) #4
Rico
10 years, 9 months ago (2010-03-04 06:39:29 UTC) #5
http://codereview.chromium.org/660072/diff/1062/1063
File src/ia32/codegen-ia32.cc (right):

http://codereview.chromium.org/660072/diff/1062/1063#newcode5345
src/ia32/codegen-ia32.cc:5345: __ test(y.reg(), Immediate(1));
On 2010/02/26 09:06:20, Lasse Reichstein wrote:
> If you shr(y.reg(),1) here, then the bit that was shifted out is in the carry
> flag. I.e.:
> shr(y.reg(), 1);
> j(not_carry, &no_multiply);
> mulsd(xmm1, xmm0);
> bind(&no_multiply);

Done.

http://codereview.chromium.org/660072/diff/1062/1063#newcode5351
src/ia32/codegen-ia32.cc:5351: __ j(zero, &powi_done);
On 2010/02/26 09:06:20, Lasse Reichstein wrote:
> Just do:
>  mulsd(xmm0, xmm0);
>  j(not_zero, &while_true);  // mulsd doesn't affect flags.
> 
> It does one more mulsd than necessary, but on, e.g., a core2 chip, that's just
> one cycle, and it saves an instruction on each iteration of the loop.
> 
> This and he previous comment should reduce the loop to four operations. That's
> probably only a space saving, since some of the multiplications are dependent
> and have a five cycle latency (and probably want to use the same ALU).

Done.

http://codereview.chromium.org/660072/diff/1062/1063#newcode5360
src/ia32/codegen-ia32.cc:5360: __ mov(p.reg(), Immediate(0x7FF00000));
On 2010/02/26 09:06:20, Lasse Reichstein wrote:
> I don't think this is single-precission infinity.
> Single precission floats only have eight exponent bits.
> Positive infinity would be 0x7f800000.
> (And 0x7ff00000 is a quiet NaN with payload).
> 
> Do we need a better test for this case? :)
As discussed offline this will always branch to runtime because of the way
comisd works, I have changed it so that it only goes to runtime if it is
actually infinity.
We already have tests for this (but they where not hit since runtime executes
correctly and we always went there if y is an negative integer).

http://codereview.chromium.org/660072/diff/1062/1063#newcode5363
src/ia32/codegen-ia32.cc:5363: __ comisd(xmm0, xmm1);
On 2010/02/26 09:06:20, Lasse Reichstein wrote:
> Use ucomisd instead of comisd.
> 

Done - added ucomisd to assembler-ia32

http://codereview.chromium.org/660072/diff/1062/1063#newcode5376
src/ia32/codegen-ia32.cc:5376: __ comisd(xmm1, xmm1);
On 2010/02/26 09:06:20, Lasse Reichstein wrote:
> ucomisd

Done.

http://codereview.chromium.org/660072/diff/1062/1063#newcode5395
src/ia32/codegen-ia32.cc:5395: __ cmp(Operand(p.reg()),
Immediate(HeapNumber::kExponentMask));
On 2010/02/26 09:06:20, Lasse Reichstein wrote:
> Add comment here saying something like "p is NaN or +/-Infinity"

Done.

http://codereview.chromium.org/660072/diff/1062/1063#newcode5409
src/ia32/codegen-ia32.cc:5409: __ comisd(xmm2, xmm1);
On 2010/02/26 09:06:20, Lasse Reichstein wrote:
> ucomisd
> 

Done.

http://codereview.chromium.org/660072/diff/1062/1063#newcode5413
src/ia32/codegen-ia32.cc:5413: __ sqrt(xmm0, xmm0);
On 2010/02/26 09:06:20, Lasse Reichstein wrote:
> Why isn't sqrt called sqrtsd?
Changed name and moved down to sse2 instructions.

http://codereview.chromium.org/660072/diff/1062/1063#newcode5415
src/ia32/codegen-ia32.cc:5415: __ movsd(xmm1, xmm3);
On 2010/02/26 09:06:20, Lasse Reichstein wrote:
> Move sqrt to the end (i.e., sqrt(xmm1,xmm1)) since it'shas a higher latency
than
> movsd.
> (And perhaps comment that 1/sqrt(x) = sqrt(1/x)).
> 

Done.

http://codereview.chromium.org/660072/diff/1062/1063#newcode5421
src/ia32/codegen-ia32.cc:5421: __ mov(p.reg(), Immediate(0x3F000000));
On 2010/02/26 09:06:20, Lasse Reichstein wrote:
> You have -0.5 in xmm2 already, and 1.0 in xmm3, so just do
> addsd(xmm2, xmm3) to get +0.5.
> 

Done.

http://codereview.chromium.org/660072/diff/1062/1063#newcode5425
src/ia32/codegen-ia32.cc:5425: __ comisd(xmm2, xmm1);
On 2010/02/26 09:06:20, Lasse Reichstein wrote:
> ucomisd
> 

Done.

http://codereview.chromium.org/660072/diff/1062/1063#newcode5428
src/ia32/codegen-ia32.cc:5428: __ sqrt(xmm0, xmm0);
On 2010/02/26 09:06:20, Lasse Reichstein wrote:
> do 
>  movsd(xmm1, xmm0);
>  sqrt(xmm1, xmm1);
> instead, to allow the latency of the sqrt operation to be spent during the
heap
> allocation code, instead of stalling on the move.

Done.

Powered by Google App Engine
This is Rietveld 408576698