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

Issue 10382033: x86/x64 port of Math.floor(x/y) to use integer division for specific divisor (Closed)

Created:
8 years, 7 months ago by Zheng Liu
Modified:
8 years, 6 months ago
Reviewers:
Erik Corry, fschneider, Yang
CC:
v8-dev, zheng.z.liu
Visibility:
Public.

Description

x86/x64 port of Math.floor(x/y) to use integer division for specific divisor. Only handles when x is int32 and y is int32 constant. BUG=v8:2038 Currently implemented by imul (not fpmul). x86 and x64 algorithm differs a bit. x86 implementation is kind of cumbersome, but I couldn't think of better ways. Committed: https://code.google.com/p/v8/source/detail?r=11887

Patch Set 1 #

Patch Set 2 : let ia32 use same algo as x64 #

Patch Set 3 : #

Total comments: 11

Patch Set 4 : #

Total comments: 8

Patch Set 5 : #

Unified diffs Side-by-side diffs Delta from patch set Stats (+375 lines, -5 lines) Patch
M src/hydrogen-instructions.h View 1 2 3 4 1 chunk +3 lines, -0 lines 0 comments Download
M src/hydrogen-instructions.cc View 1 2 3 4 2 chunks +9 lines, -1 line 0 comments Download
M src/ia32/disasm-ia32.cc View 1 2 3 4 1 chunk +1 line, -0 lines 0 comments Download
M src/ia32/lithium-codegen-ia32.cc View 1 2 3 4 1 chunk +103 lines, -0 lines 0 comments Download
M src/ia32/lithium-ia32.h View 1 2 3 4 3 chunks +19 lines, -0 lines 0 comments Download
M src/ia32/lithium-ia32.cc View 1 2 3 4 1 chunk +47 lines, -2 lines 0 comments Download
M src/x64/disasm-x64.cc View 1 2 3 4 1 chunk +3 lines, -0 lines 0 comments Download
M src/x64/lithium-codegen-x64.cc View 1 2 3 4 1 chunk +83 lines, -0 lines 0 comments Download
M src/x64/lithium-x64.h View 1 2 3 4 3 chunks +19 lines, -0 lines 0 comments Download
M src/x64/lithium-x64.cc View 1 2 3 4 1 chunk +45 lines, -2 lines 0 comments Download
A test/mjsunit/math-floor-of-div-minus-zero.js View 1 2 3 4 1 chunk +40 lines, -0 lines 0 comments Download
M test/mjsunit/mjsunit.status View 1 2 3 4 1 chunk +3 lines, -0 lines 0 comments Download

Messages

Total messages: 8 (0 generated)
Zheng Liu
8 years, 7 months ago (2012-05-07 09:56:15 UTC) #1
Zheng Liu
On 2012/05/07 09:56:15, Zheng Liu wrote: Could you please review this patch? Thanks.
8 years, 7 months ago (2012-05-15 04:44:44 UTC) #2
Zheng Liu
Any update on this? Thanks. Zheng Liu zheng.z.liu@intel.com
8 years, 6 months ago (2012-06-08 04:31:19 UTC) #3
Yang
I'm very sorry that this has taken this long. I had a look over it. ...
8 years, 6 months ago (2012-06-19 15:41:38 UTC) #4
Zheng Liu
Rebased and comments addressed. Also added a simple kBailoutOnMinusZero handling, please check it. Apparently the ...
8 years, 6 months ago (2012-06-20 09:14:29 UTC) #5
Yang
I have still some comments, but I think after those are addressed, this CL is ...
8 years, 6 months ago (2012-06-20 12:19:42 UTC) #6
Zheng Liu
http://codereview.chromium.org/10382033/diff/16002/src/hydrogen-instructions.h File src/hydrogen-instructions.h (right): http://codereview.chromium.org/10382033/diff/16002/src/hydrogen-instructions.h#newcode2780 src/hydrogen-instructions.h:2780: virtual HValue* EnsureAndPropagateNotMinusZero(BitVector* visited) { On 2012/06/20 12:19:42, Yang ...
8 years, 6 months ago (2012-06-20 13:54:15 UTC) #7
Yang
8 years, 6 months ago (2012-06-20 13:59:23 UTC) #8
On 2012/06/20 13:54:15, Zheng Liu wrote:
> http://codereview.chromium.org/10382033/diff/16002/src/hydrogen-instructions.h
> File src/hydrogen-instructions.h (right):
> 
>
http://codereview.chromium.org/10382033/diff/16002/src/hydrogen-instructions....
> src/hydrogen-instructions.h:2780: virtual HValue*
> EnsureAndPropagateNotMinusZero(BitVector* visited) {
> On 2012/06/20 12:19:42, Yang wrote:
> > All implementations of EnsureAndPropagateNotMinusZero can be found in
> > hydrogen-instructions.cc around like 2200. Please only put the function
header
> > here and move the implementation to hydrogen-instructions.cc like the
others.
> 
> Done.
> 
>
http://codereview.chromium.org/10382033/diff/16002/src/ia32/lithium-codegen-i...
> File src/ia32/lithium-codegen-ia32.cc (right):
> 
>
http://codereview.chromium.org/10382033/diff/16002/src/ia32/lithium-codegen-i...
> src/ia32/lithium-codegen-ia32.cc:1058: // The sequence is tedious because
> neg(dividend) might overflow.
> On 2012/06/20 12:19:42, Yang wrote:
> > I took a second look. Wouldn't we circumvent this problem if we simply
divide
> > first and then negate? We would then observe three distinct cases (if
divisor
> <
> > 0):
> > - divisor is -1: we can simply do a NEG. Only if divident is kMinInt would
NEG
> > overflow. We guard against this case first and deopt here, since we would
> > require a double representation for the result anyway (because (-kMinInt) >
> > kMaxInt). This case has already been dealt with in the switch!
> > - divisor is -2 or less, and divident is 0: we bail out if
kBailoutOnMinusZero
> > is set, otherwise return 0.
> > - divisor is -2 or less, and divident is not 0: we calculate
> > divident/divisor_abs by shifting and set the sign with neg. We don't expect
> > overflow for neg because divident/divisor_abs cannot be kMinInt.
> > 
> > Did I overlook anything? With this, we don't clobber divident, so it doesn't
> > have to be reserved with UseTempRegister.
> 
> As a floor() op, it's not symmetric around zero.
> e.g. Math.floor(1/-4) => -1
> 
>
http://codereview.chromium.org/10382033/diff/16002/src/ia32/lithium-codegen-i...
> src/ia32/lithium-codegen-ia32.cc:1080: unsigned b = 31 -
> CompilerIntrinsics::CountLeadingZeros(divisor_abs);
> On 2012/06/20 12:19:42, Yang wrote:
> > I assume divisor_abs == divisor here? Maybe use the former here can avoid
some
> > confusions.
> 
> Here abs(divisor) is not-power-of-two. divisor could be negative.
> 
>
http://codereview.chromium.org/10382033/diff/16002/test/mjsunit/math-floor-of...
> File test/mjsunit/math-floor-of-div.js (right):
> 
>
http://codereview.chromium.org/10382033/diff/16002/test/mjsunit/math-floor-of...
> test/mjsunit/math-floor-of-div.js:217: 
> On 2012/06/20 12:19:42, Yang wrote:
> > Please create a new test file called math-floor-of-div-minus-zero.js, and
add
> it
> > to mjsunit.status so that it is skipped on ARM and MIPS.
> 
> Done.

I see. LGTM. I'll land this CL. Thanks for sticking with me.

Powered by Google App Engine
This is Rietveld 408576698