| 1 | /* SPDX-License-Identifier: GPL-2.0 */
|
| 2 | /*
|
| 3 | * arch/alpha/lib/strchr.S
|
| 4 | * Contributed by Richard Henderson (rth@tamu.edu)
|
| 5 | *
|
| 6 | * Return the address of a given character within a null-terminated
|
| 7 | * string, or null if it is not found.
|
| 8 | */
|
| 9 | |
| 10 | |
| 11 |
|
| 12 | .set noreorder
|
| 13 | .set noat
|
| 14 |
|
| 15 | .align 3
|
| 16 | .globl strchr
|
| 17 | .ent strchr
|
| 18 | strchr:
|
| 19 | .frame sp, 0, ra
|
| 20 | .prologue 0
|
| 21 |
|
| 22 | zapnot a1, 1, a1 |
| 23 | ldq_u t0, 0(a0) |
| 24 | sll a1, 8, t5 |
| 25 | andnot a0, 7, v0 |
| 26 | or t5, a1, a1 |
| 27 | lda t4, -1 |
| 28 | sll a1, 16, t5 |
| 29 | cmpbge zero, t0, t2 |
| 30 | mskqh t4, a0, t4 |
| 31 | or t5, a1, a1 |
| 32 | sll a1, 32, t5 |
| 33 | cmpbge zero, t4, t4 |
| 34 | or t5, a1, a1 |
| 35 | xor t0, a1, t1 |
| 36 | cmpbge zero, t1, t3 |
| 37 | or t2, t3, t0 |
| 38 | andnot t0, t4, t0 |
| 39 | bne t0, $found |
| 40 |
|
| 41 | $loop: ldq t0, 8(v0) |
| 42 | addq v0, 8, v0 |
| 43 | nop |
| 44 | xor t0, a1, t1 |
| 45 | cmpbge zero, t0, t2 |
| 46 | cmpbge zero, t1, t3 |
| 47 | or t2, t3, t0 |
| 48 | beq t0, $loop |
| 49 |
|
| 50 | $found: negq t0, t1 |
| 51 | and t0, t1, t0 |
| 52 |
|
| 53 | and t0, t3, t1 |
| 54 | beq t1, $retnull |
| 55 |
|
| 56 | and t0, 0xf0, t2 |
| 57 | and t0, 0xcc, t3 |
| 58 | and t0, 0xaa, t4 |
| 59 | cmovne t2, 4, t2 |
| 60 | cmovne t3, 2, t3 |
| 61 | cmovne t4, 1, t4 |
| 62 | addq t2, t3, t2 |
| 63 | addq v0, t4, v0 |
| 64 | addq v0, t2, v0 |
| 65 | ret |
| 66 |
|
| 67 | $retnull:
|
| 68 | mov zero, v0 |
| 69 | ret |
| 70 |
|
| 71 | .end strchr
|
| 72 | EXPORT_SYMBOL(strchr)
|