65816-llvm-mos/benchmarks/strLen.c
2026-05-18 14:43:35 -05:00

14 lines
524 B
C

// strLen: walk pointer until null byte. Exercises the [dp],Y byte-read
// path plus the conditional loop exit. Touches the same DPF0 setup
// pattern as strcpy/memcmp but with only ONE pointer per iter.
//
// The pragma prevents clang from recognising this as a builtin strlen
// and rewriting it as a call to libc (which our benches don't link).
__attribute__((no_builtin("strlen")))
unsigned short strLen(const char *s) {
const char *p = s;
while (*p) {
p++;
}
return (unsigned short)(p - s);
}