From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7844) id C37C43858C51; Sat, 9 Apr 2022 16:45:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C37C43858C51 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Noah Goldstein To: glibc-cvs@sourceware.org Subject: [glibc] string: Replace outdated comments in strlen(). X-Act-Checkin: glibc X-Git-Author: Ricardo Bittencourt X-Git-Refname: refs/heads/master X-Git-Oldrev: 5325233313c66aea13e86f5dd59618e9dd74b510 X-Git-Newrev: c0efbf8920844b940b85ea340ea2eaee70da2fc0 Message-Id: <20220409164556.C37C43858C51@sourceware.org> Date: Sat, 9 Apr 2022 16:45:56 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Apr 2022 16:45:56 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c0efbf8920844b940b85ea340ea2eaee70da2fc0 commit c0efbf8920844b940b85ea340ea2eaee70da2fc0 Author: Ricardo Bittencourt Date: Sat Mar 19 22:04:42 2022 -0300 string: Replace outdated comments in strlen(). 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 Diff: --- 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);