public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Hau Hsu <hau.hsu@sifive.com>
To: libc-alpha@sourceware.org
Cc: hau.hsu@sifive.com, kito.cheng@sifive.com,
	nick.knight@sifive.com, jerry.shih@sifive.com,
	vincent.chen@sifive.com, hongrong.hsu@sifive.com,
	Yun Hsiang <yun.hsiang@sifive.com>
Subject: [PATCH v3 5/5] riscv: vectorized __memcmpeq function
Date: Thu,  4 May 2023 15:48:51 +0800	[thread overview]
Message-ID: <20230504074851.38763-6-hau.hsu@sifive.com> (raw)
In-Reply-To: <20230504074851.38763-1-hau.hsu@sifive.com>

From: Yun Hsiang <yun.hsiang@sifive.com>

This patch proposes implementations of __memcmpeq that leverage the
RISC-V V extension (RVV), version 1.0. These routines assumes VLEN is at
least 32 bits, as is required by all currently defined vector
extensions, and they support arbitrarily large VLEN. All implementations
work for both RV32 and RV64 platforms, and make no assumptions about
page size.
---
 sysdeps/riscv/rvv/memcmp.S   |  4 ---
 sysdeps/riscv/rvv/memcmpeq.S | 67 ++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+), 4 deletions(-)
 create mode 100644 sysdeps/riscv/rvv/memcmpeq.S

diff --git a/sysdeps/riscv/rvv/memcmp.S b/sysdeps/riscv/rvv/memcmp.S
index fbf81acc2f..eeec2cae6a 100644
--- a/sysdeps/riscv/rvv/memcmp.S
+++ b/sysdeps/riscv/rvv/memcmp.S
@@ -68,7 +68,3 @@ L(found):
 
 END(memcmp)
 libc_hidden_builtin_def (memcmp)
-weak_alias (memcmp,bcmp)
-strong_alias (memcmp, __memcmpeq)
-libc_hidden_def (__memcmpeq)
-
diff --git a/sysdeps/riscv/rvv/memcmpeq.S b/sysdeps/riscv/rvv/memcmpeq.S
new file mode 100644
index 0000000000..5820af69d7
--- /dev/null
+++ b/sysdeps/riscv/rvv/memcmpeq.S
@@ -0,0 +1,67 @@
+/* RVV versions memcmp.  RISC-V version.
+   Copyright (C) 2023 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+#include <sys/asm.h>
+
+
+#define result a0
+
+#define src1 a0
+#define src2 a1
+#define num a2
+
+#define ivl a3
+#define temp a4
+
+#define ELEM_LMUL_SETTING m1
+#define vdata1 v0
+#define vdata2 v8
+#define vmask v16
+
+ENTRY(__memcmpeq)
+
+L(loop):
+    vsetvli ivl, num, e8, ELEM_LMUL_SETTING, ta, ma
+
+    vle8.v vdata1, (src1)
+    vle8.v vdata2, (src2)
+
+    vmsne.vv vmask, vdata1, vdata2
+    sub num, num, ivl
+    vfirst.m temp, vmask
+
+    /* Skip the loop if we find the different value between src1 and src2. */
+    bgez temp, L(found)
+
+    add src1, src1, ivl
+    add src2, src2, ivl
+
+    bnez num, L(loop)
+
+    li result, 0
+    ret
+
+L(found):
+    mv result, ivl
+    ret
+
+END(__memcmpeq)
+
+weak_alias (__memcmpeq, bcmp)
+libc_hidden_def (__memcmpeq)
-- 
2.38.1


  parent reply	other threads:[~2023-05-04  7:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-04  7:48 [PATCH v3 0/5] riscv: Vectorized mem*/str* function Hau Hsu
2023-05-04  7:48 ` [PATCH v3 1/5] riscv: Enabling vectorized mem*/str* functions in build time Hau Hsu
2023-05-04  7:48 ` [PATCH v3 2/5] riscv: vectorized mem* functions Hau Hsu
2023-05-04  7:48 ` [PATCH v3 3/5] riscv: vectorized str* functions Hau Hsu
2023-05-04  7:48 ` [PATCH v3 4/5] riscv: vectorized strchr and strnlen functions Hau Hsu
2023-05-04  7:48 ` Hau Hsu [this message]
2023-05-08 14:06 ` [PATCH v3 0/5] riscv: Vectorized mem*/str* function Palmer Dabbelt
2023-05-10  9:01   ` Hau Hsu
2023-05-10 12:28     ` Sergei Lewis

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=20230504074851.38763-6-hau.hsu@sifive.com \
    --to=hau.hsu@sifive.com \
    --cc=hongrong.hsu@sifive.com \
    --cc=jerry.shih@sifive.com \
    --cc=kito.cheng@sifive.com \
    --cc=libc-alpha@sourceware.org \
    --cc=nick.knight@sifive.com \
    --cc=vincent.chen@sifive.com \
    --cc=yun.hsiang@sifive.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).