From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by sourceware.org (Postfix) with ESMTPS id E3B963858CDA for ; Mon, 9 Jan 2023 18:02:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E3B963858CDA 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-oi1-x234.google.com with SMTP id c133so7842654oif.1 for ; Mon, 09 Jan 2023 10:02:46 -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=qjGP/vhkxc3TbyP+2aHQNwYI5FClXgGaYcdh64YaUK8=; b=spKgw0YRtqtzNI3o/b8Tm3t36Wb1f9OLqWLenUjtWQPp7lRcYrcdZ7rndWyUKeWpfN IIkFdYPqFHwmjFBBGdkeNfikSBDQo4x0NqNY7VnBU9cy55f8sdvOheK2S4YsO7tkQG7d lRcSivsVtwY3H5xroObE8SMqv3E2K1xHeqARhw4Lph2fv+FeCLJiQxBfnSoWa7UI340z 0LapPK0Be/0Wc+WKPy1s39ec/4UzRmngAL/iuiO0kZvJBYWag8WhAkSD6H3gfPqUDOWy 6jkHEkB0FF6RlU2Vrn5hHnIejl+lRbDU5I91Oi7NB6UGL3Cv4CCDPAElQVC3cYCbyPt+ I/Pg== 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=qjGP/vhkxc3TbyP+2aHQNwYI5FClXgGaYcdh64YaUK8=; b=A1lDpXQ/zSF8FItSzNigXeOmGG2lrkJPO1phmudcnPncqE5peeKvo9jrIhmZwikh6W /9yXKrdAAb+KSkqM9BHCtWqb7GoJQeBPBMJ26iNB6w6FuvTXyZ4as46cf6k+CFnmYniC kH3fEoyp4MzT1R7nogOFD2N2/jVuYu30Xrkpnh3GVeC+K/srwBC4YouX73ONSHJRc5Lf qQYhVlAzvx8HkFh6w3G8iEGpm3BjcvWv0g5tW/A6EZzAXYaGHpYVz2e+kqBqLcyhTk8Y 2SCuZLW9GTYDqLZfnj9Fn5DpS5iAJpEK63/5FW8kd7G//H4Smd83NCfwLfcD3p8EU9PQ LTOw== X-Gm-Message-State: AFqh2kqSZ00uZ4/E1/99/GorCJ2ROpiL8TWDdLsYRFgiDDmvbWNvjQj3 CiUuRPMbsTFpdcPLmKHK2x65PA== X-Google-Smtp-Source: AMrXdXsHQ/fL4trvRSo1OXJ2vpsnxCKUt5axHcrHn8nZlaT6Mj52f9jEDWSXRyG3QYB2m0oydofrpw== X-Received: by 2002:a05:6808:2b0c:b0:35e:bbc3:7549 with SMTP id fe12-20020a0568082b0c00b0035ebbc37549mr26373891oib.10.1673287366044; Mon, 09 Jan 2023 10:02:46 -0800 (PST) Received: from ?IPV6:2804:1b3:a7c0:a93a:9d68:9321:503b:c278? ([2804:1b3:a7c0:a93a:9d68:9321:503b:c278]) by smtp.gmail.com with ESMTPSA id v4-20020a056808004400b0035173c2fddasm4174027oic.51.2023.01.09.10.02.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Jan 2023 10:02:45 -0800 (PST) Message-ID: <06a1db50-8dd4-3f06-2077-752b2e6bd711@linaro.org> Date: Mon, 9 Jan 2023 15:02:42 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH v5 03/17] Add string-maskoff.h generic header Content-Language: en-US To: Noah Goldstein Cc: libc-alpha@sourceware.org References: <20220919195920.956393-1-adhemerval.zanella@linaro.org> <20220919195920.956393-4-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.9 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 05/01/23 19:49, Noah Goldstein wrote: > On Mon, Sep 19, 2022 at 12:59 PM Adhemerval Zanella via Libc-alpha > wrote: >> >> Macros to operate on unaligned access for string operations: >> >> - create_mask: create a mask based on pointer alignment to sets up >> non-zero bytes before the beginning of the word so a following >> operation (such as find zero) might ignore these bytes. >> >> - highbit_mask: create a mask with high bit of each byte being 1, >> and the low 7 bits being all the opposite of the input. >> >> These macros are meant to be used on optimized vectorized string >> implementations. >> --- >> sysdeps/generic/string-maskoff.h | 73 ++++++++++++++++++++++++++++++++ >> 1 file changed, 73 insertions(+) >> create mode 100644 sysdeps/generic/string-maskoff.h >> >> diff --git a/sysdeps/generic/string-maskoff.h b/sysdeps/generic/string-maskoff.h >> new file mode 100644 >> index 0000000000..831647bda6 >> --- /dev/null >> +++ b/sysdeps/generic/string-maskoff.h >> @@ -0,0 +1,73 @@ >> +/* Mask off bits. Generic C version. >> + Copyright (C) 2022 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_MASKOFF_H >> +#define _STRING_MASKOFF_H 1 >> + >> +#include >> +#include >> +#include >> +#include >> + >> +/* Provide a mask based on the pointer alignment that sets up non-zero >> + bytes before the beginning of the word. It is used to mask off >> + undesirable bits from an aligned read from an unaligned pointer. >> + For instance, on a 64 bits machine with a pointer alignment of >> + 3 the function returns 0x0000000000ffffff for LE and 0xffffff0000000000 >> + (meaning to mask off the initial 3 bytes). */ >> +static inline op_t >> +create_mask (uintptr_t i) >> +{ >> + i = i % sizeof (op_t); >> + if (__BYTE_ORDER == __LITTLE_ENDIAN) >> + return ~(((op_t)-1) << (i * CHAR_BIT)); >> + else >> + return ~(((op_t)-1) >> (i * CHAR_BIT)); >> +} >> + >> +/* Setup an word with each byte being c_in. For instance, on a 64 bits >> + machine with input as 0xce the functions returns 0xcececececececece. */ >> +static inline op_t >> +repeat_bytes (unsigned char c_in) >> +{ >> + return ((op_t)-1 / 0xff) * c_in; >> +} >> + >> +/* Based on mask created by 'create_mask', mask off the high bit of each >> + byte in the mask. It is used to mask off undesirable bits from an >> + aligned read from an unaligned pointer, and also taking care to avoid >> + match possible bytes meant to be matched. For instance, on a 64 bits >> + machine with a mask created from a pointer with an alignment of 3 >> + (0x0000000000ffffff) the function returns 0x7f7f7f0000000000 for BE >> + and 0x00000000007f7f7f for LE. */ >> +static inline op_t >> +highbit_mask (op_t m) >> +{ >> + return m & repeat_bytes (0x7f); >> +} >> + >> +/* Return the address of the op_t word containing the address P. For >> + instance on address 0x0011223344556677 and op_t with size of 8, >> + it returns 0x0011223344556670. */ >> +static inline op_t * >> +word_containing (char const *p) >> +{ >> + return (op_t *) (p - (uintptr_t) p % sizeof (op_t)); > > This can just be (p & (-sizeof(p)) I think. Indeed it is simpler. > Other than that look goods. Thanks.