Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!ucsd!nosc!humu!uhccux!cs661s01 From: cs661s01@uhccux.UUCP (Cs661s01) Newsgroups: comp.sys.m68k Subject: Re: 68000 Tricks Message-ID: <1629@uhccux.UUCP> Date: 3 Mar 88 05:36:27 GMT References: <326@rose3.rosemount.com> <1200@microsoft.UUCP> Reply-To: cs661s01@uhccux.UUCP (Cs661s01) Distribution: na Organization: U. of Hawaii, Manoa (Honolulu) Lines: 30 Keywords: 68000 Tricks Speed bitcount strlen Odd that Kent Schnaith would bring up bit-counting. I spent part of the weekend doing a bit-counter. Of course, I cheated and used a 64K-byte table, so there's not much point in including the code here. In Kent's strlen, shouldn't that "add.w #$ffff, d0" be just "subq.w #1, d0"? And while we're shaving cycles, doesn't neg.w d0 subq.w #1, d0 just become "not.w d0"? (Take the hint from his comment "d0 = $FFFF - d0"). Here's a puzzle, unsolved as far as I know -- I need a fast way to compare two bitmaps, to see which has more bits set. Is there a faster way than counting each one's bits and comparing? If it helps, the two maps have no 1's in common. (This is to evaluate an endgame in Othello.) A 68000 solution is preferable, but anything is interesting... Jan Gray's strlen seems preferable, especially since it looks right for strings longer than 64K. Has it actually been timed on an '020? Seems like a 7-instruction loop for every four bytes isn't ALL that much better than a 2-instruction loop for every byte... I like the simpler solution adapted to just compare pointers, so the loop is just: loop: tst.b (An)+ bne.s loop ...and then the final pointer has the initial one subtracted (probably give or take 1). Good especially if strings are likely to be short. -- Mike Morton // P.O. Box 11378, Honolulu, HI 96828, (808) 456-8455 HST Internet: msm@uhmanoa.ics.hawaii.edu UUCP: {ihnp4,uunet,dcdwest,ucbvax}!ucsd!nosc!uhmanoa!msm BITnet: msm%uhmanoa.ics.hawaii.edu@uhccux (anagrams): Mr. Machine Tool; Ethical Mormon; Chosen Immortal; etc.