www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/08/13/19:03:48

Message-Id: <37B48ABE.110D2C13@intel.com>
Date: Fri, 13 Aug 1999 23:14:38 +0200
From: Kurt Alstrup <kurt DOT alstrup AT intel DOT com>
Organization: Intel Denmark Aps
X-Mailer: Mozilla 4.51 [en] (WinNT; U)
X-Accept-Language: en
Mime-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: Bit counting?
References: <37B45836 DOT EAD7C82D AT swipnet DOT se>
Reply-To: djgpp AT delorie DOT com

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

PS. This is the 2nd reply, the 1st one came back with the note

   ----- The following addresses had delivery problems -----
<djgpp AT delorie DOT com>  (unrecoverable error)

   ----- Transcript of session follows -----
... while talking to delorie.com.:
>>> DATA
<<< 500 Hey, offensive language ("d|a|m|n") is not allowed.
<dj AT delorie DOT com>
554 <djgpp AT delorie DOT com>... Remote protocol error

   ----- Original message follows -----

As I just replied to mail message I originally got from the djgpp
mailing list I fail to
understand why the original mail got through in the first place.
Secondly I disagree
that it was offensive languange, propably strong, but offensive;
definitely no.


Anders David Skarin wrote:

> Hi,
>
> What is the fastest way (or just a <<CENSORED, d|a|m|n>> fast way) to
> count the nr of binary 1's in a byte/word/dword ?
>
> Is there any assembler instruction for this ?
> (there should be, considering the nr of instructions
> in the sisc processors)
>
> Thanks!
>
> David Skarin

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019