| // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| // This file defines some bit utilities. |
| #include "base/basictypes.h" |
| #include "base/logging.h" |
| // Returns the integer i such as 2^i <= n < 2^(i+1) |
| inline int Log2Floor(uint32 n) { |
| for (int i = 4; i >= 0; --i) { |
| uint32 x = value >> shift; |
| // Returns the integer i such as 2^(i-1) < n <= 2^i |
| inline int Log2Ceiling(uint32 n) { |
| // Log2Floor returns -1 for 0, so the following works correctly for n=1. |
| return 1 + Log2Floor(n - 1); |