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 915443858009 for ; Sun, 20 Mar 2022 04:41:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 915443858009 Received: by mail-pg1-x530.google.com with SMTP id bc27so8014731pgb.4 for ; Sat, 19 Mar 2022 21:41:20 -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=IzmJPSN421UOOZqgQnHHilZQmU1qf0jKUiA72naaLkE=; b=XFT09q1c8hFvC9QzePnGKcBWaK3USbwBwqXHpx6gIViH+GfPbzYOMu3mD++LZHLy8h r/UpXFBpj1CVp9Bbq0booNSwAL7vuf43QgjfP4L7dCKGS9jaaRk6OdR251kMjhAy6LZX +faiEYuJ5w25x8h3RCP38Ck1m9W3P0f4KZF/O/uqtuedQZuyjp0PkT4+ThYdUkkkSaxX 4UD2U/2sOciqAmPTSjyKh5DIy3xmmsHnsSjij/15vn4tLf16OzbY+GY8l5rSvLNPj9h8 HHurH27bPPiJqf1KHsLs5vTGHv32gCSZbaqB5q4DWe4OywKOTcz0b7ImJvuFF6cgx14K TQJg== X-Gm-Message-State: AOAM531cCR6E/NSemq9lFFf6nf66w7y6Ub1ZkmoXg33MUuQ/8ITdy5HV pLoaQJrcRVM4Uflwdf/rcGWkmi6CptAVPpGJptOva9pOjlY= X-Google-Smtp-Source: ABdhPJwuSmhF1YmkEqSALJsbe0BrOHx5CJVsA54GG9+u8C1quytqnPSZmm2aqRneEpYoMYySqlaeCDpxSnmPCpLVWsE= X-Received: by 2002:a05:6a00:3404:b0:4fa:8dcb:6da2 with SMTP id cn4-20020a056a00340400b004fa8dcb6da2mr2806964pfb.19.1647751279484; Sat, 19 Mar 2022 21:41:19 -0700 (PDT) MIME-Version: 1.0 References: <20220320010442.991728-1-bluepenguin@gmail.com> In-Reply-To: <20220320010442.991728-1-bluepenguin@gmail.com> From: Noah Goldstein Date: Sat, 19 Mar 2022 23:41:08 -0500 Message-ID: Subject: Re: [PATCH] string: Replace outdated comments in strlen(). To: Ricardo Bittencourt Cc: GNU C Library Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.1 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Sun, 20 Mar 2022 04:41:22 -0000 On Sat, Mar 19, 2022 at 8:05 PM Ricardo Bittencourt via Libc-alpha wrote: > > Copyright The GNU Toolchain Authors. > > The comments on strlen() don't match what the actual code does. They > describe an older algorithm which is no longer in use. This change > replace the old comments with new ones describing the algorithm used. > > I am a first time contributor, and I believe there is no need for > copyright assignment, since the file changed is not in the shared > source files list. > > This patch only changes comments, but for safety I have run the tests in > my x64 ubuntu machine, with the following results: > > Summary of test results: > 5051 PASS > 80 UNSUPPORTED > 16 XFAIL > 6 XPASS > > Signed-off-by: Ricardo Bittencourt > --- > string/strlen.c | 16 +++++----------- > 1 file changed, 5 insertions(+), 11 deletions(-) > > diff --git a/string/strlen.c b/string/strlen.c > index 0b8aefb812..54f3fb8167 100644 > --- a/string/strlen.c > +++ b/string/strlen.c > @@ -46,15 +46,10 @@ STRLEN (const char *str) > > longword_ptr = (unsigned long int *) char_ptr; > > - /* Bits 31, 24, 16, and 8 of this number are zero. Call these bits > - the "holes." Note that there is a hole just to the left of > - each byte, with an extra at the end: > - > - bits: 01111110 11111110 11111110 11111111 > - bytes: AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD > - > - The 1-bits make sure that carries propagate to the next 0-bit. > - The 0-bits provide holes for carries to fall into. */ > + /* Computing (longword - lomagic) sets the high bit of any corresponding > + byte that is either zero or greater than 0x80. The latter case can be > + filtered out by computing (~longword & himagic). The final result > + will always be non-zero if one of the bytes of longword is zero. */ > himagic = 0x80808080L; > lomagic = 0x01010101L; > if (sizeof (longword) > 4) > @@ -76,8 +71,7 @@ STRLEN (const char *str) > > if (((longword - lomagic) & ~longword & himagic) != 0) > { > - /* Which of the bytes was the zero? If none of them were, it was > - a misfire; continue the search. */ > + /* Which of the bytes was the zero? */ > > const char *cp = (const char *) (longword_ptr - 1); > > -- > 2.25.1 > LGTM. But wait to commit until monday so others can give feedback if they want to.