shithub: asif

Download patch

ref: 8b2dd20c6c68f54047b748c84a2444c1125e36c6
parent: b79711a757fe2247128e0524c6ae6da0c23f616a
author: qwx <qwx@sciops.net>
date: Thu Oct 22 20:21:43 EDT 2020

add bitwise round up to next power of 2

--- a/asif.h
+++ b/asif.h
@@ -16,6 +16,7 @@
 void	vinsert(VArray*, char*);
 VArray*	valloc(ulong, int);
 
+u32int	next32pow2(u32int);
 int	lsb64(uvlong);
 int	msb64(uvlong);
 
--- a/bit.c
+++ b/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)