Index: src/utils.h |
=================================================================== |
--- src/utils.h (revision 11426) |
+++ src/utils.h (working copy) |
@@ -85,6 +85,32 @@ |
} |
+// Magic numbers for integer division. |
+// These are kind of 2's complement reciprocal of the divisors. |
+// Details and proofs can be found in: |
+// - Hacker's Delight, Henry S. Warren, Jr. |
+// - The PowerPC Compiler Writer’s Guide |
+// and probably many others. |
+// See details in the implementation of the algorithm in |
+// lithium-codegen-arm.cc : LCodeGen::TryEmitSignedIntegerDivisionByConstant(). |
+struct DivMagicNumbers { |
+ unsigned M; |
+ unsigned s; |
+}; |
+ |
+const DivMagicNumbers InvalidDivMagicNumber= {0, 0}; |
+const DivMagicNumbers DivMagicNumberFor3 = {0x55555556, 0}; |
+const DivMagicNumbers DivMagicNumberFor5 = {0x66666667, 1}; |
+const DivMagicNumbers DivMagicNumberFor7 = {0x92492493, 2}; |
+const DivMagicNumbers DivMagicNumberFor9 = {0x38e38e39, 1}; |
+const DivMagicNumbers DivMagicNumberFor11 = {0x2e8ba2e9, 1}; |
+const DivMagicNumbers DivMagicNumberFor25 = {0x51eb851f, 3}; |
+const DivMagicNumbers DivMagicNumberFor125 = {0x10624dd3, 3}; |
+const DivMagicNumbers DivMagicNumberFor625 = {0x68db8bad, 8}; |
+ |
+const DivMagicNumbers DivMagicNumberFor(int32_t divisor); |
+ |
+ |
// The C++ standard leaves the semantics of '>>' undefined for |
// negative signed operands. Most implementations do the right thing, |
// though. |