From patchwork Fri Jan 13 18:27:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 63182 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 BC72E3882FC6 for ; Fri, 13 Jan 2023 18:31:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC72E3882FC6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673634674; bh=Wej9hmRIG6E511H58aJkE9khzXv1ASTDIoxkGOi95w0=; 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=CTBHWeob0SZX3/tJ1nSBKi//nwJl9Nip899ZWnlQQTRYNEEVjFXKab6jH5kg4cYS8 mwJVE2HfKvlwQonfq95bn6NdIVwcYUqjNfooJC0+RAZxy30VGfxbP5msskgGS2rpq5 qSCAdyeLWmkW1r9VVNdviBJiY6jjLfsRH+2+PwLU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by sourceware.org (Postfix) with ESMTPS id 4ABA0383FBA4 for ; Fri, 13 Jan 2023 18:28:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4ABA0383FBA4 Received: by mail-pl1-x62b.google.com with SMTP id d3so24241205plr.10 for ; Fri, 13 Jan 2023 10:28:01 -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=Wej9hmRIG6E511H58aJkE9khzXv1ASTDIoxkGOi95w0=; b=GCxZOUQ0EhFWMdVc6LOf8FCD7m3EZIFarF4wAhiGWGQGvbVvmfcQTF2KwIxxxrgfVl +/v/Gv/xp56VYUIpThTja4imSUJKJRF+K9HFlNx0/oKbk5CjIe2Pk5RgeIEObBlVhDYB 4reWfi7sObaopk04WDzOk2x7l3emuYPLMDdRv0PV7WoPO1YWTN0R8OwjQQErXsh5ielh 7RTAKhKKeOUs4roHLisYXKN37SzZjZlqk3VpXybzIDxirC0t2GSYly5cA5t5D/GnGMqI WOTTKzADj4TfSXJpO8EpwhXOgKPE9I2qoD8WBCKGQJ5+19EyfufYTh0e/jRgaPQ4elBE qJtg== X-Gm-Message-State: AFqh2koqqIX1QKgGCWorT0gxOPn/BX3kHQN6NAnqQmCtO8FATOzSvshr r8KZq18vuv8+11j5x5ed+VIh8wLBXj+qAgZG X-Google-Smtp-Source: AMrXdXv5c0qKbuDNypYSTtuY2FnpAA2RBCLSNmY5syFMp/HPCk550upsr6SWFUPg7+kMbfy5BtMCmw== X-Received: by 2002:a17:903:292:b0:194:721e:611d with SMTP id j18-20020a170903029200b00194721e611dmr3013067plr.14.1673634480329; Fri, 13 Jan 2023 10:28:00 -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.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 10:27:59 -0800 (PST) To: libc-alpha@sourceware.org Cc: adhemerval.zanella@linaro.org, goldstein.w.n@gmail.com Subject: [PATCH v8 16/17] powerpc: Add string-fza.h Date: Fri, 13 Jan 2023 08:27:32 -1000 Message-Id: <20230113182733.1268668-17-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=-12.2 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+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" While ppc has the more important string functions in assembly, there are still a few generic routines used. Use the Power 6 CMPB insn for testing of zeros. Checked on powerpc64le-linux-gnu. Message-Id: <20230111204558.2402155-17-adhemerval.zanella@linaro.org> --- sysdeps/powerpc/powerpc32/power6/string-fza.h | 1 + sysdeps/powerpc/powerpc64/power6/string-fza.h | 1 + sysdeps/powerpc/string-fza.h | 82 +++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 sysdeps/powerpc/powerpc32/power6/string-fza.h create mode 100644 sysdeps/powerpc/powerpc64/power6/string-fza.h create mode 100644 sysdeps/powerpc/string-fza.h diff --git a/sysdeps/powerpc/powerpc32/power6/string-fza.h b/sysdeps/powerpc/powerpc32/power6/string-fza.h new file mode 100644 index 0000000000..bb00d7c4f7 --- /dev/null +++ b/sysdeps/powerpc/powerpc32/power6/string-fza.h @@ -0,0 +1 @@ +#include diff --git a/sysdeps/powerpc/powerpc64/power6/string-fza.h b/sysdeps/powerpc/powerpc64/power6/string-fza.h new file mode 100644 index 0000000000..bb00d7c4f7 --- /dev/null +++ b/sysdeps/powerpc/powerpc64/power6/string-fza.h @@ -0,0 +1 @@ +#include diff --git a/sysdeps/powerpc/string-fza.h b/sysdeps/powerpc/string-fza.h new file mode 100644 index 0000000000..6a495d14d7 --- /dev/null +++ b/sysdeps/powerpc/string-fza.h @@ -0,0 +1,82 @@ +/* Zero byte detection; basics. PowerPC 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 _POWERPC_STRING_FZA_H +#define _POWERPC_STRING_FZA_H 1 + +/* PowerISA 2.05 (POWER6) provides cmpb instruction. */ + +#include +#include +#include +#include + +/* The functions return a byte mask. */ +typedef op_t find_t; + +/* Return the mask WORD shifted based on S_INT address value, to ignore + values not presented in the aligned word read. */ +static __always_inline find_t +shift_find (find_t word, uintptr_t s) +{ + if (__BYTE_ORDER == __LITTLE_ENDIAN) + return word >> (CHAR_BIT * (s % sizeof (op_t))); + else + return word << (CHAR_BIT * (s % sizeof (op_t))); +} + +/* 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 __builtin_cmpb (x1, x2); +} + +/* This function returns 0xff for each byte that is zero in X. */ + +static __always_inline find_t +find_zero_all (op_t x) +{ + return find_eq_all (x, 0); +} + +/* 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 + +#endif /* _POWERPC_STRING_FZA_H */