From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by sourceware.org (Postfix) with ESMTPS id 3A267386102B for ; Wed, 5 May 2021 18:19:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3A267386102B Received: by mail-pg1-x530.google.com with SMTP id y32so2348180pga.11 for ; Wed, 05 May 2021 11:19:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MoXNVFvkdv9CowG28fUNJ2lTC3Lx4qR6HxaUW2KXmnI=; b=AQbDS8hDHDhkYRGvK2o0JWgpNms6sNuMmFr1lm6K0hKnzzqW54ZrsYvvQvA2tK7F7W Q+gPJ+RsQL6W05M5AaDOfW+tzW1gXe8zw4fWoEMgmHZd84DlRbJzp12ZRxEDFAVlL9WC a0emRaQe6CL0IAIoBB4pE3eyO5YsF5qwlaQrvrLoZHwvnhDc1J8JaS6G9qSSxeszCRzM 2noOny2aVx+vxqFin6bP8kXGw8Fmtl2DjSTLsnUu8IaTJLI70pwwSiruMXsJDQi5/uE0 zRtTCeA11WIsR/gSNZroXjxvxfeeEz4mPmj1gMJsAPUrXf5xkxi9d70H4SrZHfQ6fs6u WBDw== X-Gm-Message-State: AOAM532i7v+0T72AfzxijWmakQ3xF+4hQgJovn/NRwi7y9awJ0loU1I3 bVrzbCnjoF9rluLxYW0qlcpf8odqzFgnOI89iTQ= X-Google-Smtp-Source: ABdhPJwnKdEZARrynO+tfT+1EQi5c3ApEEib1dl1zmb48K4MhI3A60WFSpeCGYOwWChPz8xDOhIYCdj9SQeAWaTXT4Y= X-Received: by 2002:aa7:8e85:0:b029:28f:2620:957e with SMTP id a5-20020aa78e850000b029028f2620957emr130857pfr.40.1620238743358; Wed, 05 May 2021 11:19:03 -0700 (PDT) MIME-Version: 1.0 References: <20210504233226.1514601-1-goldstein.w.n@gmail.com> In-Reply-To: From: Noah Goldstein Date: Wed, 5 May 2021 14:18:51 -0400 Message-ID: Subject: Re: [PATCH v1] x86: Add EVEX optimized memchr family not safe for RTM To: "H.J. Lu" Cc: GNU C Library , "Carlos O'Donell" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Wed, 05 May 2021 18:19:05 -0000 On Wed, May 5, 2021 at 1:55 PM H.J. Lu wrote: > > On Wed, May 5, 2021 at 9:25 AM Noah Goldstein wrote: > > > > On Wed, May 5, 2021 at 9:23 AM H.J. Lu wrote: > > > > > > On Tue, May 4, 2021 at 4:34 PM Noah Goldstein wrote: > > > > > > > > No bug. > > > > > > > > This commit adds a new implementation for EVEX memchr that is not safe > > > > for RTM because it uses vzeroupper. The benefit is that by using > > > > > > EVEX memchr won't cause RTM abort if YMM16-YMM31 are used > > > since there is no need to use vzeroupper. Please remove vzeroupper from > > > EVEX memchr and remove EVEX RTM functions. > > > > That's impossible for this implementation. > > > > The reason ymm0-ymm15 are used is so that we can use vpcmpeq which is > > not encodable with ymm16-ymm31. > > > > This implementation is optimized for CPUs which dont support RTM but > > do support EVEX. > > > > Are you seeing something along the line of Prefer_AVX2_STRCMP: Yes. For atleast some functions I think EVEX + AVX2 is probably the ideal implementation unless you have to worry about RTM. And as of right now there are a fair amount of x86_64 chips out there w/ avx512 but w/o RTM (or intel might fix the issue where vzeroupper aborts transactions in the future) For small values even if EVEX costs an extra instruction (i.e strchr vpxor + vpmin + vpcmp can be replace with vpcmpeq + vpcmp) the overhead of vzeroupper make EVEX perform better. But once the main loop is hit the overhead of vzeroupper isn't really a concern and vpcmpeq isnt really replaceable with vpcmp from a logic perspective (i.e 3x vpcmpeq + vptern isnt doable with vpcmp) and vpcmp is slower for tput and latency. As a little tackon the EVEX instructions are all larger code footprint than AVX2 so keeping instruction length <= 6byte for the DSB isnt really doable. I havent taken that long of a look at strcmp but would guess it would benefit in a simliar way as memchr from EVEX for sizes [0..160] then AVX2 for the loop (possibly augmented with vptern for 3way reduction) > > commit 1da50d4bda07f04135dca39f40e79fc9eabed1f8 > Author: H.J. Lu > Date: Fri Feb 26 05:36:59 2021 -0800 > > x86: Set Prefer_No_VZEROUPPER and add Prefer_AVX2_STRCMP > > 1. Set Prefer_No_VZEROUPPER if RTM is usable to avoid RTM abort triggered > by VZEROUPPER inside a transactionally executing RTM region. > 2. Since to compare 2 32-byte strings, 256-bit EVEX strcmp requires 2 > loads, 3 VPCMPs and 2 KORDs while AVX2 strcmp requires 1 load, 2 VPCMPEQs, > 1 VPMINU and 1 VPMOVMSKB, AVX2 strcmp is faster than EVEX strcmp. Add > Prefer_AVX2_STRCMP to prefer AVX2 strcmp family functions. > > > -- > H.J.