aboutsummaryrefslogtreecommitdiff
path: root/deps/v8/src/base/division-by-constant.h
diff options
context:
space:
mode:
authorFedor Indutny <fedor@indutny.com>2014-10-10 14:49:02 +0400
committerFedor Indutny <fedor@indutny.com>2014-10-10 14:49:02 +0400
commit6bcea4ff932144a5fd02affefd45164fbf471e67 (patch)
treea8e078c679b12f0daebe10ed254239cb0d79e146 /deps/v8/src/base/division-by-constant.h
parent4fae2356d105e394115188a814097c4a95ae0c5d (diff)
downloadandroid-node-v8-6bcea4ff932144a5fd02affefd45164fbf471e67.tar.gz
android-node-v8-6bcea4ff932144a5fd02affefd45164fbf471e67.tar.bz2
android-node-v8-6bcea4ff932144a5fd02affefd45164fbf471e67.zip
deps: update v8 to 3.29.93.1
Diffstat (limited to 'deps/v8/src/base/division-by-constant.h')
-rw-r--r--deps/v8/src/base/division-by-constant.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/deps/v8/src/base/division-by-constant.h b/deps/v8/src/base/division-by-constant.h
new file mode 100644
index 0000000000..02e7e14b01
--- /dev/null
+++ b/deps/v8/src/base/division-by-constant.h
@@ -0,0 +1,45 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef V8_BASE_DIVISION_BY_CONSTANT_H_
+#define V8_BASE_DIVISION_BY_CONSTANT_H_
+
+namespace v8 {
+namespace base {
+
+// ----------------------------------------------------------------------------
+
+// The magic numbers for division via multiplication, see Warren's "Hacker's
+// Delight", chapter 10. The template parameter must be one of the unsigned
+// integral types.
+template <class T>
+struct MagicNumbersForDivision {
+ MagicNumbersForDivision(T m, unsigned s, bool a)
+ : multiplier(m), shift(s), add(a) {}
+ bool operator==(const MagicNumbersForDivision& rhs) const;
+
+ T multiplier;
+ unsigned shift;
+ bool add;
+};
+
+
+// Calculate the multiplier and shift for signed division via multiplication.
+// The divisor must not be -1, 0 or 1 when interpreted as a signed value.
+template <class T>
+MagicNumbersForDivision<T> SignedDivisionByConstant(T d);
+
+
+// Calculate the multiplier and shift for unsigned division via multiplication,
+// see Warren's "Hacker's Delight", chapter 10. The divisor must not be 0 and
+// leading_zeros can be used to speed up the calculation if the given number of
+// upper bits of the dividend value are known to be zero.
+template <class T>
+MagicNumbersForDivision<T> UnsignedDivisionByConstant(
+ T d, unsigned leading_zeros = 0);
+
+} // namespace base
+} // namespace v8
+
+#endif // V8_BASE_DIVISION_BY_CONSTANT_H_