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

Side by Side Diff: src/base/bits.h

Issue 1952843002: Create TimeBase for time related classes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « no previous file | src/base/bits.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_BASE_BITS_H_ 5 #ifndef V8_BASE_BITS_H_
6 #define V8_BASE_BITS_H_ 6 #define V8_BASE_BITS_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include "src/base/macros.h" 9 #include "src/base/macros.h"
10 #if V8_CC_MSVC 10 #if V8_CC_MSVC
11 #include <intrin.h> 11 #include <intrin.h>
12 #endif 12 #endif
13 #if V8_OS_WIN32 13 #if V8_OS_WIN32
14 #include "src/base/win32-headers.h" 14 #include "src/base/win32-headers.h"
15 #endif 15 #endif
16 16
17 namespace v8 { 17 namespace v8 {
18 namespace base { 18 namespace base {
19
20 namespace internal {
jochen (gone - plz use gerrit) 2016/05/06 09:43:02 safe_math.h has using internal::CheckedNumeric in
lpy 2016/05/06 17:23:23 It's used in the declaration of FromCheckedNumeric
21 template <typename T>
22 class CheckedNumeric;
23 }
24
19 namespace bits { 25 namespace bits {
20 26
21 // CountPopulation32(value) returns the number of bits set in |value|. 27 // CountPopulation32(value) returns the number of bits set in |value|.
22 inline unsigned CountPopulation32(uint32_t value) { 28 inline unsigned CountPopulation32(uint32_t value) {
23 #if V8_HAS_BUILTIN_POPCOUNT 29 #if V8_HAS_BUILTIN_POPCOUNT
24 return __builtin_popcount(value); 30 return __builtin_popcount(value);
25 #else 31 #else
26 value = ((value >> 1) & 0x55555555) + (value & 0x55555555); 32 value = ((value >> 1) & 0x55555555) + (value & 0x55555555);
27 value = ((value >> 2) & 0x33333333) + (value & 0x33333333); 33 value = ((value >> 2) & 0x33333333) + (value & 0x33333333);
28 value = ((value >> 4) & 0x0f0f0f0f) + (value & 0x0f0f0f0f); 34 value = ((value >> 4) & 0x0f0f0f0f) + (value & 0x0f0f0f0f);
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 return rhs ? lhs / rhs : 0u; 295 return rhs ? lhs / rhs : 0u;
290 } 296 }
291 297
292 298
293 // UnsignedMod32(lhs, rhs) divides |lhs| by |rhs| and returns the remainder 299 // UnsignedMod32(lhs, rhs) divides |lhs| by |rhs| and returns the remainder
294 // truncated to uint32. If |rhs| is zero, then zero is returned. 300 // truncated to uint32. If |rhs| is zero, then zero is returned.
295 inline uint32_t UnsignedMod32(uint32_t lhs, uint32_t rhs) { 301 inline uint32_t UnsignedMod32(uint32_t lhs, uint32_t rhs) {
296 return rhs ? lhs % rhs : 0u; 302 return rhs ? lhs % rhs : 0u;
297 } 303 }
298 304
305
306 // Clamp |value| on overflow and underflow conditions.
307 int64_t FromCheckedNumeric(const internal::CheckedNumeric<int64_t> value);
308
309
310 // SignedSaturatedAdd64(lhs, rhs) adds |lhs| and |rhs|,
311 // checks and returns the result.
312 int64_t SignedSaturatedAdd64(int64_t lhs, int64_t rhs);
313
314
315 // SignedSaturatedSub64(lhs, rhs) substracts |lhs| by |rhs|,
316 // checks and returns the result.
317 int64_t SignedSaturatedSub64(int64_t lhs, int64_t rhs);
318
319
299 } // namespace bits 320 } // namespace bits
300 } // namespace base 321 } // namespace base
301 } // namespace v8 322 } // namespace v8
302 323
303 #endif // V8_BASE_BITS_H_ 324 #endif // V8_BASE_BITS_H_
OLDNEW
« no previous file with comments | « no previous file | src/base/bits.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698