18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * arch/alpha/lib/ev67-strcat.S
48c2ecf20Sopenharmony_ci * 21264 version contributed by Rick Gorton <rick.gorton@alpha-processor.com>
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Append a null-terminated string from SRC to DST.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Much of the information about 21264 scheduling/coding comes from:
98c2ecf20Sopenharmony_ci *	Compiler Writer's Guide for the Alpha 21264
108c2ecf20Sopenharmony_ci *	abbreviated as 'CWG' in other comments here
118c2ecf20Sopenharmony_ci *	ftp.digital.com/pub/Digital/info/semiconductor/literature/dsc-library.html
128c2ecf20Sopenharmony_ci * Scheduling notation:
138c2ecf20Sopenharmony_ci *	E	- either cluster
148c2ecf20Sopenharmony_ci *	U	- upper subcluster; U0 - subcluster U0; U1 - subcluster U1
158c2ecf20Sopenharmony_ci *	L	- lower subcluster; L0 - subcluster L0; L1 - subcluster L1
168c2ecf20Sopenharmony_ci * Try not to change the actual algorithm if possible for consistency.
178c2ecf20Sopenharmony_ci * Commentary: It seems bogus to walk the input string twice - once
188c2ecf20Sopenharmony_ci * to determine the length, and then again while doing the copy.
198c2ecf20Sopenharmony_ci * A significant (future) enhancement would be to only read the input
208c2ecf20Sopenharmony_ci * string once.
218c2ecf20Sopenharmony_ci */
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#include <asm/export.h>
248c2ecf20Sopenharmony_ci	.text
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci	.align 4
278c2ecf20Sopenharmony_ci	.globl strcat
288c2ecf20Sopenharmony_ci	.ent strcat
298c2ecf20Sopenharmony_cistrcat:
308c2ecf20Sopenharmony_ci	.frame $30, 0, $26
318c2ecf20Sopenharmony_ci	.prologue 0
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	mov	$16, $0		# E : set up return value
348c2ecf20Sopenharmony_ci	/* Find the end of the string.  */
358c2ecf20Sopenharmony_ci	ldq_u   $1, 0($16)	# L : load first quadword (a0 may be misaligned)
368c2ecf20Sopenharmony_ci	lda     $2, -1		# E :
378c2ecf20Sopenharmony_ci	insqh   $2, $16, $2	# U :
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci	andnot  $16, 7, $16	# E :
408c2ecf20Sopenharmony_ci	or      $2, $1, $1	# E :
418c2ecf20Sopenharmony_ci	cmpbge  $31, $1, $2	# E : bits set iff byte == 0
428c2ecf20Sopenharmony_ci	bne     $2, $found	# U :
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci$loop:	ldq     $1, 8($16)	# L :
458c2ecf20Sopenharmony_ci	addq    $16, 8, $16	# E :
468c2ecf20Sopenharmony_ci	cmpbge  $31, $1, $2	# E :
478c2ecf20Sopenharmony_ci	beq     $2, $loop	# U :
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci$found:	cttz	$2, $3		# U0 :
508c2ecf20Sopenharmony_ci	addq	$16, $3, $16	# E :
518c2ecf20Sopenharmony_ci	/* Now do the append.  */
528c2ecf20Sopenharmony_ci	mov	$26, $23	# E :
538c2ecf20Sopenharmony_ci	br	__stxcpy	# L0 :
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci	.end strcat
568c2ecf20Sopenharmony_ci	EXPORT_SYMBOL(strcat)
57