| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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 // This file defines some bit utilities. | 5 // This file defines some bit utilities. |
| 6 | 6 |
| 7 #ifndef BASE_BITS_H_ | 7 #ifndef BASE_BITS_H_ |
| 8 #define BASE_BITS_H_ | 8 #define BASE_BITS_H_ |
| 9 #pragma once | |
| 10 | 9 |
| 11 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 12 #include "base/logging.h" | 11 #include "base/logging.h" |
| 13 | 12 |
| 14 namespace base { | 13 namespace base { |
| 15 namespace bits { | 14 namespace bits { |
| 16 | 15 |
| 17 // Returns the integer i such as 2^i <= n < 2^(i+1) | 16 // Returns the integer i such as 2^i <= n < 2^(i+1) |
| 18 inline int Log2Floor(uint32 n) { | 17 inline int Log2Floor(uint32 n) { |
| 19 if (n == 0) | 18 if (n == 0) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 39 } else { | 38 } else { |
| 40 // Log2Floor returns -1 for 0, so the following works correctly for n=1. | 39 // Log2Floor returns -1 for 0, so the following works correctly for n=1. |
| 41 return 1 + Log2Floor(n - 1); | 40 return 1 + Log2Floor(n - 1); |
| 42 } | 41 } |
| 43 } | 42 } |
| 44 | 43 |
| 45 } // namespace bits | 44 } // namespace bits |
| 46 } // namespace base | 45 } // namespace base |
| 47 | 46 |
| 48 #endif // BASE_BITS_H_ | 47 #endif // BASE_BITS_H_ |
| OLD | NEW |