From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 6BA353858D37 for ; Mon, 19 Sep 2022 21:59:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6BA353858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x62f.google.com with SMTP id y17so1845200ejo.6 for ; Mon, 19 Sep 2022 14:59:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=9P9vFMlMXL3IXMcp9gENeXm/MPj0rPAsWzIiCnef9Eo=; b=i8S8aDxWiJSN1QEmvhg0J2SUvwJnBQEGmduM1vAOvUt0od0ZPYMon2SEdFmR2EPrGk XhbeXb5qrIrrlvuwxS92cBr9dNXDFpOjhR+TC9LIUxcZlBBYoct+dR4r9AIi8UU0iNb0 b5PpnkvhwOIgoz0KtEa/lRYLaFMHnY3DEJeVgvVxU700HR97c7QXoym76vtKLk6jc/7v qbXLtBT56G5CJBYzZ9VhZ/9mM9+06zfiKNaaynEk3WPftxwMr5WxQwMhZMHjNOPLb2a8 gjMkbvxxA5l3yjHwCuGoE5M2vwBOeSvt41Sjhm9mZ/6AttmQfEYLQst3ClmeJygb+XHY dhbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=9P9vFMlMXL3IXMcp9gENeXm/MPj0rPAsWzIiCnef9Eo=; b=UZRJTgUOdKVM4/WziMxW9IHHdC8tLZfQjTS02qKll0z1zpdC5RhFjAebM6HzrVafPZ mWWvp+XrfP9C0R++fxjhFa2ZxomRLuWaKGfJmFgNi7XvdLUoWA1BViEqt4hfHX3ySer0 xmyE1aYjiFK2xCBHqvoO88UBTZwXCyJusO7yjpaapgzR2tkQ0XdJThA72eU51MsM/N7O 9OKoZAZwa6/vD2tv2xZd6OmT1PNM2PHyIIXUyi5afwskYvxr6XExUGV2jDueTydgIu9V 4j9cXEqYVoeHle9lRr2blZ5lVRqh9oe3xX8cX5dvwd8BnHcQnSWaE+Zrnngg9VBT/fLH ZqBg== X-Gm-Message-State: ACrzQf3YpgMkqcAqIZoTPijwxPW/0uKeXVkayX8/VMnfq6/rzxDk5EPM vD/oSMFuX71MgoRSJjneCYBO4tWr4HwIrpyuPq8= X-Google-Smtp-Source: AMsMyM77VArL0n1MN3/xxlSOdxm5O5BmWphkFfAt3q46jSw4cTcc8M1rh4/8GBDiuVgYJy513zF6ks+hjDXF0a/xTwA= X-Received: by 2002:a17:906:fe46:b0:73d:939a:ec99 with SMTP id wz6-20020a170906fe4600b0073d939aec99mr14466342ejb.169.1663624769036; Mon, 19 Sep 2022 14:59:29 -0700 (PDT) MIME-Version: 1.0 References: <20220902203940.2385967-1-adhemerval.zanella@linaro.org> <20220902203940.2385967-11-adhemerval.zanella@linaro.org> <0358c009-eda0-ae01-5d63-69003e3fe375@linaro.org> In-Reply-To: <0358c009-eda0-ae01-5d63-69003e3fe375@linaro.org> From: Noah Goldstein Date: Mon, 19 Sep 2022 14:59:17 -0700 Message-ID: Subject: Re: [PATCH 10/17] string: Improve generic memchr To: Adhemerval Zanella Netto Cc: GNU C Library , Richard Henderson , Joseph Myers , caiyinyu Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.7 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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, Sep 19, 2022 at 12:17 PM Adhemerval Zanella Netto wrote: > > > > On 03/09/22 00:47, Noah Goldstein wrote: > > >> > >> - longword_ptr = (const longword *) char_ptr; > >> + /* Compute the address of the word containing the last byte. */ > >> + const op_t *lword = word_containing (lbyte); > >> > >> - /* All these elucidatory comments refer to 4-byte longwords, > >> - but the theory applies equally well to any size longwords. */ > >> + /* Read the first word, but munge it so that bytes before the array > >> + will not match goal. */ > >> + const op_t * word_ptr = word_containing (s); > >> + op_t word = (*word_ptr | before_mask) ^ (repeated_c & before_mask); > > > > Why do you xor with repeated_c & before_mask here? > > > > Doesn't the has_eq(word, repeated_c) do that? > > For the case of c_in being 0xff, since for this case or with before_mask > will make has_eq to return early. The test-memchr does not trigger it, > but test-memccpy does fail without the XOR. I see. Since a match in the first several bytes is fairly common maybe it would be better to special case the first iteration and just do has_eq(word, repeated_c) >> (CHAR_BIT * (addr % sizeof(addr)). The result can just be added to `s` if there is a match.