| * strlen.S (c) 1995 David Mosberger (davidm@cs.arizona.edu) |
| * Finds length of a 0-terminated string. Optimized for the |
| * - memory accessed as aligned quadwords only |
| * - uses bcmpge to compare 8 bytes in parallel |
| * - does binary search to find 0 byte in last |
| * quadword (HAKMEM needed 12 instructions to |
| * do this instead of the 9 instructions that |
| ldq_u $1, 0($16) # load first quadword ($16 may be misaligned) |
| cmpbge $31, $1, $2 # $2 <- bitmask: bit i == 1 <==> i-th byte == 0 |
| addq $0, 8, $0 # addr += 8 |
| nop # helps dual issue last two insns |
| found: blbs $2, done # make aligned case fast |