Add rounddown_pow_of_two.

This commit is contained in:
riastradh 2014-08-06 14:05:08 +00:00
parent 7d1de5ea18
commit 6727e543c7

View File

@ -1,4 +1,4 @@
/* $NetBSD: log2.h,v 1.4 2014/07/16 20:59:58 riastradh Exp $ */
/* $NetBSD: log2.h,v 1.5 2014/08/06 14:05:08 riastradh Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@ -58,6 +58,14 @@ roundup_pow_of_two(unsigned long n)
return (n + 1);
}
static inline unsigned long
rounddown_pow_of_two(unsigned long n)
{
/* XXX fls64 is not fls_ulong, but it'll do for now. */
return (1UL << (fls64(n) - 1));
}
static inline unsigned
order_base_2(unsigned long n)
{