public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Robin Dapp <rdapp@linux.ibm.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>,
	Andreas Krebbel <krebbel@linux.ibm.com>
Subject: [PATCH] s390: Implement vec_revb(vector short)/bswapv8hi with, verllh.
Date: Fri, 12 Aug 2022 13:03:31 +0200	[thread overview]
Message-ID: <abc6a08b-8915-0d6d-01b7-d074a6d84bfb@linux.ibm.com> (raw)

Hi,

this patch implements a byte swap for a V8HImode vector via an element
rotate by 8 bits.

Bootstrapped and regtested, no regressions.

Is it OK?

Regards
 Robin

gcc/ChangeLog:

	PR target/100867
	* config/s390/vector.md: Add special case for V8HImode.

gcc/testsuite/ChangeLog:

	* gcc.target/s390/zvector/vec-revb-short.c: New test.
---
 gcc/config/s390/vector.md                     | 35 ++++++++++++-------
 .../gcc.target/s390/zvector/vec-revb-short.c  | 13 +++++++
 2 files changed, 35 insertions(+), 13 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/s390/zvector/vec-revb-short.c

diff --git a/gcc/config/s390/vector.md b/gcc/config/s390/vector.md
index 2207f39b80e4..6f46bed03e00 100644
--- a/gcc/config/s390/vector.md
+++ b/gcc/config/s390/vector.md
@@ -2898,22 +2898,31 @@ (define_expand "bswap<mode>"
   for (int i = 0; i < 16; i++)
     perm_rtx[i] = GEN_INT (perm[i]);

-  operands[2] = gen_rtx_CONST_VECTOR (V16QImode, gen_rtvec_v (16,
perm_rtx));
-
-  /* Without vxe2 we do not have byte swap instructions dealing
-     directly with memory operands.  So instead of waiting until
-     reload to fix that up switch over to vector permute right
-     now.  */
-  if (!TARGET_VXE2)
+  if (!TARGET_VXE2 && <MODE>mode == V8HImode)
     {
-      rtx in = force_reg (V16QImode, simplify_gen_subreg (V16QImode,
operands[1], <MODE>mode, 0));
-      rtx permute = force_reg (V16QImode, force_const_mem (V16QImode,
operands[2]));
-      rtx out = gen_reg_rtx (V16QImode);
-
-      emit_insn (gen_vec_permv16qi (out, in, in, permute));
-      emit_move_insn (operands[0], simplify_gen_subreg (<MODE>mode,
out, V16QImode, 0));
+      /* A byte swap for a short is just a rotate by 8 bits.  */
+      emit_insn (gen_rotlv8hi3 (operands[0], operands[1], GEN_INT (8)));
       DONE;
     }
+  else
+    {
+      operands[2] = gen_rtx_CONST_VECTOR (V16QImode, gen_rtvec_v (16,
perm_rtx));
+
+      /* Without vxe2 we do not have byte swap instructions dealing
+	 directly with memory operands.  So instead of waiting until
+	 reload to fix that up switch over to vector permute right
+	 now.  */
+      if (!TARGET_VXE2)
+	{
+	  rtx in = force_reg (V16QImode, simplify_gen_subreg (V16QImode,
operands[1], <MODE>mode, 0));
+	  rtx permute = force_reg (V16QImode, force_const_mem (V16QImode,
operands[2]));
+	  rtx out = gen_reg_rtx (V16QImode);
+
+	  emit_insn (gen_vec_permv16qi (out, in, in, permute));
+	  emit_move_insn (operands[0], simplify_gen_subreg (<MODE>mode, out,
V16QImode, 0));
+	  DONE;
+	}
+    }
 })

 ; Switching late to the reg-reg variant requires the vector permute
diff --git a/gcc/testsuite/gcc.target/s390/zvector/vec-revb-short.c
b/gcc/testsuite/gcc.target/s390/zvector/vec-revb-short.c
new file mode 100644
index 000000000000..bf58a0e12e74
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/zvector/vec-revb-short.c
@@ -0,0 +1,13 @@
+/* Test that we use verllh for byte reversing a vector of shorts.  */
+/* { dg-do compile { target { s390*-*-* } } } */
+/* { dg-options "-O2 -march=z13 -mzvector -mzarch -fno-unroll-loops" } */
+
+/* { dg-final { scan-assembler-times "verllh\t" 1 } } */
+/* { dg-final { scan-assembler-not "vperm" } } */
+
+#include <vecintrin.h>
+
+vector short revb (vector short a)
+{
+   return vec_revb (a);
+}
-- 
2.31.1


                 reply	other threads:[~2022-08-12 11:03 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=abc6a08b-8915-0d6d-01b7-d074a6d84bfb@linux.ibm.com \
    --to=rdapp@linux.ibm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=krebbel@linux.ibm.com \
    /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).