Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!waikato.ac.nz!ldo From: ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) Newsgroups: comp.arch Subject: Re: Loop instructions Message-ID: <1991Apr24.174259.3541@waikato.ac.nz> Date: 24 Apr 91 17:42:59 +1200 References: <1991Apr16.152438.3445@waikato.ac.nz> <12739@pt.cs.cmu.edu> <1991Apr21.210031.16749@leland.Stanford.EDU> Organization: University of Waikato, Hamilton, New Zealand Lines: 29 In article <1991Apr21.210031.16749@leland.Stanford.EDU>, dhinds@elaine18.Stanford.EDU (David Hinds) asks: "I'm not familiar with the 68000 instruction set, but couldn't [DBRA] be adapted to 32-bit counts by just splitting the count into upper and lower half-words and using a nested pair of 16-bit loops? This would have minimal overhead - a few instructions in loop setup - but would have essentially the same performance as the 16 bit count for long loops." Yup, and here's how you do it: ; loop initialization, including loading 32-bit ; unsigned count into d0, comes here bra.s @7 ; enter loop at bottom, as usual @1 swap d0 @2 ; ... body of loop @7 dbra d0, @2 swap d0 dbra d0, @1 My instruction timings indicate that DBRA is preferable to a simple SUBQ/BNE on the 68000, 68010, 68020 and 68030. This is because DBRA is faster when the branch is taken. Lawrence D'Oliveiro fone: +64-71-562-889 Computer Services Dept fax: +64-71-384-066 University of Waikato electric mail: ldo@waikato.ac.nz Hamilton, New Zealand 37^ 47' 26" S, 175^ 19' 7" E, GMT+12:00 MADAME MACLUHAN, fortune-telling and back rubs. "The medium is the massage."