From owner-freebsd-arch@FreeBSD.ORG Thu Nov 15 05:04:07 2012 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 1A8E1F65; Thu, 15 Nov 2012 05:04:07 +0000 (UTC) (envelope-from julian@freebsd.org) Received: from vps1.elischer.org (vps1.elischer.org [204.109.63.16]) by mx1.freebsd.org (Postfix) with ESMTP id C91158FC0C; Thu, 15 Nov 2012 05:04:06 +0000 (UTC) Received: from JRE-MBP-2.local (c-50-143-149-146.hsd1.ca.comcast.net [50.143.149.146]) (authenticated bits=0) by vps1.elischer.org (8.14.5/8.14.5) with ESMTP id qAF53xNA008119 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Wed, 14 Nov 2012 21:04:00 -0800 (PST) (envelope-from julian@freebsd.org) Message-ID: <50A477BA.4020700@freebsd.org> Date: Wed, 14 Nov 2012 21:03:54 -0800 From: Julian Elischer User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:16.0) Gecko/20121026 Thunderbird/16.0.2 MIME-Version: 1.0 To: Jung-uk Kim Subject: Re: [RFC] Generic population count function References: <50A43B52.8030102@FreeBSD.org> In-Reply-To: <50A43B52.8030102@FreeBSD.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: freebsd-arch@freebsd.org X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Nov 2012 05:04:07 -0000 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"