From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id 1149B385840C for ; Sun, 20 Mar 2022 01:04:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1149B385840C Received: by mail-ot1-x334.google.com with SMTP id a17-20020a9d3e11000000b005cb483c500dso3813679otd.6 for ; Sat, 19 Mar 2022 18:04:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=veYjyN/tQlmc69HzxGzG05H2ngblzEpW4VCR3L3u3bI=; b=xCKkIyhpPhk55KIOseNrR3yE3oak5xqtlNwFYBlqZK23zg7n/nqQPKaks1h9P0Vklh 9Kc0MyStWA8ukZwHehNChFdqzVH1KYLMncbcZfXVhpdpQRsQQ5ofY+bj/q2ygnTKLIxq ywD5+Eex9CkNPmlkZ3eJA58PpPqhLwx1P9xzSHGU0K4+PsaeyA1rLfqsWf6SqTO9f9/H pl1vcEbfjIkG+DVZmQNRP3fkl0StRl8anEJjRcwqjwEt5zcx6ptBHXMWGyR0CSweIHLc YHFmZmSfNX23sgLczMnWovwBAyP1IX6uvDAoYQgZUvEiek2nR+WxUqnPigFNGR8iaaWQ yACQ== X-Gm-Message-State: AOAM532+0VOsks8+ligXr9B2261OaFUWhRGtWdavibJQG0R7DbCTBDa5 u+lUHNvpuEqV8b+NsEuGDXd8zloYa2w= X-Google-Smtp-Source: ABdhPJwZL19J05pobWAtYVD6mCq4ouykjYOIjjspTJg14iW0mGbx5phUmbsBmOU4Fmv6jtAHznTpHw== X-Received: by 2002:a9d:7d03:0:b0:5c5:6784:147c with SMTP id v3-20020a9d7d03000000b005c56784147cmr5622589otn.6.1647738289218; Sat, 19 Mar 2022 18:04:49 -0700 (PDT) Received: from localhost.localdomain ([189.120.77.91]) by smtp.googlemail.com with ESMTPSA id 190-20020a4a0dc7000000b003244ae0bbd5sm5283334oob.7.2022.03.19.18.04.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Mar 2022 18:04:48 -0700 (PDT) From: Ricardo Bittencourt To: libc-alpha@sourceware.org Cc: Ricardo Bittencourt Subject: [PATCH] string: Replace outdated comments in strlen(). Date: Sat, 19 Mar 2022 22:04:42 -0300 Message-Id: <20220320010442.991728-1-bluepenguin@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, 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 01:04:54 -0000 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