home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / arch / 8384 < prev    next >
Encoding:
Internet Message Format  |  1992-07-28  |  1.6 KB

  1. Path: sparky!uunet!crdgw1!rdsunx.crd.ge.com!ariel!davidsen
  2. From: davidsen@ariel.crd.GE.COM (william E Davidsen)
  3. Newsgroups: comp.arch
  4. Subject: Re: Finding which bit set in a bit-string.
  5. Keywords: Bit-counting.
  6. Message-ID: <1992Jul28.160158.23842@crd.ge.com>
  7. Date: 28 Jul 92 16:01:58 GMT
  8. References: <1992Jul27.212607.26361@infonode.ingr.com>
  9. Sender: usenet@crd.ge.com (Required for NNTP)
  10. Reply-To: davidsen@crd.ge.com (bill davidsen)
  11. Organization: GE Corporate R&D Center, Schenectady NY
  12. Lines: 25
  13. Nntp-Posting-Host: ariel.crd.ge.com
  14.  
  15. In article <1992Jul27.212607.26361@infonode.ingr.com>, aaronb@suhana.analog.ingr.com (Aaron B.) writes:
  16.  
  17. | I posted this on "comp.compression":
  18. | >Given a bit-string of any size print out the bits set starting with the
  19. | >least significant bit.
  20.  
  21.   Doing it in C, you don't want a bit by bit test, you want a branch
  22. table. A byte is too slow with a switch, so use a procedure vector:
  23.  
  24.     void (*showbits[256])();
  25.  
  26. Then write 256 procedures which each print all the bits set in one
  27. particular bit pattern. If you want offset from bit zero add it as a
  28. global variable (passing as arg is slower).
  29.  
  30.   I did a CPU emulator using this once, and it's *fast*, but complex.
  31. Much faster than any bit by bit operation. Of course you can extend this
  32. to do 16 bits at a time, or even 32 when you get your 64 bit micro with
  33. a TB of memory.
  34. -- 
  35. bill davidsen, GE Corp. R&D Center; Box 8; Schenectady NY 12345
  36.     It never ceases to amaze me that otherwise rational people, able to
  37.     understand calculus, compound interest, and the income tax form, can
  38.     continue to believe that poker is a game of chance.
  39.