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

Side by Side Diff: base/bits.h

Issue 373001: Moved bits.h from O3D to Chrome base. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 | « base/base.gyp ('k') | base/bits_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium 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 // This file defines some bit utilities.
6
7 #ifndef BASE_BITS_H_
8 #define BASE_BITS_H_
9
10 #include "base/basictypes.h"
11 #include "base/logging.h"
12
13 namespace base {
14 namespace bits {
15
16 // Returns the integer i such as 2^i <= n < 2^(i+1)
17 inline int Log2Floor(uint32 n) {
18 if (n == 0)
19 return -1;
20 int log = 0;
21 uint32 value = n;
22 for (int i = 4; i >= 0; --i) {
23 int shift = (1 << i);
24 uint32 x = value >> shift;
25 if (x != 0) {
26 value = x;
27 log += shift;
28 }
29 }
30 DCHECK_EQ(value, 1u);
31 return log;
32 }
33
34 // Returns the integer i such as 2^(i-1) < n <= 2^i
35 inline int Log2Ceiling(uint32 n) {
36 if (n == 0) {
37 return -1;
38 } else {
39 // Log2Floor returns -1 for 0, so the following works correctly for n=1.
40 return 1 + Log2Floor(n - 1);
41 }
42 }
43
44 } // namespace bits
45 } // namespace base
46
47 #endif // BASE_BITS_H_
OLDNEW
« no previous file with comments | « base/base.gyp ('k') | base/bits_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698