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

Side by Side Diff: src/base/division-by-constant.h

Issue 532003004: Generalized division via multiplication. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased Created 6 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/base/base.gyp ('k') | src/base/division-by-constant.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_BASE_DIVISION_BY_CONSTANT_H_
6 #define V8_BASE_DIVISION_BY_CONSTANT_H_
7
8 namespace v8 {
9 namespace base {
10
11 // ----------------------------------------------------------------------------
12
13 // The magic numbers for division via multiplication, see Warren's "Hacker's
14 // Delight", chapter 10. The template parameter must be one of the unsigned
15 // integral types.
16 template <class T>
17 struct MagicNumbersForDivision {
18 MagicNumbersForDivision(T m, unsigned s, bool a)
19 : multiplier(m), shift(s), add(a) {}
20 bool operator==(const MagicNumbersForDivision& rhs) const;
21
22 T multiplier;
23 unsigned shift;
24 bool add;
25 };
26
27
28 // Calculate the multiplier and shift for signed division via multiplication.
29 // The divisor must not be -1, 0 or 1 when interpreted as a signed value.
30 template <class T>
31 MagicNumbersForDivision<T> SignedDivisionByConstant(T d);
32
33
34 // Calculate the multiplier and shift for unsigned division via multiplication,
35 // see Warren's "Hacker's Delight", chapter 10. The divisor must not be 0 and
36 // leading_zeros can be used to speed up the calculation if the given number of
37 // upper bits of the dividend value are known to be zero.
38 template <class T>
39 MagicNumbersForDivision<T> UnsignedDivisionByConstant(
40 T d, unsigned leading_zeros = 0);
41
42 } // namespace base
43 } // namespace v8
44
45 #endif // V8_BASE_DIVISION_BY_CONSTANT_H_
OLDNEW
« no previous file with comments | « src/base/base.gyp ('k') | src/base/division-by-constant.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698