1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/src/misc/prlog2.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,27 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "prbit.h" 1.10 + 1.11 +/* 1.12 +** Compute the log of the least power of 2 greater than or equal to n 1.13 +*/ 1.14 +PR_IMPLEMENT(PRIntn) PR_CeilingLog2(PRUint32 n) 1.15 +{ 1.16 + PRIntn log2; 1.17 + PR_CEILING_LOG2(log2, n); 1.18 + return log2; 1.19 +} 1.20 + 1.21 +/* 1.22 +** Compute the log of the greatest power of 2 less than or equal to n. 1.23 +** This really just finds the highest set bit in the word. 1.24 +*/ 1.25 +PR_IMPLEMENT(PRIntn) PR_FloorLog2(PRUint32 n) 1.26 +{ 1.27 + PRIntn log2; 1.28 + PR_FLOOR_LOG2(log2, n); 1.29 + return log2; 1.30 +}