Home | History | Annotate | Line # | Download | only in string
      1 /*
      2  * Written by J.T. Conklin <jtc (at) NetBSD.org>.
      3  * Public domain.
      4  */
      5 
      6 #include <machine/asm.h>
      7 
      8 #if defined(LIBC_SCCS)
      9 	RCSID("$NetBSD: swab.S,v 1.4 2014/05/22 15:01:57 uebayasi Exp $")
     10 #endif
     11 
     12 #define LOAD_SWAP_STORE_WORD \
     13 	lodsw	; \
     14 	xchgb	%al,%ah ; \
     15 	stosw
     16 
     17 ENTRY(swab)
     18 	xchgq	%rdi,%rsi
     19 	cld				# set direction forward
     20 
     21 	shrq	$1,%rdx
     22 	testq	$7,%rdx			# copy first group of 1 to 7 words
     23 	jz	L2			# while swapping alternate bytes.
     24 L1:	lodsw
     25 	rorw	$8,%ax
     26 	stosw
     27 	decq	%rdx
     28 	testq	$7,%rdx
     29 	jnz	L1
     30 
     31 L2:	shrq	$3,%rdx			# copy remainder 8 words at a time
     32 	jz	L4			# while swapping alternate bytes.
     33 L3:
     34 	LOAD_SWAP_STORE_WORD
     35 	LOAD_SWAP_STORE_WORD
     36 	LOAD_SWAP_STORE_WORD
     37 	LOAD_SWAP_STORE_WORD
     38 	LOAD_SWAP_STORE_WORD
     39 	LOAD_SWAP_STORE_WORD
     40 	LOAD_SWAP_STORE_WORD
     41 	LOAD_SWAP_STORE_WORD
     42 
     43 	decq	%rdx
     44 	jnz	L3
     45 L4:
     46 	ret
     47 END(swab)
     48