/*1* arch/alpha/lib/ev67-strrchr.S2* 21264 version by Rick Gorton <[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*10* Much of the information about 21264 scheduling/coding comes from:11* Compiler Writer's Guide for the Alpha 2126412* abbreviated as 'CWG' in other comments here13* ftp.digital.com/pub/Digital/info/semiconductor/literature/dsc-library.html14* Scheduling notation:15* E - either cluster16* U - upper subcluster; U0 - subcluster U0; U1 - subcluster U117* L - lower subcluster; L0 - subcluster L0; L1 - subcluster L118*/192021#include <asm/regdef.h>2223.set noreorder24.set noat2526.align 427.ent strrchr28.globl strrchr29strrchr:30.frame sp, 0, ra31.prologue 03233and a1, 0xff, t2 # E : 00000000000000ch34insbl a1, 1, t4 # U : 000000000000ch0035insbl a1, 2, t5 # U : 0000000000ch000036ldq_u t0, 0(a0) # L : load first quadword Latency=33738mov zero, t6 # E : t6 is last match aligned addr39or t2, t4, a1 # E : 000000000000chch40sll t5, 8, t3 # U : 00000000ch00000041mov zero, t8 # E : t8 is last match byte compare mask4243andnot a0, 7, v0 # E : align source addr44or t5, t3, t3 # E : 00000000chch000045sll a1, 32, t2 # U : 0000chch0000000046sll a1, 48, t4 # U : chch0000000000004748or t4, a1, a1 # E : chch00000000chch49or t2, t3, t2 # E : 0000chchchch000050or a1, t2, a1 # E : chchchchchchchch51lda t5, -1 # E : build garbage mask5253cmpbge zero, t0, t1 # E : bits set iff byte == zero54mskqh t5, a0, t4 # E : Complete garbage mask55xor t0, a1, t2 # E : make bytes == c zero56cmpbge zero, t4, t4 # E : bits set iff byte is garbage5758cmpbge zero, t2, t3 # E : bits set iff byte == c59andnot t1, t4, t1 # E : clear garbage from null test60andnot t3, t4, t3 # E : clear garbage from char test61bne t1, $eos # U : did we already hit the terminator?6263/* Character search main loop */64$loop:65ldq t0, 8(v0) # L : load next quadword66cmovne t3, v0, t6 # E : save previous comparisons match67nop # : Latency=2, extra map slot (keep nop with cmov)68nop6970cmovne t3, t3, t8 # E : Latency=2, extra map slot71nop # : keep with cmovne72addq v0, 8, v0 # E :73xor t0, a1, t2 # E :7475cmpbge zero, t0, t1 # E : bits set iff byte == zero76cmpbge zero, t2, t3 # E : bits set iff byte == c77beq t1, $loop # U : if we havnt seen a null, loop78nop7980/* Mask out character matches after terminator */81$eos:82negq t1, t4 # E : isolate first null byte match83and t1, t4, t4 # E :84subq t4, 1, t5 # E : build a mask of the bytes up to...85or t4, t5, t4 # E : ... and including the null8687and t3, t4, t3 # E : mask out char matches after null88cmovne t3, t3, t8 # E : save it, if match found Latency=2, extra map slot89nop # : Keep with cmovne90nop9192cmovne t3, v0, t6 # E :93nop # : Keep with cmovne94/* Locate the address of the last matched character */95ctlz t8, t2 # U0 : Latency=3 (0x40 for t8=0)96nop9798cmoveq t8, 0x3f, t2 # E : Compensate for case when no match is seen99nop # E : hide the cmov latency (2) behind ctlz latency100lda t5, 0x3f($31) # E :101subq t5, t2, t5 # E : Normalize leading zero count102103addq t6, t5, v0 # E : and add to quadword address104ret # L0 : Latency=3105nop106nop107108.end strrchr109110111