xref: /netbsd-src/external/bsd/ipf/dist/lib/count6bits.c (revision 13885a665959c62f13a82b3caedf986eaa17aa31)
1*13885a66Sdarrenr /*	$NetBSD: count6bits.c,v 1.2 2012/07/22 14:27:36 darrenr Exp $	*/
2bc4097aaSchristos 
3bc4097aaSchristos /*
4c9d5dc6cSdarrenr  * Copyright (C) 2012 by Darren Reed.
5bc4097aaSchristos  *
6bc4097aaSchristos  * See the IPFILTER.LICENCE file for details on licencing.
7bc4097aaSchristos  *
8*13885a66Sdarrenr  * Id: count6bits.c,v 1.1.1.2 2012/07/22 13:44:38 darrenr Exp $
9bc4097aaSchristos  */
10bc4097aaSchristos 
11bc4097aaSchristos #include "ipf.h"
12bc4097aaSchristos 
13bc4097aaSchristos 
count6bits(msk)14bc4097aaSchristos int count6bits(msk)
15bc4097aaSchristos 	u_32_t *msk;
16bc4097aaSchristos {
17bc4097aaSchristos 	int i = 0, k;
18bc4097aaSchristos 	u_32_t j;
19bc4097aaSchristos 
20bc4097aaSchristos 	for (k = 3; k >= 0; k--)
21bc4097aaSchristos 		if (msk[k] == 0xffffffff)
22bc4097aaSchristos 			i += 32;
23bc4097aaSchristos 		else {
24bc4097aaSchristos 			for (j = msk[k]; j; j <<= 1)
25bc4097aaSchristos 				if (j & 0x80000000)
26bc4097aaSchristos 					i++;
27bc4097aaSchristos 		}
28bc4097aaSchristos 	return i;
29bc4097aaSchristos }
30