From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc2d.google.com (mail-oo1-xc2d.google.com [IPv6:2607:f8b0:4864:20::c2d]) by sourceware.org (Postfix) with ESMTPS id 70F053858D1E for ; Mon, 6 Feb 2023 16:14:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 70F053858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oo1-xc2d.google.com with SMTP id i21-20020a4ad395000000b00517895ed15dso1160630oos.0 for ; Mon, 06 Feb 2023 08:14:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=EOCrTzJgH92RIa+ZxOy8iE0e+3JXU4LK43DyCq5O1Lg=; b=qyHiJJr4yYe7nkDg4WEumz53pYIn6obiXjgPyTS1d4KN/l1jwhvNSTpUrFiYNmC8V6 JyG4U+Tmlp7XyeiXfffeCKGH69OhoIH1yT5eCPEdloTxAkl5n3qiVJoWzB9i6dmZzltS mO3FyMUng7bm4iMPucE4/EkzTKTdgfMy7zdqDtf4MbMmXT5+igf8FOYksK8ge+DEVJz0 48D4xx+x1vaIYRLkluPagg2PLTCaFo5m91OLLq/rDO9x5cqcoqFlhlNKvrkvIn5gdoOI I6TYPPq029IBkTFCDTR/XWfDDN0yhIFWaaIo4nymeRM7xEw83EopIqKKdTPwLV8tsgAx 3elQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EOCrTzJgH92RIa+ZxOy8iE0e+3JXU4LK43DyCq5O1Lg=; b=A4me4gE4R2XNufVZlI9hiYO4LxQA6tC/S+/J3rAAy4ra15KmRqEPaor+83BbBus0y4 uxQwU47+oAH7p58T8NyslHz7iR3IkgosNt/GPc4Vt8qIGEAZfTB8/A3yU1LLmXlflIKM ZW/EwySsZfkUVW7P5BV9se3lrZbOcjLw8nDTq/Yss2KoIO6SmQVp7txXS1pAaL6om3RK uxqur4NVjo/AcWqCkiX3Araw8W1HPsVuj1iEMepiwh8s6WwuRdjaH1ob6wTKVD0UA12N rVqyjMHfrNzgMR+HbqhDjGzORkVVIVFzbuxJ7TUhBHwFHkgA9dzFg9IWGsXbDcVQr/dc ePIw== X-Gm-Message-State: AO0yUKUUbrCyOO9geY9/3VUGMEwJ6ilL0uI7el2RNRxJbfcv/Dt5oqaO xDBi84yXYjbRxRPo7OaYYAYftnR6TMIPUYYQYd0= X-Google-Smtp-Source: AK7set+3qumYPlemn1xv/WV82OgVUol48ZWKgSGmQnAM6USvPYbmC1xLucMBPzQPnhTOhchJ7hX7Gw== X-Received: by 2002:a4a:8505:0:b0:4f2:875:5252 with SMTP id k5-20020a4a8505000000b004f208755252mr107747ooh.3.1675700063618; Mon, 06 Feb 2023 08:14:23 -0800 (PST) Received: from ?IPV6:2804:1b3:a7c2:8ced:8a3:838:7129:e0bf? ([2804:1b3:a7c2:8ced:8a3:838:7129:e0bf]) by smtp.gmail.com with ESMTPSA id x48-20020a4a97f3000000b004f28d09a880sm4770008ooi.13.2023.02.06.08.14.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 Feb 2023 08:14:22 -0800 (PST) Message-ID: <50335aba-eba2-f904-43b2-90df9eb45f08@linaro.org> Date: Mon, 6 Feb 2023 13:14:19 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [PATCH v12 21/31] riscv: Add string-fza.h and string-fzi.h Content-Language: en-US To: Noah Goldstein Cc: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao References: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> <20230202181149.2181553-22-adhemerval.zanella@linaro.org> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 03/02/23 16:47, Noah Goldstein wrote: > On Thu, Feb 2, 2023 at 12:12 PM Adhemerval Zanella > wrote: >> >> It uses the bitmanip extension to optimize index_fist and index_last >> with clz/ctz (using generic implementation that routes to compiler >> builtin) and orc.b to check null bytes. >> >> Checked the string test on riscv64 user mode. >> Reviewed-by: Richard Henderson >> --- >> sysdeps/riscv/string-fza.h | 70 ++++++++++++++++++++++++++++++++++ >> sysdeps/riscv/string-fzi.h | 77 ++++++++++++++++++++++++++++++++++++++ >> 2 files changed, 147 insertions(+) >> create mode 100644 sysdeps/riscv/string-fza.h >> create mode 100644 sysdeps/riscv/string-fzi.h >> >> diff --git a/sysdeps/riscv/string-fza.h b/sysdeps/riscv/string-fza.h >> new file mode 100644 >> index 0000000000..9c7a6efba2 >> --- /dev/null >> +++ b/sysdeps/riscv/string-fza.h >> @@ -0,0 +1,70 @@ >> +/* Zero byte detection; basics. RISCV 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 >> + . */ >> + >> +#ifndef _RISCV_STRING_FZA_H >> +#define _RISCV_STRING_FZA_H 1 >> + >> +#ifdef __riscv_zbb >> +/* With bitmap extension we can use orc.b to find all zero bytes. */ >> +# include >> +# include >> + >> +/* The functions return a byte mask. */ >> +typedef op_t find_t; >> + >> +/* This function returns 0xff for each byte that is zero in X. */ >> +static __always_inline find_t >> +find_zero_all (op_t x) >> +{ >> + find_t r; >> + asm ("orc.b %0, %1" : "=r" (r) : "r" (x)); >> + return ~r; >> +} >> + >> +/* This function returns 0xff for each byte that is equal between X1 and >> + X2. */ >> +static __always_inline find_t >> +find_eq_all (op_t x1, op_t x2) >> +{ >> + return find_zero_all (x1 ^ x2); >> +} >> + >> +/* Identify zero bytes in X1 or equality between X1 and X2. */ >> +static __always_inline find_t >> +find_zero_eq_all (op_t x1, op_t x2) >> +{ >> + return find_zero_all (x1) | find_eq_all (x1, x2); >> +} >> + >> +/* Identify zero bytes in X1 or inequality between X1 and X2. */ >> +static __always_inline find_t >> +find_zero_ne_all (op_t x1, op_t x2) >> +{ >> + return find_zero_all (x1) | ~find_eq_all (x1, x2); >> +} >> + >> +/* Define the "inexact" versions in terms of the exact versions. */ >> +# define find_zero_low find_zero_all >> +# define find_eq_low find_eq_all >> +# define find_zero_eq_low find_zero_eq_all >> +# define find_zero_ne_low find_zero_ne_all >> +#else >> +#include >> +#endif >> + >> +#endif /* _RISCV_STRING_FZA_H */ >> diff --git a/sysdeps/riscv/string-fzi.h b/sysdeps/riscv/string-fzi.h >> new file mode 100644 >> index 0000000000..3cde113afb >> --- /dev/null >> +++ b/sysdeps/riscv/string-fzi.h >> @@ -0,0 +1,77 @@ >> +/* Zero byte detection; indexes. RISCV 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 >> + . */ >> + >> +#ifndef _STRING_RISCV_FZI_H >> +#define _STRING_RISCV_FZI_H 1 >> + >> +#ifdef __riscv_zbb >> +# include >> +#else >> +/* Without bitmap clz/ctz extensions, it is faster to direct test the bits >> + instead of calling compiler auxiliary functions. */ >> +# include >> + >> +static __always_inline unsigned int >> +index_first (find_t c) >> +{ >> + if (c & 0x80U) >> + return 0; >> + if (c & 0x8000U) >> + return 1; >> + if (c & 0x800000U) >> + return 2; >> + >> + if (sizeof (op_t) == 4) >> + return 3; >> + >> + if (c & 0x80000000U) >> + return 3; >> + if (c & 0x8000000000UL) >> + return 4; >> + if (c & 0x800000000000UL) >> + return 5; >> + if (c & 0x80000000000000UL) >> + return 6; >> + return 7; >> +} >> + >> +static __always_inline unsigned int >> +index_last (find_t c) >> +{ >> + if (sizeof (op_t) == 8) >> + { >> + if (c & 0x8000000000000000UL) >> + return 7; >> + if (c & 0x80000000000000UL) >> + return 6; >> + if (c & 0x800000000000UL) >> + return 5; >> + if (c & 0x8000000000UL) >> + return 4; >> + } >> + if (c & 0x80000000U) >> + return 3; >> + if (c & 0x800000U) >> + return 2; >> + if (c & 0x8000U) >> + return 1; >> + return 0; >> +} >> +#endif >> + >> +#endif /* STRING_FZI_H */ >> -- >> 2.34.1 >> > > Has WS error: > ``` > Applying: riscv: Add string-fza.h and string-fzi.h > .git/rebase-apply/patch:115: trailing whitespace. > instead of calling compiler auxiliary functions. */ > warning: 1 line adds whitespace errors. > ``` Thanks, I will fix it before apply.