git: 3acea07c1873 - main - Restore the augmented strlen commentary

Mateusz Guzik mjg at FreeBSD.org
Mon Feb 8 19:15:32 UTC 2021


The branch main has been updated by mjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=3acea07c1873b1e4042f4a4fa8668745ee59f15b

commit 3acea07c1873b1e4042f4a4fa8668745ee59f15b
Author:     Mateusz Guzik <mjg at FreeBSD.org>
AuthorDate: 2021-02-07 19:53:34 +0000
Commit:     Mateusz Guzik <mjg at FreeBSD.org>
CommitDate: 2021-02-08 19:15:21 +0000

    Restore the augmented strlen commentary
    
    ... lost in revert
---
 lib/libc/string/strlen.c | 15 ++++-----------
 sys/libkern/strlen.c     | 15 ++++-----------
 2 files changed, 8 insertions(+), 22 deletions(-)

diff --git a/lib/libc/string/strlen.c b/lib/libc/string/strlen.c
index a862ffc245ca..2d1803b1e078 100644
--- a/lib/libc/string/strlen.c
+++ b/lib/libc/string/strlen.c
@@ -35,10 +35,6 @@ __FBSDID("$FreeBSD$");
 /*
  * Portable strlen() for 32-bit and 64-bit systems.
  *
- * Rationale: it is generally much more efficient to do word length
- * operations and avoid branches on modern computer systems, as
- * compared to byte-length operations with a lot of branches.
- *
  * The expression:
  *
  *	((x - 0x01....01) & ~x & 0x80....80)
@@ -46,15 +42,12 @@ __FBSDID("$FreeBSD$");
  * would evaluate to a non-zero value iff any of the bytes in the
  * original word is zero.
  *
- * On multi-issue processors, we can divide the above expression into:
- *	a)  (x - 0x01....01)
- *	b) (~x & 0x80....80)
- *	c) a & b
- *
- * Where, a) and b) can be partially computed in parallel.
- *
  * The algorithm above is found on "Hacker's Delight" by
  * Henry S. Warren, Jr.
+ *
+ * Note: this leaves performance on the table and each architecture
+ * would be best served with a tailor made routine instead, even if
+ * using the same trick.
  */
 
 /* Magic numbers for the algorithm */
diff --git a/sys/libkern/strlen.c b/sys/libkern/strlen.c
index a8c7964f69a3..1c4a2b954de3 100644
--- a/sys/libkern/strlen.c
+++ b/sys/libkern/strlen.c
@@ -34,10 +34,6 @@ __FBSDID("$FreeBSD$");
 /*
  * Portable strlen() for 32-bit and 64-bit systems.
  *
- * Rationale: it is generally much more efficient to do word length
- * operations and avoid branches on modern computer systems, as
- * compared to byte-length operations with a lot of branches.
- *
  * The expression:
  *
  *	((x - 0x01....01) & ~x & 0x80....80)
@@ -45,15 +41,12 @@ __FBSDID("$FreeBSD$");
  * would evaluate to a non-zero value iff any of the bytes in the
  * original word is zero.
  *
- * On multi-issue processors, we can divide the above expression into:
- *	a)  (x - 0x01....01)
- *	b) (~x & 0x80....80)
- *	c) a & b
- *
- * Where, a) and b) can be partially computed in parallel.
- *
  * The algorithm above is found on "Hacker's Delight" by
  * Henry S. Warren, Jr.
+ *
+ * Note: this leaves performance on the table and each architecture
+ * would be best served with a tailor made routine instead, even if
+ * using the same trick.
  */
 
 /* Magic numbers for the algorithm */


More information about the dev-commits-src-all mailing list