/* SPDX-License-Identifier: GPL-2.0 */1/*2* strlen.S (c) 1995 David Mosberger ([email protected])3*4* Finds length of a 0-terminated string. Optimized for the5* Alpha architecture:6*7* - memory accessed as aligned quadwords only8* - uses bcmpge to compare 8 bytes in parallel9* - does binary search to find 0 byte in last10* quadword (HAKMEM needed 12 instructions to11* do this instead of the 9 instructions that12* binary search needs).13*/14#include <linux/export.h>15.set noreorder16.set noat1718.align 31920.globl strlen21.ent strlen2223strlen:24ldq_u $1, 0($16) # load first quadword ($16 may be misaligned)25lda $2, -1($31)26insqh $2, $16, $227andnot $16, 7, $028or $2, $1, $129cmpbge $31, $1, $2 # $2 <- bitmask: bit i == 1 <==> i-th byte == 030bne $2, found3132loop: ldq $1, 8($0)33addq $0, 8, $0 # addr += 834nop # helps dual issue last two insns35cmpbge $31, $1, $236beq $2, loop3738found: blbs $2, done # make aligned case fast39negq $2, $340and $2, $3, $24142and $2, 0x0f, $143addq $0, 4, $344cmoveq $1, $3, $04546and $2, 0x33, $147addq $0, 2, $348cmoveq $1, $3, $04950and $2, 0x55, $151addq $0, 1, $352cmoveq $1, $3, $05354done: subq $0, $16, $055ret $31, ($26)5657.end strlen58EXPORT_SYMBOL(strlen)596061