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