Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!decwrl!granite!jensen From: jensen@granite.dec.com (Paul Jensen) Newsgroups: comp.arch Subject: Re: Endian reversing MOVEs Message-ID: <397@granite.dec.com> Date: 9 Feb 89 00:46:28 GMT References: <759@atanasoff.cs.iastate.edu> <772@atanasoff.cs.iastate.edu> Reply-To: jensen@granite.UUCP (Paul Jensen) Organization: DEC Workstation Systems Engineering, Palo Alto, CA Lines: 46 In article <772@atanasoff.cs.iastate.edu> hascall@atanasoff.cs.iastate.edu (John Hascall) writes: >In article jk3k+@andrew.cmu.edu (Joe Keane) writes: >>John Hascall writes: >>> ; >>> ; Move and Reverse Endian-ness Longword >>> ; > [....] >>That's 11 memory references for something which has nothing to do with memory. >>It only takes 6 instructions (0 memory references) on the RT. > > Well, if you have a better method, then by all means post it. > > BTW, I could do it in less than 11, if I assumed somethings about > the addressing mode of the operands and/or the availability of > a register to work in, but for my situation I neeeded a completely > general method. > > John Hascall I thought I would never write VAX macro again, especially in the context of a subject to which I am utterly indifferent (or agnostic, at any rate). However... if your machine includes rotate instructions, you can do a little better than directly moving the bytes. Rotating by half the word size swaps the upper and lower halves. Rotating a longword by +/- 8 bits moves 2 of the 4 bytes into the correct position. In the context of the VAX, you can save one instruction (while preserving the semantics of your macro) with something like pushl src rotl $8, src, -(sp) movb 4(sp),3(sp) movb 6(sp),1(sp) movl (sp)+,dst tstl (sp)+ I am not certain that one rotl is faster than 2 movb's, but I suspect it is. (The best thing about the endian debate is that it will encourage people to read "Gulliver's Travels", one of the funniest (& most vicious) books ever written.) -- /Paul Jensen Digital Equipment Corp. Palo Alto, CA