/*1* arch/alpha/lib/strchr.S2* Contributed by Richard Henderson ([email protected])3*4* Return the address of a given character within a null-terminated5* string, or null if it is not found.6*/78#include <asm/regdef.h>910.set noreorder11.set noat1213.align 314.globl strchr15.ent strchr16strchr:17.frame sp, 0, ra18.prologue 01920zapnot a1, 1, a1 # e0 : zero extend the search character21ldq_u t0, 0(a0) # .. e1 : load first quadword22sll a1, 8, t5 # e0 : replicate the search character23andnot a0, 7, v0 # .. e1 : align our loop pointer24or t5, a1, a1 # e0 :25lda t4, -1 # .. e1 : build garbage mask26sll a1, 16, t5 # e0 :27cmpbge zero, t0, t2 # .. e1 : bits set iff byte == zero28mskqh t4, a0, t4 # e0 :29or t5, a1, a1 # .. e1 :30sll a1, 32, t5 # e0 :31cmpbge zero, t4, t4 # .. e1 : bits set iff byte is garbage32or t5, a1, a1 # e0 :33xor t0, a1, t1 # .. e1 : make bytes == c zero34cmpbge zero, t1, t3 # e0 : bits set iff byte == c35or t2, t3, t0 # e1 : bits set iff char match or zero match36andnot t0, t4, t0 # e0 : clear garbage bits37bne t0, $found # .. e1 (zdb)3839$loop: ldq t0, 8(v0) # e0 :40addq v0, 8, v0 # .. e1 :41nop # e0 :42xor t0, a1, t1 # .. e1 (ev5 data stall)43cmpbge zero, t0, t2 # e0 : bits set iff byte == 044cmpbge zero, t1, t3 # .. e1 : bits set iff byte == c45or t2, t3, t0 # e0 :46beq t0, $loop # .. e1 (zdb)4748$found: negq t0, t1 # e0 : clear all but least set bit49and t0, t1, t0 # e1 (stall)5051and t0, t3, t1 # e0 : bit set iff byte was the char52beq t1, $retnull # .. e1 (zdb)5354and t0, 0xf0, t2 # e0 : binary search for that set bit55and t0, 0xcc, t3 # .. e1 :56and t0, 0xaa, t4 # e0 :57cmovne t2, 4, t2 # .. e1 :58cmovne t3, 2, t3 # e0 :59cmovne t4, 1, t4 # .. e1 :60addq t2, t3, t2 # e0 :61addq v0, t4, v0 # .. e1 :62addq v0, t2, v0 # e0 :63ret # .. e1 :6465$retnull:66mov zero, v0 # e0 :67ret # .. e1 :6869.end strchr707172