Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!amdahl!oliveb!Ozona!chase From: chase@Ozona.orc.olivetti.com (David Chase) Newsgroups: comp.arch Subject: Re: Endian reversing MOVEs Message-ID: <37562@oliveb.olivetti.com> Date: 9 Feb 89 07:49:26 GMT References: <759@atanasoff.cs.iastate.edu> <772@atanasoff.cs.iastate.edu> <397@granite.dec.com> Sender: news@oliveb.olivetti.com Reply-To: chase@Ozona.UUCP (David Chase) Organization: Olivetti Research Center, Menlo Park, CA Lines: 36 Didn't we have this discussion just a few months ago already? anyhow, someone writes: >> Well, if you have a better method, then by all means post it. and, authored by some unknown programmer with Acorn, is the 4 instruction, no memory reference endian reversing code sequence: input is in R0, R0 = a,b,c,d r1 := ~ (0xFF << 8) // r1 := F,F,0,F r2 := r0 ^ (r0 ROTR 16) // r2 := a,b,c,d ^ c,d,a,b = a^c,b^d,a^c,b^d r2 := r1 & (r2 >> 8) // r2 := F,F,0,F & 0,a^c,b^d,a^c = 0,a^c,0,a^c r0 := r2 ^ (r0 ROTR 8) // r0 := 0,a^c,0,a^c ^ d,a,b,c = d,c,b,a Each of these lines translates into one Acorn RISC Machine instruction, and each of these instructions executes in one "cycle" (I don't know what they do with their clock, but the rotates don't slow it down). I would expect similar tricks to be possible on the HP Spectrum, since I understand that it also has shift-and-op instructions. (They're great for generating fast constant multiplication sequences, but I KNOW we've already had that discussed here.) Note that the first instruction need not be repeated if you are swapping several registers; thus, it is possible to swap bytes in 12 registers in 37 instructions (of course, then you wait all day to get the registers in and out of memory). I guess I should ask: what else are shift-and-op style instructions good for? So far I have 1) byte swapping 2) fast multiplication by constants David