From patchwork Fri Jan 13 18:27:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 642041 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp358320pvb; Fri, 13 Jan 2023 10:29:15 -0800 (PST) X-Google-Smtp-Source: AMrXdXvg8pFbxx3aHWOIEWYOPskueyc1/8NoJqDF4nvfN4W8skGDRJvxErVJHQiMeLnafIa9D0PH X-Received: by 2002:a05:6402:5505:b0:499:c332:3b50 with SMTP id fi5-20020a056402550500b00499c3323b50mr14476104edb.39.1673634555040; Fri, 13 Jan 2023 10:29:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673634555; cv=none; d=google.com; s=arc-20160816; b=c+oFwEARP1xYjjaW9Ek7U4UJ6Ap1hd1ZYzpySWwPkW70mUGdFxVE9DWPGbzhGLGcE3 dBQSAY2b1ou1eYWCXLNQTmKKX2f3h9WQw19GLUltwk6m+vOyJIwEnswy7aJgUFQZ3pzl 1L8wa7HfBHrD769yqJhO6HFLnCuJ0tf8hdTqP86UToseBd2R0NSYQsrOJNpfFh+OJAJn 3e2keaEs0Yqd1l1TJI24Z1BHdut8k+nWRvCWWrtNPpP5LIT3fmW14MXCIz6ulJXUTq6T rjRa5vm/ZGuKAQp59pJ1WCvZDVQc5/2Y1204ymsLQs4UI74FLspm0M8TxSb/3GtdbIDB hjIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=3YOfQgzvPO37lwN5xewD1gZlsrMvF0C46UAL/M8JUhM=; b=SxGZpPnLG0CIRIuQRLUlzs4RESbuhrX2LBxL0ieLtMxDH5ILC/1/8ipfZOe9IBcuDf F2OdlI9nQ2rDHnTE3wf8YpkpEYSTwRc3j1wfo4E5jRqK2OOpaTIeEO92gklezUAVHKPk Mo+cq9WppOhM5XEMKMXo3je/Yg6Lu2lvHUEwFXTO2DQMIkeB17Lzg+5JUgBdBpBq7L/L gmuanNsYT4D8s06Nkg+0ivGVSKnQbvRL9Z6kdXKDLZODXrXZMioyehdicBXISCOuUHof +fA+1b3eP+9XCAiQSZgpzlCwfPPgi7YLpIq7CZ3MSTbtlgkvus709ZJWUwJSPxFTj+Dm P8vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=g1CNFWEh; spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Return-Path: Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b7-20020a056402278700b0046dd7c3ceb5si23580354ede.475.2023.01.13.10.29.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 10:29:15 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=g1CNFWEh; spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F18C038983B7 for ; Fri, 13 Jan 2023 18:29:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F18C038983B7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673634554; bh=3YOfQgzvPO37lwN5xewD1gZlsrMvF0C46UAL/M8JUhM=; 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=g1CNFWEh9i+pxc7s/Rgde7TnF+EMh5hpMBLkxabyQoyYGmRuuVsTNc7Z94PmRCytW FOf+hBMzC0jD0Vbt1iF19UkLaw3m/dgj8lGSFUiwq3pvIoBRUQXPTHupDBLB49pMSI z+QjXVWTLEbYrLB0BtPFuqCDAVEp00VNA2fLLxy8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id E3EEA3861009 for ; Fri, 13 Jan 2023 18:27:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E3EEA3861009 Received: by mail-pl1-x62e.google.com with SMTP id b17so16755599pld.7 for ; Fri, 13 Jan 2023 10:27:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=3YOfQgzvPO37lwN5xewD1gZlsrMvF0C46UAL/M8JUhM=; b=TgYwwhjSez75YU6XLYvajl8HqURRFTyojjOzCQJDnAVQIbzFclLSGa370T0yYS1XEY M36GkEMhJpkdjwG8dxiM/pZxaDAd/p1eckxIWh20u6OF24P9Y0qA2sAN1mW/5TOpJmyX eaLjHMpnhB+Gs5b3ngWnW99SitHSQs215UpcMH391MTdO0zgNKZ3R+TKuHNMX4dJLuuX tfs0aH7vnCUxfah1VrMcroHW3RgM+9EL0NRzCnJ4DgIS6ZWW9O6burkW0fqNJcnphk23 SHALIzF+1Chtx+RT2xhq1oUQXIEq1rrxXgBcRgGLv7KtCzs9LbbPZxhARWW+j3swJwQm k+VA== X-Gm-Message-State: AFqh2kon1PF8GGBoW6icICrzmydyx2FLT5g2CP5bxBjrqY0RvuWrTioM JWgW1+ahGnyiLtj60ix5YX9RCFDHF4mMelAy X-Received: by 2002:a17:902:9884:b0:194:7a99:d5fd with SMTP id s4-20020a170902988400b001947a99d5fdmr315138plp.10.1673634460954; Fri, 13 Jan 2023 10:27:40 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id s17-20020a170902c65100b001927ebc40e2sm14443640pls.193.2023.01.13.10.27.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 10:27:40 -0800 (PST) To: libc-alpha@sourceware.org Cc: adhemerval.zanella@linaro.org, goldstein.w.n@gmail.com Subject: [PATCH v8 03/17] Add string-maskoff.h generic header Date: Fri, 13 Jan 2023 08:27:19 -1000 Message-Id: <20230113182733.1268668-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230113182733.1268668-1-richard.henderson@linaro.org> References: <20230113182733.1268668-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 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 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: Richard Henderson via Libc-alpha From: Richard Henderson Reply-To: Richard Henderson Errors-To: libc-alpha-bounces+patch=linaro.org@sourceware.org Sender: "Libc-alpha" From: Adhemerval Zanella Netto 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. - repeat_bytes: setup an word with each byte being c_in. - 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. - word_containing: return the address of the op_t word containing the addres. These macros are meant to be used on optimized vectorized string implementations. Message-Id: <20230111204558.2402155-4-adhemerval.zanella@linaro.org> --- 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..73edd5ad0f --- /dev/null +++ b/sysdeps/generic/string-maskoff.h @@ -0,0 +1,73 @@ +/* Mask off bits. Generic C 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_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 __always_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 __always_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 __always_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 __always_inline op_t * +word_containing (char const *p) +{ + return (op_t *) ((uintptr_t) p & -sizeof (op_t)); +} + +#endif /* _STRING_MASKOFF_H */