delorie.com/archives/browse.cgi | search |
Message-ID: | <37B4D8BC.6465@ns.sympatico.ca> |
From: | Klaas <klaas AT ns DOT sympatico DOT ca> |
Organization: | N/A |
X-Mailer: | Mozilla 3.04 (Win95; I) |
MIME-Version: | 1.0 |
Newsgroups: | comp.os.msdos.djgpp |
Subject: | Re: Bit counting? |
References: | <37B45836 DOT EAD7C82D AT swipnet DOT se> <37B48ABE DOT 110D2C13 AT intel DOT com> |
Lines: | 27 |
Date: | Fri, 13 Aug 1999 23:47:24 -0300 |
NNTP-Posting-Host: | 142.177.60.2 |
X-Trace: | sapphire.mtt.net 934598824 142.177.60.2 (Fri, 13 Aug 1999 23:47:04 ADT) |
NNTP-Posting-Date: | Fri, 13 Aug 1999 23:47:04 ADT |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Reply-To: | djgpp AT delorie DOT com |
Kurt Alstrup wrote: > > Try this little function, I guess it may gain if written in assembly > though .. > > /* > * Ones > * > * This magic counts the number of bits in one longword > */ > > int > Ones(unsigned long mask) > { > register unsigned long y; > > y = (mask >> 1) & 033333333333; > y = mask - y - ((y >>1) & 033333333333); > return (int) (((y + (y >> 3)) & 030707070707) % 077); > } > > Regards, > Kurt Alstrup Doesn't the modulo make it rather slow? -Mike
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |