1994-07-07 - Re: Counting bits

Header Data

From: gtoal@an-teallach.com (Graham Toal)
To: cypherpunks@toad.com
Message Hash: 81d4348e6eedc10243c414d33b63d6f1e0fc94165f2cdc788629f81907a0cd20
Message ID: <199407071323.OAA05688@an-teallach.com>
Reply To: N/A
UTC Datetime: 1994-07-07 13:24:29 UTC
Raw Date: Thu, 7 Jul 94 06:24:29 PDT

Raw message

From: gtoal@an-teallach.com (Graham Toal)
Date: Thu, 7 Jul 94 06:24:29 PDT
To: cypherpunks@toad.com
Subject: Re: Counting bits
Message-ID: <199407071323.OAA05688@an-teallach.com>
MIME-Version: 1.0
Content-Type: text/plain


	Why bother when you can simply do an eight line function?

	int bitcount(char b)
	{
	register int retval=0;

	 if (a & 1) retval++;
	 if (a & 2) retval++;
	 if (a & 4) retval++;
	 if (a & 8) retval++;
	 if (a & 16) retval++;
	 if (a & 32) retval++;
	 if (a & 64) retval++;
	 if (a & 128) retval++; 

	return retval;
	}

There's a man who has never had to code a critical inner-loop.

When you're exhaustively testing keyspaces, or getting hard crypto
to run at lan speeds, sometimes every cycle is critical.  If the function
above is in the main inner loop (say 80% of the CPU time as gleaned
from a profile utility), the optimisations people suggested will
speed your program up by a factor of 10.  This is the one time
that bit-twiddling optimisations are worthwhile.  (Mostly they're
irrelevant and just posturing by smart-ass kiddies...)

G





Thread