18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * arch/alpha/lib/ev67-strlen.S 48c2ecf20Sopenharmony_ci * 21264 version by Rick Gorton <rick.gorton@alpha-processor.com> 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Finds length of a 0-terminated string. Optimized for the 78c2ecf20Sopenharmony_ci * Alpha architecture: 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * - memory accessed as aligned quadwords only 108c2ecf20Sopenharmony_ci * - uses bcmpge to compare 8 bytes in parallel 118c2ecf20Sopenharmony_ci * 128c2ecf20Sopenharmony_ci * Much of the information about 21264 scheduling/coding comes from: 138c2ecf20Sopenharmony_ci * Compiler Writer's Guide for the Alpha 21264 148c2ecf20Sopenharmony_ci * abbreviated as 'CWG' in other comments here 158c2ecf20Sopenharmony_ci * ftp.digital.com/pub/Digital/info/semiconductor/literature/dsc-library.html 168c2ecf20Sopenharmony_ci * Scheduling notation: 178c2ecf20Sopenharmony_ci * E - either cluster 188c2ecf20Sopenharmony_ci * U - upper subcluster; U0 - subcluster U0; U1 - subcluster U1 198c2ecf20Sopenharmony_ci * L - lower subcluster; L0 - subcluster L0; L1 - subcluster L1 208c2ecf20Sopenharmony_ci */ 218c2ecf20Sopenharmony_ci#include <asm/export.h> 228c2ecf20Sopenharmony_ci .set noreorder 238c2ecf20Sopenharmony_ci .set noat 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci .globl strlen 268c2ecf20Sopenharmony_ci .ent strlen 278c2ecf20Sopenharmony_ci .align 4 288c2ecf20Sopenharmony_cistrlen: 298c2ecf20Sopenharmony_ci ldq_u $1, 0($16) # L : load first quadword ($16 may be misaligned) 308c2ecf20Sopenharmony_ci lda $2, -1($31) # E : 318c2ecf20Sopenharmony_ci insqh $2, $16, $2 # U : 328c2ecf20Sopenharmony_ci andnot $16, 7, $0 # E : 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci or $2, $1, $1 # E : 358c2ecf20Sopenharmony_ci cmpbge $31, $1, $2 # E : $2 <- bitmask: bit i == 1 <==> i-th byte == 0 368c2ecf20Sopenharmony_ci nop # E : 378c2ecf20Sopenharmony_ci bne $2, $found # U : 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci$loop: ldq $1, 8($0) # L : 408c2ecf20Sopenharmony_ci addq $0, 8, $0 # E : addr += 8 418c2ecf20Sopenharmony_ci cmpbge $31, $1, $2 # E : 428c2ecf20Sopenharmony_ci beq $2, $loop # U : 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci$found: 458c2ecf20Sopenharmony_ci cttz $2, $3 # U0 : 468c2ecf20Sopenharmony_ci addq $0, $3, $0 # E : 478c2ecf20Sopenharmony_ci subq $0, $16, $0 # E : 488c2ecf20Sopenharmony_ci ret $31, ($26) # L0 : 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci .end strlen 518c2ecf20Sopenharmony_ci EXPORT_SYMBOL(strlen) 52