162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * arch/alpha/lib/ev67-strcat.S
462306a36Sopenharmony_ci * 21264 version contributed by Rick Gorton <rick.gorton@alpha-processor.com>
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Append a null-terminated string from SRC to DST.
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci * Much of the information about 21264 scheduling/coding comes from:
962306a36Sopenharmony_ci *	Compiler Writer's Guide for the Alpha 21264
1062306a36Sopenharmony_ci *	abbreviated as 'CWG' in other comments here
1162306a36Sopenharmony_ci *	ftp.digital.com/pub/Digital/info/semiconductor/literature/dsc-library.html
1262306a36Sopenharmony_ci * Scheduling notation:
1362306a36Sopenharmony_ci *	E	- either cluster
1462306a36Sopenharmony_ci *	U	- upper subcluster; U0 - subcluster U0; U1 - subcluster U1
1562306a36Sopenharmony_ci *	L	- lower subcluster; L0 - subcluster L0; L1 - subcluster L1
1662306a36Sopenharmony_ci * Try not to change the actual algorithm if possible for consistency.
1762306a36Sopenharmony_ci * Commentary: It seems bogus to walk the input string twice - once
1862306a36Sopenharmony_ci * to determine the length, and then again while doing the copy.
1962306a36Sopenharmony_ci * A significant (future) enhancement would be to only read the input
2062306a36Sopenharmony_ci * string once.
2162306a36Sopenharmony_ci */
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci#include <linux/export.h>
2462306a36Sopenharmony_ci	.text
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci	.align 4
2762306a36Sopenharmony_ci	.globl strcat
2862306a36Sopenharmony_ci	.ent strcat
2962306a36Sopenharmony_cistrcat:
3062306a36Sopenharmony_ci	.frame $30, 0, $26
3162306a36Sopenharmony_ci	.prologue 0
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci	mov	$16, $0		# E : set up return value
3462306a36Sopenharmony_ci	/* Find the end of the string.  */
3562306a36Sopenharmony_ci	ldq_u   $1, 0($16)	# L : load first quadword (a0 may be misaligned)
3662306a36Sopenharmony_ci	lda     $2, -1		# E :
3762306a36Sopenharmony_ci	insqh   $2, $16, $2	# U :
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci	andnot  $16, 7, $16	# E :
4062306a36Sopenharmony_ci	or      $2, $1, $1	# E :
4162306a36Sopenharmony_ci	cmpbge  $31, $1, $2	# E : bits set iff byte == 0
4262306a36Sopenharmony_ci	bne     $2, $found	# U :
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci$loop:	ldq     $1, 8($16)	# L :
4562306a36Sopenharmony_ci	addq    $16, 8, $16	# E :
4662306a36Sopenharmony_ci	cmpbge  $31, $1, $2	# E :
4762306a36Sopenharmony_ci	beq     $2, $loop	# U :
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci$found:	cttz	$2, $3		# U0 :
5062306a36Sopenharmony_ci	addq	$16, $3, $16	# E :
5162306a36Sopenharmony_ci	/* Now do the append.  */
5262306a36Sopenharmony_ci	mov	$26, $23	# E :
5362306a36Sopenharmony_ci	br	__stxcpy	# L0 :
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci	.end strcat
5662306a36Sopenharmony_ci	EXPORT_SYMBOL(strcat)
57