12fe8fb19SBen Gras/* 22fe8fb19SBen Gras * Written by J.T. Conklin <jtc@NetBSD.org>. 32fe8fb19SBen Gras * Public domain. 42fe8fb19SBen Gras */ 52fe8fb19SBen Gras 62fe8fb19SBen Gras#include <machine/asm.h> 72fe8fb19SBen Gras 82fe8fb19SBen Gras#if defined(LIBC_SCCS) 9*0a6a1f1dSLionel Sambuc RCSID("$NetBSD: swab.S,v 1.4 2014/05/22 15:01:57 uebayasi Exp $") 102fe8fb19SBen Gras#endif 112fe8fb19SBen Gras 122fe8fb19SBen Gras#define LOAD_SWAP_STORE_WORD \ 132fe8fb19SBen Gras lodsw ; \ 142fe8fb19SBen Gras xchgb %al,%ah ; \ 152fe8fb19SBen Gras stosw 162fe8fb19SBen Gras 172fe8fb19SBen GrasENTRY(swab) 182fe8fb19SBen Gras xchgq %rdi,%rsi 192fe8fb19SBen Gras cld # set direction forward 202fe8fb19SBen Gras 212fe8fb19SBen Gras shrq $1,%rdx 222fe8fb19SBen Gras testq $7,%rdx # copy first group of 1 to 7 words 232fe8fb19SBen Gras jz L2 # while swapping alternate bytes. 242fe8fb19SBen GrasL1: lodsw 252fe8fb19SBen Gras rorw $8,%ax 262fe8fb19SBen Gras stosw 272fe8fb19SBen Gras decq %rdx 282fe8fb19SBen Gras testq $7,%rdx 292fe8fb19SBen Gras jnz L1 302fe8fb19SBen Gras 312fe8fb19SBen GrasL2: shrq $3,%rdx # copy remainder 8 words at a time 322fe8fb19SBen Gras jz L4 # while swapping alternate bytes. 332fe8fb19SBen GrasL3: 342fe8fb19SBen Gras LOAD_SWAP_STORE_WORD 352fe8fb19SBen Gras LOAD_SWAP_STORE_WORD 362fe8fb19SBen Gras LOAD_SWAP_STORE_WORD 372fe8fb19SBen Gras LOAD_SWAP_STORE_WORD 382fe8fb19SBen Gras LOAD_SWAP_STORE_WORD 392fe8fb19SBen Gras LOAD_SWAP_STORE_WORD 402fe8fb19SBen Gras LOAD_SWAP_STORE_WORD 412fe8fb19SBen Gras LOAD_SWAP_STORE_WORD 422fe8fb19SBen Gras 432fe8fb19SBen Gras decq %rdx 442fe8fb19SBen Gras jnz L3 452fe8fb19SBen GrasL4: 462fe8fb19SBen Gras ret 47*0a6a1f1dSLionel SambucEND(swab) 48