public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: x86_64: import swab.S from NetBSD
Date: Tue, 20 Dec 2022 21:55:02 +0000 (GMT)	[thread overview]
Message-ID: <20221220215502.13AB23858281@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=2af7dd95671197f43fb8c2c6d30461c143d63b03

commit 2af7dd95671197f43fb8c2c6d30461c143d63b03
Author:     Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Tue Dec 20 10:19:23 2022 +0100
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Tue Dec 20 10:19:23 2022 +0100

    Cygwin: x86_64: import swab.S from NetBSD
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/Makefile.am   |  1 +
 winsup/cygwin/x86_64/swab.S | 47 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/winsup/cygwin/Makefile.am b/winsup/cygwin/Makefile.am
index f8c249f527e7..0200f6e2a451 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 000000000000..ae73d1124762
--- /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)

                 reply	other threads:[~2022-12-20 21:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221220215502.13AB23858281@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).