Commit:8b2dd20c6c68f54047b748c84a2444c1125e36c6 (browse)
Parent:b79711a757fe2247128e0524c6ae6da0c23f616a
Author:qwx <qwx@sciops.net>
Date:Fri Oct 23 02:21:43 CES 2020
Message:
add bitwise round up to next power of 2

asif.h => asif.h
@@ -16,6 +16,7 @@
 void	vinsert(VArray*, char*);
 VArray*	valloc(ulong, int);
 
+u32int	next32pow2(u32int);
 int	lsb64(uvlong);
 int	msb64(uvlong);
 

bit.c => bit.c
@@ -2,6 +2,19 @@
 #include <libc.h>
 #include "asif.h"
 
+/* 32bit round up to next power of 2 */
+u32int
+next32pow2(u32int v)
+{
+	v--;
+	v |= v >> 1;
+	v |= v >> 2;
+	v |= v >> 4;
+	v |= v >> 8;
+	v |= v >> 16;
+	return v + 1;
+}
+
 /* find least significant set bit in 64bit integers */
 int
 lsb64(uvlong v)