/** strlen.S (c) 1995 David Mosberger (davidm@cs.arizona.edu)** Finds length of a 0-terminated string. Optimized for the* Alpha architecture:** - 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* binary search needs).*/.set noreorder.set noat.align 3.globl strlen.ent strlenstrlen:ldq_u $1, 0($16) # load first quadword ($16 may be misaligned)lda $2, -1($31)insqh $2, $16, $2andnot $16, 7, $0or $2, $1, $1cmpbge $31, $1, $2 # $2 <- bitmask: bit i == 1 <==> i-th byte == 0bne $2, foundloop: ldq $1, 8($0)addq $0, 8, $0 # addr += 8nop # helps dual issue last two insnscmpbge $31, $1, $2beq $2, loopfound: blbs $2, done # make aligned case fastnegq $2, $3and $2, $3, $2and $2, 0x0f, $1addq $0, 4, $3cmoveq $1, $3, $0and $2, 0x33, $1addq $0, 2, $3cmoveq $1, $3, $0and $2, 0x55, $1addq $0, 1, $3cmoveq $1, $3, $0done: subq $0, $16, $0ret $31, ($26).end strlen
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。