/*1* strlen.S (c) 1995 David Mosberger ([email protected])2*3* Finds length of a 0-terminated string. Optimized for the4* Alpha architecture:5*6* - memory accessed as aligned quadwords only7* - uses bcmpge to compare 8 bytes in parallel8* - does binary search to find 0 byte in last9* quadword (HAKMEM needed 12 instructions to10* do this instead of the 9 instructions that11* binary search needs).12*/1314.set noreorder15.set noat1617.align 31819.globl strlen20.ent strlen2122strlen:23ldq_u $1, 0($16) # load first quadword ($16 may be misaligned)24lda $2, -1($31)25insqh $2, $16, $226andnot $16, 7, $027or $2, $1, $128cmpbge $31, $1, $2 # $2 <- bitmask: bit i == 1 <==> i-th byte == 029bne $2, found3031loop: ldq $1, 8($0)32addq $0, 8, $0 # addr += 833nop # helps dual issue last two insns34cmpbge $31, $1, $235beq $2, loop3637found: blbs $2, done # make aligned case fast38negq $2, $339and $2, $3, $24041and $2, 0x0f, $142addq $0, 4, $343cmoveq $1, $3, $04445and $2, 0x33, $146addq $0, 2, $347cmoveq $1, $3, $04849and $2, 0x55, $150addq $0, 1, $351cmoveq $1, $3, $05253done: subq $0, $16, $054ret $31, ($26)5556.end strlen575859