From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id 897383858C50 for ; Tue, 12 Jul 2022 17:11:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 897383858C50 Received: by mail-ot1-x32f.google.com with SMTP id y10-20020a9d634a000000b006167f7ce0c5so6594259otk.0 for ; Tue, 12 Jul 2022 10:11:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WRG77PTYEkyKD1/TJ7LwKpiUuYNNP6Twl9lrik0CbcQ=; b=0hqtMMvSf6i3fRIahAAkPySi6UmP+RsN/LT0sCB00KzglZ5Payfb5rPCr8FfSDCOyz j2Mtc1CZQuvdpoP6wWba/rno5JaXSZXNp2A/cmCd2hV6/V0LL4Z6/pqXGnHgAc+J5Yad NMXilQj8Lw0ZKO3fiUJ5PYH1PaqZQKgOoQRL9UJBK2Yw8BobNFALOD7tsp7W+Qfrqq+W 2V2d5n88sHMlCekkYRGMXDAANWShCNaHrLx770AoLG9KffxDj0xImHdsx4nuEW9nbfW/ AtUTEXah60BmNnzlt/jWCSx8SbVFeqEJsPD4Hg6pEqZyp9pdUWXGWF99vKSV5Y+ghyKz n14Q== X-Gm-Message-State: AJIora/1PcGW65xddfKn4XDpujMLdnWKHwayPhM3OscDKIZ0MyvX6TLy 6SyG0rHoQFILdodxaBAcAkyZf+UcRCkHyMQu3I4= X-Google-Smtp-Source: AGRyM1tr8mgXQGV56DNFcrsHx6AGOjGzZO6xYf1o1WdW+uf6s0U4X9PoMcQCmLzyCpVXiHa+LcG2dHtdQ/Rc2tYWl8M= X-Received: by 2002:a9d:6942:0:b0:61c:4c06:549c with SMTP id p2-20020a9d6942000000b0061c4c06549cmr4457886oto.103.1657645887742; Tue, 12 Jul 2022 10:11:27 -0700 (PDT) MIME-Version: 1.0 References: <20220711220730.1968923-1-goldstein.w.n@gmail.com> <20220711223841.2041611-1-goldstein.w.n@gmail.com> In-Reply-To: From: Noah Goldstein Date: Tue, 12 Jul 2022 10:11:16 -0700 Message-ID: Subject: Re: [PATCH v2] x86: Remove __mmask intrinsics in strstr-avx512.c To: "H.J. Lu" Cc: Sunil Pandey , GNU C Library , "Carlos O'Donell" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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-List-Received-Date: Tue, 12 Jul 2022 17:11:30 -0000 On Tue, Jul 12, 2022 at 8:56 AM H.J. Lu wrote: > > On Mon, Jul 11, 2022 at 7:38 PM Noah Goldstein wrote: > > > > On Mon, Jul 11, 2022 at 7:26 PM H.J. Lu wrote: > > > > > > On Mon, Jul 11, 2022 at 4:33 PM Sunil Pandey wrote: > > > > > > > > On Mon, Jul 11, 2022 at 3:52 PM Noah Goldstein wrote: > > > > > > > > > > On Mon, Jul 11, 2022 at 3:38 PM Noah Goldstein wrote: > > > > > > > > > > > > Using standard operators generates and the same code and __mmask > > > > > > instrinsics are not available before GCC7. > > > > > > > > > > > > Removed: > > > > > > _cvtmask64_u64 > > > > > > _kshiftri_mask64 > > > > > > _kand_mask64 > > > > > > --- > > > > > > sysdeps/x86_64/multiarch/strstr-avx512.c | 16 ++++++++++------ > > > > > > 1 file changed, 10 insertions(+), 6 deletions(-) > > > > > > > > > > > > diff --git a/sysdeps/x86_64/multiarch/strstr-avx512.c b/sysdeps/x86_64/multiarch/strstr-avx512.c > > > > > > index 2ab9e96db8..e44c1a05dc 100644 > > > > > > --- a/sysdeps/x86_64/multiarch/strstr-avx512.c > > > > > > +++ b/sysdeps/x86_64/multiarch/strstr-avx512.c > > > > > > @@ -26,6 +26,10 @@ > > > > > > #define ZMM_SIZE_IN_BYTES 64 > > > > > > #define PAGESIZE 4096 > > > > > > > > > > > > +#define cvtmask64_u64(...) (uint64_t) (__VA_ARGS__) > > > > > > +#define kshiftri_mask64(x, y) ((x) >> (y)) > > > > > > +#define kand_mask64(x, y) ((x) & (y)) > > > > > > + > > > > > > /* > > > > > > Returns the index of the first edge within the needle, returns 0 if no edge > > > > > > is found. Example: 'ab' is the first edge in 'aaaaaaaaaabaarddg' > > > > > > @@ -133,15 +137,15 @@ __strstr_avx512 (const char *haystack, const char *ned) > > > > > > __m512i hay0 = _mm512_maskz_loadu_epi8 (loadmask, haystack + hay_index); > > > > > > /* Search for NULL and compare only till null char */ > > > > > > uint64_t nullmask > > > > > > - = _cvtmask64_u64 (_mm512_mask_testn_epi8_mask (loadmask, hay0, hay0)); > > > > > > + = cvtmask64_u64 (_mm512_mask_testn_epi8_mask (loadmask, hay0, hay0)); > > > > > > uint64_t cmpmask = nullmask ^ (nullmask - ONE_64BIT); > > > > > > - cmpmask = cmpmask & _cvtmask64_u64 (loadmask); > > > > > > + cmpmask = cmpmask & cvtmask64_u64 (loadmask); > > > > > > /* Search for the 2 charaters of needle */ > > > > > > __mmask64 k0 = _mm512_cmpeq_epi8_mask (hay0, ned0); > > > > > > __mmask64 k1 = _mm512_cmpeq_epi8_mask (hay0, ned1); > > > > > > - k1 = _kshiftri_mask64 (k1, 1); > > > > > > + k1 = kshiftri_mask64 (k1, 1); > > > > > > /* k2 masks tell us if both chars from needle match */ > > > > > > - uint64_t k2 = _cvtmask64_u64 (_kand_mask64 (k0, k1)) & cmpmask; > > > > > > + uint64_t k2 = cvtmask64_u64 (kand_mask64 (k0, k1)) & cmpmask; > > > > > > /* For every match, search for the entire needle for a full match */ > > > > > > while (k2) > > > > > > { > > > > > > @@ -178,13 +182,13 @@ __strstr_avx512 (const char *haystack, const char *ned) > > > > > > hay0 = _mm512_loadu_si512 (haystack + hay_index); > > > > > > hay1 = _mm512_load_si512 (haystack + hay_index > > > > > > + 1); // Always 64 byte aligned > > > > > > - nullmask = _cvtmask64_u64 (_mm512_testn_epi8_mask (hay1, hay1)); > > > > > > + nullmask = cvtmask64_u64 (_mm512_testn_epi8_mask (hay1, hay1)); > > > > > > /* Compare only till null char */ > > > > > > cmpmask = nullmask ^ (nullmask - ONE_64BIT); > > > > > > k0 = _mm512_cmpeq_epi8_mask (hay0, ned0); > > > > > > k1 = _mm512_cmpeq_epi8_mask (hay1, ned1); > > > > > > /* k2 masks tell us if both chars from needle match */ > > > > > > - k2 = _cvtmask64_u64 (_kand_mask64 (k0, k1)) & cmpmask; > > > > > > + k2 = cvtmask64_u64 (kand_mask64 (k0, k1)) & cmpmask; > > > > > > /* For every match, compare full strings for potential match */ > > > > > > while (k2) > > > > > > { > > > > > > -- > > > > > > 2.34.1 > > > > > > > > > > > Sunil, > > > > > Does this work (v2 didn't get chained because I changed commit msg). > > > > > > > > Yes, v2 works. > > > > > > > > > > Any performance differences? > > > > It should generate the same code. It's just using standard operators instead > > of intrinsics. > > Has it been verified? You are right there are some diffs. Took a look at the ASM and think the new is probably fine, but will run a quick benchmark. > > > > > > > > > > -- > > > H.J. > > > > -- > H.J.