/* SPDX-License-Identifier: GPL-2.0 */1/*2* arch/alpha/lib/strchr.S3* Contributed by Richard Henderson ([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#include <linux/export.h>9#include <asm/regdef.h>1011.set noreorder12.set noat1314.align 315.globl strchr16.ent strchr17strchr:18.frame sp, 0, ra19.prologue 02021zapnot a1, 1, a1 # e0 : zero extend the search character22ldq_u t0, 0(a0) # .. e1 : load first quadword23sll a1, 8, t5 # e0 : replicate the search character24andnot a0, 7, v0 # .. e1 : align our loop pointer25or t5, a1, a1 # e0 :26lda t4, -1 # .. e1 : build garbage mask27sll a1, 16, t5 # e0 :28cmpbge zero, t0, t2 # .. e1 : bits set iff byte == zero29mskqh t4, a0, t4 # e0 :30or t5, a1, a1 # .. e1 :31sll a1, 32, t5 # e0 :32cmpbge zero, t4, t4 # .. e1 : bits set iff byte is garbage33or t5, a1, a1 # e0 :34xor t0, a1, t1 # .. e1 : make bytes == c zero35cmpbge zero, t1, t3 # e0 : bits set iff byte == c36or t2, t3, t0 # e1 : bits set iff char match or zero match37andnot t0, t4, t0 # e0 : clear garbage bits38bne t0, $found # .. e1 (zdb)3940$loop: ldq t0, 8(v0) # e0 :41addq v0, 8, v0 # .. e1 :42nop # e0 :43xor t0, a1, t1 # .. e1 (ev5 data stall)44cmpbge zero, t0, t2 # e0 : bits set iff byte == 045cmpbge zero, t1, t3 # .. e1 : bits set iff byte == c46or t2, t3, t0 # e0 :47beq t0, $loop # .. e1 (zdb)4849$found: negq t0, t1 # e0 : clear all but least set bit50and t0, t1, t0 # e1 (stall)5152and t0, t3, t1 # e0 : bit set iff byte was the char53beq t1, $retnull # .. e1 (zdb)5455and t0, 0xf0, t2 # e0 : binary search for that set bit56and t0, 0xcc, t3 # .. e1 :57and t0, 0xaa, t4 # e0 :58cmovne t2, 4, t2 # .. e1 :59cmovne t3, 2, t3 # e0 :60cmovne t4, 1, t4 # .. e1 :61addq t2, t3, t2 # e0 :62addq v0, t4, v0 # .. e1 :63addq v0, t2, v0 # e0 :64ret # .. e1 :6566$retnull:67mov zero, v0 # e0 :68ret # .. e1 :6970.end strchr71EXPORT_SYMBOL(strchr)727374