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

Unified Diff: src/assembler.cc

Issue 190383002: Handle non-power-of-2 divisors in division-like operations (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/assembler.h ('k') | src/ia32/lithium-codegen-ia32.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/assembler.cc
diff --git a/src/assembler.cc b/src/assembler.cc
index d51264dca9f22dcad218a4ca328a70a800580e7c..535b4befa4ce632cf99ebb0789e6497d7672832d 100644
--- a/src/assembler.cc
+++ b/src/assembler.cc
@@ -1593,4 +1593,37 @@ bool PositionsRecorder::WriteRecordedPositions() {
return written;
}
+
+MultiplierAndShift::MultiplierAndShift(int32_t d) {
+ ASSERT(d <= -2 || 2 <= d);
+ const uint32_t two31 = 0x80000000;
+ uint32_t ad = Abs(d);
+ uint32_t t = two31 + (uint32_t(d) >> 31);
+ uint32_t anc = t - 1 - t % ad; // Absolute value of nc.
+ int32_t p = 31; // Init. p.
+ uint32_t q1 = two31 / anc; // Init. q1 = 2**p/|nc|.
+ uint32_t r1 = two31 - q1 * anc; // Init. r1 = rem(2**p, |nc|).
+ uint32_t q2 = two31 / ad; // Init. q2 = 2**p/|d|.
+ uint32_t r2 = two31 - q2 * ad; // Init. r2 = rem(2**p, |d|).
+ uint32_t delta;
+ do {
+ p++;
+ q1 *= 2; // Update q1 = 2**p/|nc|.
+ r1 *= 2; // Update r1 = rem(2**p, |nc|).
+ if (r1 >= anc) { // Must be an unsigned comparison here.
+ q1++;
+ r1 = r1 - anc;
+ }
+ q2 *= 2; // Update q2 = 2**p/|d|.
+ r2 *= 2; // Update r2 = rem(2**p, |d|).
+ if (r2 >= ad) { // Must be an unsigned comparison here.
+ q2++;
+ r2 = r2 - ad;
+ }
+ delta = ad - r2;
+ } while (q1 < delta || (q1 == delta && r1 == 0));
+ multiplier_ = (d < 0) ? -(q2 + 1) : (q2 + 1);
+ shift_ = p - 32;
+}
+
} } // namespace v8::internal
« no previous file with comments | « src/assembler.h ('k') | src/ia32/lithium-codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698