From patchwork Fri Apr 21 07:54:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hau Hsu X-Patchwork-Id: 68110 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1A2DF385381F for ; Fri, 21 Apr 2023 07:55:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A2DF385381F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682063730; bh=iXYYco1kbXOODD2dFTtsWq6yKtRa6g72VD/nuRu/hoo=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=lPdskiA3u9gZ4OTBl8yy7niDL6T4KpR+CFYQUDpWNYEqq49PTOtnUpMUKtcFOIsYx szfMF6wQ97tMkfbsoDIR9nR5X1+mf5m7NnhQGj0Hbln4iOSHl3GKjRJDQM8beaQc1V sG6pqxlOA1plU7dhJLTqHBnNBypZ7DUbzONX8nFY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 3EB893858434 for ; Fri, 21 Apr 2023 07:54:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3EB893858434 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-63b35789313so1489430b3a.3 for ; Fri, 21 Apr 2023 00:54:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682063672; x=1684655672; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iXYYco1kbXOODD2dFTtsWq6yKtRa6g72VD/nuRu/hoo=; b=Y/wAJSw6rSSkWxikeYKtxiDPx2XbZIuJMkR1OjVGlpQMMKlXTrJoIIh1xWHLM1G4f6 Rq3p/zoM/pSBJLxIshTllX5QSuJz23RLHzIWV2W+tltqmFVs4C1iuycdRL0neGKIvDQo fD8JHItbXsEaZOyeBaygFdX6mNcthNSMOwo0lxMtD5C/27PNGGYFjIpqPIpLgzFTxTdw 0nHmISDytxq6DNOxzqC1wRXNR1YCH4NPLDRfuviktXmzpRJaRuq71TxI1OLkcNvSEdbq O2We0TVXe55ug8Qs3y8JF3TP1tzIy+KpMC2qfarqLOHcbCrgUjMSCoh1v/iFFautH+Jj akFA== X-Gm-Message-State: AAQBX9e2mnjV092BvR235q+y7pOj+5RLStVWYUXsh1PcpRaxXX6L+3Gx ClnrcvIRZ7JXNA4XHWvLHQTrnitin9j0+IWuBC6gKCFvj2QsQw/7t6pcjB0sny174ZYwzFqT9zs N7C5rljyOR5cq3331K2vaOXgFh6GMjjwNCI3IX+Zp0K5MVg5a3a/ErargPP4tzyCrgkv9KW6g/2 mGAGvW X-Google-Smtp-Source: AKy350Z2ZuJyZrCiHc16kn7tYxku6EaucCv7nYwdpZghs7qn9P6taOFQJojfRVkekUC7Ce8iRXSazg== X-Received: by 2002:a05:6a20:c1a6:b0:e5:58e6:be37 with SMTP id bg38-20020a056a20c1a600b000e558e6be37mr5344940pzb.61.1682063671874; Fri, 21 Apr 2023 00:54:31 -0700 (PDT) Received: from localhost.localdomain (1-169-217-217.dynamic-ip.hinet.net. [1.169.217.217]) by smtp.gmail.com with ESMTPSA id fa23-20020a056a002d1700b006259e883ee9sm650992pfb.189.2023.04.21.00.54.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Apr 2023 00:54:31 -0700 (PDT) To: libc-alpha@sourceware.org, hongrong.hsu@sifive.com, jerry.shih@sifive.com, nick.knight@sifive.com, kito.cheng@sifive.com Cc: greentime.hu@sifive.com, alice.chan@sifive.com, andrew@sifive.com, vincent.chen@sifive.com, hau.hsu@sifive.com, Yun Hsiang Subject: [PATCH v2 5/5] riscv: add vectorized __memcmpeq Date: Fri, 21 Apr 2023 15:54:05 +0800 Message-Id: <20230421075405.14892-6-hau.hsu@sifive.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230421075405.14892-1-hau.hsu@sifive.com> References: <20230421075405.14892-1-hau.hsu@sifive.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Hau Hsu via Libc-alpha From: Hau Hsu Reply-To: Hau Hsu Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" From: Yun Hsiang 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 | 69 ++++++++++++++++++++++++++++++++++++ 2 files changed, 69 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 b156ec524c..74d8361293 100644 --- a/sysdeps/riscv/rvv/memcmp.S +++ b/sysdeps/riscv/rvv/memcmp.S @@ -69,7 +69,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..302bca6992 --- /dev/null +++ b/sysdeps/riscv/rvv/memcmpeq.S @@ -0,0 +1,69 @@ +/* RVV versions memcmp. RISC-V version. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jerry Shih , + Yun Hsiang . + + 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 + . */ + +#include +#include + + +#define iResult a0 + +#define pSrc1 a0 +#define pSrc2 a1 +#define iNum a2 + +#define iVL a3 +#define iTemp a4 + +#define ELEM_LMUL_SETTING m1 +#define vData1 v0 +#define vData2 v8 +#define vMask v16 + +ENTRY(__memcmpeq) + +L(loop): + vsetvli iVL, iNum, e8, ELEM_LMUL_SETTING, ta, ma + + vle8.v vData1, (pSrc1) + vle8.v vData2, (pSrc2) + + vmsne.vv vMask, vData1, vData2 + sub iNum, iNum, iVL + vfirst.m iTemp, vMask + + // Skip the loop if we find the different value between pSrc1 and pSrc2. + bgez iTemp, L(found) + + add pSrc1, pSrc1, iVL + add pSrc2, pSrc2, iVL + + bnez iNum, L(loop) + + li iResult, 0 + ret + +L(found): + mv iResult, iVL + ret + +END(__memcmpeq) + +weak_alias (__memcmpeq, bcmp) +libc_hidden_def (__memcmpeq)