From patchwork Thu May 4 07:48:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hau Hsu X-Patchwork-Id: 68735 X-Patchwork-Delegate: palmer@dabbelt.com 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 3D0653854146 for ; Thu, 4 May 2023 07:50:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D0653854146 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683186601; bh=TH84YE7rqdm9XGv6T+O94pI96mPlo4WeYYypkankhqA=; 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=FU8SddE97MfDhbM+WicH47AYJO945jAUC0vVbzeHk4G2RfKZc6u9VzTskVFaoRXcS vsaqEwFiYtpT02qjoGNZsyp3fQjJkYVzohHewxtJFMrcdweoYuYEyuapRPPonLBbbp jeJHG2c9hIFjN7Z1aRsaKJ1gKx0pGoKBaD9N33+k= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id EE9AC3856DC8 for ; Thu, 4 May 2023 07:49:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EE9AC3856DC8 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1aafa03f541so1185235ad.0 for ; Thu, 04 May 2023 00:49:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683186566; x=1685778566; 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=TH84YE7rqdm9XGv6T+O94pI96mPlo4WeYYypkankhqA=; b=HeFGBc6ibR4unD56o3xQLiGr5yLP/6MJBJqyF2RPpQiZA58hSuAazCwEC4tx403Qcf HEYUZn8ca2mFSK9RlLeRlVvct+Ml2z79/dttT7+5utAPc1M28QgoO6TUeY32VAMAX/E4 oavWPOF8PPrtdDjPgNO682aMBYQCZfVkUxJ4Hsbg241fB9tztae9HpUyNTKG27IZwKXN q+cHZ0hQdQ30vfKh1EQBOpTB3g0plDEbUIX/0vp1iOr4RPJIhwY1LJzYjxp5UFkUb6pn vpzRs3g2EuEI6rWvPTg3bVtF3mDiB2Qa2b24VCZYAJVQ1KGtbtyQgBQwjC9b1WG2vXrs RedA== X-Gm-Message-State: AC+VfDx7DwRlf5IdwSRl/DguMYjewyl+AuqH0n15JyLTdxVXuSeutDJ4 Zuq8Qksefggx7JApczWbrcyJHHPA6NEsEwp3kVkHSyRzC9y7UfCLns981Aj9nayYihCVIu2Ctzk abgxFMo8L0DziMYBPy2mqVt//Mxu6/YTKwi+wIPj3emyEUMrVylYqaFROl3Rzw3B8eYme13n4tC /a5g== X-Google-Smtp-Source: ACHHUZ6GrQcdIDjYFZPgyl3lRe78bgpVLPdocmMP8V9fbRZ+zOsU38t8i79OiWKESJx45reTVgmcxg== X-Received: by 2002:a17:902:7294:b0:1a9:21bc:65f8 with SMTP id d20-20020a170902729400b001a921bc65f8mr2808469pll.11.1683186565784; Thu, 04 May 2023 00:49:25 -0700 (PDT) Received: from localhost.localdomain (36-238-22-214.dynamic-ip.hinet.net. [36.238.22.214]) by smtp.gmail.com with ESMTPSA id y18-20020a17090322d200b001ab06958770sm4875294plg.161.2023.05.04.00.49.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 00:49:25 -0700 (PDT) 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 Subject: [PATCH v3 5/5] riscv: vectorized __memcmpeq function Date: Thu, 4 May 2023 15:48:51 +0800 Message-Id: <20230504074851.38763-6-hau.hsu@sifive.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230504074851.38763-1-hau.hsu@sifive.com> References: <20230504074851.38763-1-hau.hsu@sifive.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, 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 | 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 + . */ + +#include +#include + + +#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)