[RFC] Generic population count function
Julian Elischer
julian at freebsd.org
Thu Nov 15 05:04:07 UTC 2012
On 11/14/12 4:46 PM, Jung-uk Kim wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> I implemented generic population count function. Please see the
> attachment. It is also available from here:
>
> http://people.freebsd.org/~jkim/bitcount.diff
>
> The idea is to make use of CPU-supported population count instructions
> if available and the compiler supports them (i.e., clang), especially
> for larger than 32-bit data. The patch also has use cases for the new
> function (i.e., counting number of bits in IPv6 address[*]).
>
> Any objection?
there are more efficient algorithms than the one you show in bitcount.h
see the bit-twidling site:
http://graphics.stanford.edu/~seander/bithacks.html
>
> Jung-uk Kim
>
> * PS: BTW, I am not sure whether this is correct:
>
> - --- sys/netpfil/ipfw/ip_fw_table.c
> +++ sys/netpfil/ipfw/ip_fw_table.c
> @@ -720,11 +717,10 @@ dump_table_xentry_extended(struct radix_node *rn,
> switch (tbl->type) {
> #ifdef INET6
> case IPFW_TABLE_CIDR:
> - - /* Count IPv6 mask */
> - - v = (uint32_t *)&n->m.mask6.sin6_addr;
> - - for (i = 0; i < sizeof(struct in6_addr) / 4; i++, v++)
> - - xent->masklen += bitcount32(*v);
> - - memcpy(&xent->k, &n->a.addr6.sin6_addr, sizeof(struct
> in6_addr));
> + xent->masklen += bitcount(&n->m.mask6.sin6_addr,
> + sizeof(struct in6_addr));
> + memcpy(&xent->k, &n->a.addr6.sin6_addr,
> + sizeof(struct in6_addr));
> break;
> #endif
> case IPFW_TABLE_INTERFACE:
>
> Is xent->masklen initialized to a non-zero value somewhere, i.e.,
> shouldn't we just use '=' instead of '+=' here?
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2.0.19 (FreeBSD)
> Comment: Using GnuPG with Mozilla - http://www.enigmail.net/
>
> iEYEARECAAYFAlCkO1IACgkQmlay1b9qnVNzggCfW+Fri0Aj4TDDXcAoPc4SaATB
> clQAnikNhO6JVJ+Ez71cbdQV5Qy4uHam
> =r4nt
> -----END PGP SIGNATURE-----
>
>
> _______________________________________________
> freebsd-arch at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-arch
> To unsubscribe, send any mail to "freebsd-arch-unsubscribe at freebsd.org"
More information about the freebsd-arch
mailing list