From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by sourceware.org (Postfix) with ESMTPS id E90BE385740C for ; Wed, 5 May 2021 18:29:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E90BE385740C Received: by mail-oi1-x22b.google.com with SMTP id e25so3079667oii.2 for ; Wed, 05 May 2021 11:29:50 -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=Rzgj6NPtOZRc9BKch0fmR2QVfLwgoao9MxN8ZV9eRMw=; b=mELGNLomnoC2amzsT07FsqqfT6YP9HYwdXRcEzadewR58qCt/CKo3o72thO3qgQQ89 NJ7tGTiMOzevCZNrFWRwIcoFv6c/2QcCfu+/G/NP9bzVyEtaxN3XGj9K6ngL/jY9VsAs iDfAoN4Xz9FcdqONpZGw+YFdXmxFntmPg+g7K2KrTi4PjqIwI0KV47P2Jx3LlJO4hOaV 94fnWab30Rlx7sGhIvwM0EzFrj2+JqitYwrWHHgwOyoKD8vJcJgwxFYBm6xH+syJB9Nu SMDmEDXborOJNuv+9zgCdpGynf5NkrpBFK+wbSKd8ujkYnfup/4PmBfy8oUi9r25077A gZjQ== X-Gm-Message-State: AOAM5312sFNwLnSn8yJCLVxO8a+Q6Uxrx9VdT3OH29JIgB7iUoxEzmSF FtVpliUK1XXHK1hp/yRmPyxInSegrzTiFJYlulPYc4j5l1U= X-Google-Smtp-Source: ABdhPJzhWWzxOfrn9ge8KV8y1JB4o0Xe/HZZn/Q8RfdCxKtPoyZG2GnwNF5aYSoVO6CEwrfcDnDeTHUVUKowXR3+Qrc= X-Received: by 2002:aca:bdc6:: with SMTP id n189mr7970437oif.156.1620239390408; Wed, 05 May 2021 11:29:50 -0700 (PDT) MIME-Version: 1.0 References: <20210504233226.1514601-1-goldstein.w.n@gmail.com> In-Reply-To: From: "H.J. Lu" Date: Wed, 5 May 2021 11:29:14 -0700 Message-ID: Subject: Re: [PATCH v1] x86: Add EVEX optimized memchr family not safe for RTM To: Noah Goldstein Cc: GNU C Library , "Carlos O'Donell" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3027.9 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:29:52 -0000 On Wed, May 5, 2021 at 11:19 AM Noah Goldstein wrote: > > 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. The only reason to use YMM16-YMM31 is to avoid vzeroupper. Since we are going to issue vzeroupper anyway, please use YMM0 to YMM15. > 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. -- H.J.