Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 14 Nov 2012 21:03:54 -0800
From:      Julian Elischer <julian@freebsd.org>
To:        Jung-uk Kim <jkim@freebsd.org>
Cc:        freebsd-arch@freebsd.org
Subject:   Re: [RFC] Generic population count function
Message-ID:  <50A477BA.4020700@freebsd.org>
In-Reply-To: <50A43B52.8030102@FreeBSD.org>
References:  <50A43B52.8030102@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-arch
> To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?50A477BA.4020700>