/* SPDX-License-Identifier: GPL-2.0 */1/*2* arch/alpha/lib/ev67-strchr.S3* 21264 version contributed by Rick Gorton <[email protected]>4*5* Return the address of a given character within a null-terminated6* string, or null if it is not found.7*8* Much of the information about 21264 scheduling/coding comes from:9* Compiler Writer's Guide for the Alpha 2126410* abbreviated as 'CWG' in other comments here11* ftp.digital.com/pub/Digital/info/semiconductor/literature/dsc-library.html12* Scheduling notation:13* E - either cluster14* U - upper subcluster; U0 - subcluster U0; U1 - subcluster U115* L - lower subcluster; L0 - subcluster L0; L1 - subcluster L116* Try not to change the actual algorithm if possible for consistency.17*/18#include <linux/export.h>19#include <asm/regdef.h>2021.set noreorder22.set noat2324.align 425.globl strchr26.ent strchr27strchr:28.frame sp, 0, ra29.prologue 03031ldq_u t0, 0(a0) # L : load first quadword Latency=332and a1, 0xff, t3 # E : 00000000000000ch33insbl a1, 1, t5 # U : 000000000000ch0034insbl a1, 7, a2 # U : ch000000000000003536insbl t3, 6, a3 # U : 00ch00000000000037or t5, t3, a1 # E : 000000000000chch38andnot a0, 7, v0 # E : align our loop pointer39lda t4, -1 # E : build garbage mask4041mskqh t4, a0, t4 # U : only want relevant part of first quad42or a2, a3, a2 # E : chch00000000000043inswl a1, 2, t5 # E : 00000000chch000044inswl a1, 4, a3 # E : 0000chch000000004546or a1, a2, a1 # E : chch00000000chch47or a3, t5, t5 # E : 0000chchchch000048cmpbge zero, t0, t2 # E : bits set iff byte == zero49cmpbge zero, t4, t4 # E : bits set iff byte is garbage5051/* This quad is _very_ serialized. Lots of stalling happens */52or t5, a1, a1 # E : chchchchchchchch53xor t0, a1, t1 # E : make bytes == c zero54cmpbge zero, t1, t3 # E : bits set iff byte == c55or t2, t3, t0 # E : bits set iff char match or zero match5657andnot t0, t4, t0 # E : clear garbage bits58cttz t0, a2 # U0 : speculative (in case we get a match)59nop # E :60bne t0, $found # U :6162/*63* Yuk. This loop is going to stall like crazy waiting for the64* data to be loaded. Not much can be done about it unless it's65* unrolled multiple times - is that safe to do in kernel space?66* Or would exception handling recovery code do the trick here?67*/68$loop: ldq t0, 8(v0) # L : Latency=369addq v0, 8, v0 # E :70xor t0, a1, t1 # E :71cmpbge zero, t0, t2 # E : bits set iff byte == 07273cmpbge zero, t1, t3 # E : bits set iff byte == c74or t2, t3, t0 # E :75cttz t3, a2 # U0 : speculative (in case we get a match)76beq t0, $loop # U :7778$found: negq t0, t1 # E : clear all but least set bit79and t0, t1, t0 # E :80and t0, t3, t1 # E : bit set iff byte was the char81addq v0, a2, v0 # E : Add in the bit number from above8283cmoveq t1, $31, v0 # E : Two mapping slots, latency = 284nop85nop86ret # L0 :8788.end strchr89EXPORT_SYMBOL(strchr)909192