Chromium Code Reviews| Index: src/utils.h |
| =================================================================== |
| --- src/utils.h (revision 11193) |
| +++ src/utils.h (working copy) |
| @@ -85,6 +85,35 @@ |
| } |
| +// 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 DivMagicNumberFor6 = {0x2aaaaaab, 0}; |
| +const DivMagicNumbers DivMagicNumberFor7 = {0x92492493, 2}; |
| +const DivMagicNumbers DivMagicNumberFor9 = {0x38e38e39, 1}; |
| +const DivMagicNumbers DivMagicNumberFor10 = {0x66666667, 2}; |
| +const DivMagicNumbers DivMagicNumberFor11 = {0x2e8ba2e9, 1}; |
| +const DivMagicNumbers DivMagicNumberFor12 = {0x2aaaaaab, 1}; |
| +const DivMagicNumbers DivMagicNumberFor25 = {0x51eb851f, 3}; |
| +const DivMagicNumbers DivMagicNumberFor125 = {0x10624dd3, 3}; |
| +const DivMagicNumbers DivMagicNumberFor625 = {0x68db8bad, 8}; |
|
alexeif
2012/04/17 16:59:28
How about adding 60, 100 and 1000? They seem to ha
Alexandre
2012/04/17 17:12:22
We can generate optimized code for numbers with an
alexeif
2012/04/17 18:30:26
Oh, I see, it has a shift anyway. Btw, why do you
Alexandre
2012/04/18 09:03:59
Fair question! I actually noticed a non-optimal pa
|
| + |
| +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. |