Subject: Re: hton64
To: None <tv@pobox.com, current-users@NetBSD.ORG>
From: Ty Sarna <tsarna@endicor.com>
List: current-users
Date: 06/28/1997 19:28:42
In article <Pine.GSO.3.96.970628180058.9710A-100000@shell> you write:
> ; Motorola format m68k assembler variations of __swap16(), __swap32(),
> ; __swap64(), and __swapbytes().  Sorry this isn't MIT style; this is an
> ; on the spot mental compile and optimization, and I don't know MIT syntax.
> ; :>

This looks faster to me (though I haven't counted cycles and don't claim
to be a m68k genius. There may very well be an even better
implementation than this.)

__swap64:
	movl	sp@(4),d1	| get high 32 to low half reg
	rorw	#8,d1		| swap low 2 bytes
	swap	d1		| swap halves
	rorw	#8,d1		| swap low 2 bytes
	movl	sp@(8),d0	| get low 32 to high half reg
	rorw	#8,d0		| swap low 2 bytes
	swap	d0		| swap halves
	rorw	#8,d0		| swap low 2 bytes
	rts

__swap32:
	movl	sp@(4),d0	| get int32_t 
	rorw	#8,d0		| swap low 2 bytes
	swap	d0		| swap halves
	rorw	#8,d0		| swap low 2 bytes
	rts

__swap16:
	moveq	#0,d0		| zero top bits
        movw	sp@(6),d0	| get int16_t
	rorw	#8,d0		| swap bytes
	rts