summaryrefslogtreecommitdiffstats
path: root/src/bfstd.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2025-02-21 13:38:16 -0500
committerTavian Barnes <tavianator@tavianator.com>2025-02-21 13:38:16 -0500
commitaf3bfcccc484ace662c78f053f633bc883c73152 (patch)
tree386ebca53ab56b405103c2c7c519ca2dad2e7c5f /src/bfstd.c
parent504dd8e9a551c75d6e83ab0d328a2d482d8b48d5 (diff)
downloadbfs-af3bfcccc484ace662c78f053f633bc883c73152.tar.xz
Micro-optimize word-at-a-time loop tails
Compilers apparently aren't smart enough to infer that the odd tail length fixup "loops" run at most once, and could be converted to ifs, so do that manually.
Diffstat (limited to 'src/bfstd.c')
-rw-r--r--src/bfstd.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/bfstd.c b/src/bfstd.c
index f2938ad..219b8d0 100644
--- a/src/bfstd.c
+++ b/src/bfstd.c
@@ -786,7 +786,7 @@ size_t asciinlen(const char *str, size_t n) {
// Word-at-a-time isascii()
#define CHUNK(n) CHUNK_(uint##n##_t, load8_leu##n)
#define CHUNK_(type, load8) \
- while (n - i >= sizeof(type)) { \
+ (n - i >= sizeof(type)) { \
type word = load8(ustr + i); \
type mask = (((type)-1) / 0xFF) << 7; /* 0x808080.. */ \
word &= mask; \
@@ -797,11 +797,13 @@ size_t asciinlen(const char *str, size_t n) {
}
#if SIZE_WIDTH >= 64
- CHUNK(64);
+ while CHUNK(64);
+ if CHUNK(32);
+#else
+ while CHUNK(32);
#endif
- CHUNK(32);
- CHUNK(16);
- CHUNK(8);
+ if CHUNK(16);
+ if CHUNK(8);
#undef CHUNK_
#undef CHUNK