Mail Archives: djgpp/1999/08/14/05:46:54
Well ... Looking at it again then a modulo 077 (= 0x3f) could be
accompliced by using '&' instead.
Thus the line
return (int) (((y + (y >> 3)) & 030707070707) & 077);
should do the same without using a potential slow mod operator.
Kurt Alstrup
Klaas wrote:
> 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
- Raw text -