aboutsummaryrefslogtreecommitdiff
path: root/winsup
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2022-12-20 10:19:23 +0100
committerCorinna Vinschen <corinna@vinschen.de>2022-12-20 10:19:23 +0100
commit2af7dd95671197f43fb8c2c6d30461c143d63b03 (patch)
treec980661368f0a8b4a2390433d0dd095e49a61586 /winsup
parent43743ed754727a0ab5bbe9b15068d3256791f011 (diff)
downloadnewlib-2af7dd95671197f43fb8c2c6d30461c143d63b03.zip
newlib-2af7dd95671197f43fb8c2c6d30461c143d63b03.tar.gz
newlib-2af7dd95671197f43fb8c2c6d30461c143d63b03.tar.bz2
Cygwin: x86_64: import swab.S from NetBSD
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'winsup')
-rw-r--r--winsup/cygwin/Makefile.am1
-rw-r--r--winsup/cygwin/x86_64/swab.S47
2 files changed, 48 insertions, 0 deletions
diff --git a/winsup/cygwin/Makefile.am b/winsup/cygwin/Makefile.am
index f8c249f..0200f6e 100644
--- a/winsup/cygwin/Makefile.am
+++ b/winsup/cygwin/Makefile.am
@@ -58,6 +58,7 @@ TARGET_FILES= \
x86_64/memmove.S \
x86_64/mempcpy.S \
x86_64/memset.S \
+ x86_64/swab.S \
x86_64/wmemcpy.S \
x86_64/wmemmove.S \
x86_64/wmempcpy.S
diff --git a/winsup/cygwin/x86_64/swab.S b/winsup/cygwin/x86_64/swab.S
new file mode 100644
index 0000000..ae73d11
--- /dev/null
+++ b/winsup/cygwin/x86_64/swab.S
@@ -0,0 +1,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)