Path: utzoo!mnetor!uunet!rosevax!rose3!kent From: kent@rose3.rosemount.com (Kent Schnaith) Newsgroups: comp.sys.m68k Subject: 68000 Tricks Message-ID: <326@rose3.rosemount.com> Date: 23 Feb 88 21:15:25 GMT Distribution: na Organization: Rosemount Inc., Burnsville, MN Lines: 57 Keywords: 68000 Tricks Speed Sounds like the beginning of a contest ? Here is my two bits, a couple of routines in a non-standard version of 68000 asm. ! ! Kent Schnaith ! Rosemount Inc. ! ...!ihnp4!rosevax!rose3!kent !** !* pop0cnt: Count 0 bits in a long. !* pop1cnt: Count 1 bits in a long. !* !* Entry - d0 = long to test !* Exit - d0 = count (word) !* Uses - d0, d1, d2 !* pop0cnt: movl d0,d1 ! d1 holds input moveq #32,d0 ! assume ALL zeros tstl d1 bras popl2 pop1cnt: movl d0,d1 moveq #32,d0 ! assume ALL ones notl d1 ! want to count 1's, not 0's bras popl2 popl1: movl d1,d2 ! mask off lowest 1 bit using subql #1,d2 ! d1 = d1 & (d1 - 1) andl d2,d1 ! thanks to Gene H. Olson popl2: dbeq d0,popl1 ! count zero's rts !** !* strlen: Find length of a 0 terminated string. !* !* Entry - a0 = string address !* Exit - d0 = length (word) !* Uses - a0, d0 !* strlen: moveq #-1,d0 ! assume a big string strl1: tstb (a0)+ ! words would be faster, less trivial dbeq d0,strl1 ! 68010 cache is nice here negw d0 ! d0 = $FFFF - d0 addw #$FFFF,d0 rts