Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!nosc!humu!uhccux!mikem From: mikem@uhccux.uhcc.hawaii.edu (Mike Morton) Newsgroups: comp.sys.m68k Subject: Re: addq.w #n,sp and a pop quiz Keywords: C asm addq Message-ID: <2833@uhccux.uhcc.hawaii.edu> Date: 14 Dec 88 19:33:31 GMT References: <5005@bsu-cs.UUCP> <5460@cbmvax.UUCP> <1100@ncar.ucar.edu> <196@xpiinc.UU.NET> Distribution: na Organization: University of Hawaii Lines: 29 Tom Talpey is right that the CMPM.B does more memory access. But it *is* the shortest way, and fewest cycles. I've never actually used this trick, so I don't know if it's empirically faster. [I use a Mac Plus, which has funny timing anyway...] I also bow to Tom's point that the Carry and eXtend bits must be the same for "SUBX.B Dn,Dn" to replace "SCS". Incidentally, I got this trick from an article Bill Gates wrote ca 1975 on 8080 (?) hacking, reprinted in "Programmers at Work". Counting the cycles in Tom's Max(Dx,Dy) as a function of word or long operands and whether the branch takes/doesn't. word long mov Dx,result 4 4 cmp Dx,Dy 4 6 bles .+4 10/8 (taken/not) mov Dy,result 4 4 18/20 20/22 The Superoptimizer's solution has no branches at all, so its time is constant at 16 cycles for word operands (small win) or 32 for longword (big loss). Anyone care to solve the 4-instruction signum function? -- Mike Morton // P.O. Box 11378, Honolulu, HI 96828, (808) 676-6966 HST Internet: msm@ceta.ics.hawaii.edu (anagrams): Mr. Machine Tool; Ethical Mormon; Chosen Immortal; etc.