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

11 lines
424 B
C

// djb2 string hash. Exercises i32 arithmetic in a tight pointer-walk
// loop — hash << 5 + hash + c. Hits the i32 shift inline path and the
// byte-load pattern in the same loop body. Real-world: every hash
// table keyed by strings uses something like this.
unsigned long djb2Hash(const char *s) {
unsigned long h = 5381;
while (*s) {
h = ((h << 5) + h) + (unsigned char)(*s++);
}
return h;
}