Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * arch/alpha/lib/strrchr.S
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  * Contributed by Richard Henderson (rth@tamu.edu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  * Return the address of the last occurrence of a given character
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  * within a null-terminated string, or null if it is not found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <asm/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <asm/regdef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) 	.set noreorder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) 	.set noat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 	.align 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 	.ent strrchr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 	.globl strrchr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) strrchr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 	.frame sp, 0, ra
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 	.prologue 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 	zapnot	a1, 1, a1	# e0    : zero extend our test character
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 	mov	zero, t6	# .. e1 : t6 is last match aligned addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 	sll	a1, 8, t5	# e0    : replicate our test character
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 	mov	zero, t8	# .. e1 : t8 is last match byte compare mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 	or	t5, a1, a1	# e0    :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 	ldq_u   t0, 0(a0)	# .. e1 : load first quadword
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 	sll	a1, 16, t5	# e0    :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 	andnot  a0, 7, v0	# .. e1 : align source addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	or	t5, a1, a1	# e0    :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 	lda	t4, -1		# .. e1 : build garbage mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	sll	a1, 32, t5	# e0    :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	cmpbge  zero, t0, t1	# .. e1 : bits set iff byte == zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	mskqh	t4, a0, t4	# e0    :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	or	t5, a1, a1	# .. e1 : character replication complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	xor	t0, a1, t2	# e0    : make bytes == c zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	cmpbge	zero, t4, t4	# .. e1 : bits set iff byte is garbage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	cmpbge  zero, t2, t3	# e0    : bits set iff byte == c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	andnot	t1, t4, t1	# .. e1 : clear garbage from null test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	andnot	t3, t4, t3	# e0    : clear garbage from char test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	bne	t1, $eos	# .. e1 : did we already hit the terminator?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	/* Character search main loop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) $loop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	ldq	t0, 8(v0)	# e0    : load next quadword
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	cmovne	t3, v0, t6	# .. e1 : save previous comparisons match
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 	cmovne	t3, t3, t8	# e0    :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	addq	v0, 8, v0	# .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	xor	t0, a1, t2	# e0    :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	cmpbge	zero, t0, t1	# .. e1 : bits set iff byte == zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	cmpbge	zero, t2, t3	# e0    : bits set iff byte == c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	beq	t1, $loop	# .. e1 : if we havnt seen a null, loop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	/* Mask out character matches after terminator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) $eos:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 	negq	t1, t4		# e0    : isolate first null byte match
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	and	t1, t4, t4	# e1    :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 	subq	t4, 1, t5	# e0    : build a mask of the bytes up to...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	or	t4, t5, t4	# e1    : ... and including the null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	and	t3, t4, t3	# e0    : mask out char matches after null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 	cmovne	t3, t3, t8	# .. e1 : save it, if match found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	cmovne	t3, v0, t6	# e0    :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 	/* Locate the address of the last matched character */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	/* Retain the early exit for the ev4 -- the ev5 mispredict penalty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 	   is 5 cycles -- the same as just falling through.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 	beq	t8, $retnull	# .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 	and	t8, 0xf0, t2	# e0    : binary search for the high bit set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 	cmovne	t2, t2, t8	# .. e1 (zdb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 	cmovne	t2, 4, t2	# e0    :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 	and	t8, 0xcc, t1	# .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 	cmovne	t1, t1, t8	# e0    :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 	cmovne	t1, 2, t1	# .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 	and	t8, 0xaa, t0	# e0    :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 	cmovne	t0, 1, t0	# .. e1 (zdb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 	addq	t2, t1, t1	# e0    :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 	addq	t6, t0, v0	# .. e1 : add our aligned base ptr to the mix
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 	addq	v0, t1, v0	# e0    :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) 	ret			# .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) $retnull:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) 	mov	zero, v0	# e0    :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) 	ret			# .. e1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) 	.end strrchr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) 	EXPORT_SYMBOL(strrchr)