Blame sysdeps/alpha/strncpy.S

Packit 6c4009
/* Copyright (C) 1996-2018 Free Software Foundation, Inc.
Packit 6c4009
   Contributed by Richard Henderson (rth@tamu.edu)
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library.  If not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
/* Copy no more than COUNT bytes of the null-terminated string from
Packit 6c4009
   SRC to DST.  If SRC does not cover all of COUNT, the balance is
Packit 6c4009
   zeroed.  */
Packit 6c4009
Packit 6c4009
#include <sysdep.h>
Packit 6c4009
Packit 6c4009
	.set noat
Packit 6c4009
	.set noreorder
Packit 6c4009
Packit 6c4009
	.text
Packit 6c4009
Packit 6c4009
ENTRY(strncpy)
Packit 6c4009
	ldgp	gp, 0(pv)
Packit 6c4009
#ifdef PROF
Packit 6c4009
	lda	AT, _mcount
Packit 6c4009
	jsr	AT, (AT), _mcount
Packit 6c4009
#endif
Packit 6c4009
	.prologue 1
Packit 6c4009
Packit 6c4009
	mov	a0, v0		# set return value now
Packit 6c4009
	beq	a2, $zerocount
Packit 6c4009
	jsr	t9, __stxncpy	# do the work of the copy
Packit 6c4009
Packit 6c4009
	bne	a2, $multiword	# do we have full words left?
Packit 6c4009
Packit 6c4009
	.align 3
Packit 6c4009
	subq	t8, 1, t2	# e0    : guess not
Packit 6c4009
	subq	t10, 1, t3	# .. e1 :
Packit 6c4009
	or	t2, t8, t2	# e0    : clear the bits between the last
Packit 6c4009
	or	t3, t10, t3	# .. e1 : written byte and the last byte in
Packit 6c4009
	andnot	t3, t2, t3	# e0    : COUNT
Packit 6c4009
	zap	t0, t3, t0	# e1    :
Packit 6c4009
	stq_u	t0, 0(a0)	# e0    :
Packit 6c4009
	ret			# .. e1 :
Packit 6c4009
Packit 6c4009
$multiword:
Packit 6c4009
	subq	t8, 1, t7	# e0    : clear the final bits in the prev
Packit 6c4009
	or	t7, t8, t7	# e1    : word
Packit 6c4009
	zapnot	t0, t7, t0	# e0    :
Packit 6c4009
	subq	a2, 1, a2	# .. e1 :
Packit 6c4009
	stq_u	t0, 0(a0)	# e0    :
Packit 6c4009
	addq	a0, 8, a0	# .. e1 :
Packit 6c4009
Packit 6c4009
	beq	a2, 1f		# e1    :
Packit 6c4009
	blbc	a2, 0f		# e1    :
Packit 6c4009
Packit 6c4009
	stq_u	zero, 0(a0)	# e0    : zero one word
Packit 6c4009
	subq	a2, 1, a2	# .. e1 :
Packit 6c4009
	addq	a0, 8, a0	# e0    :
Packit 6c4009
	beq	a2, 1f		# .. e1 :
Packit 6c4009
Packit 6c4009
0:	stq_u	zero, 0(a0)	# e0    : zero two words
Packit 6c4009
	subq	a2, 2, a2	# .. e1 :
Packit 6c4009
	stq_u	zero, 8(a0)	# e0    :
Packit 6c4009
	addq	a0, 16, a0	# .. e1 :
Packit 6c4009
	bne	a2, 0b		# e1    :
Packit 6c4009
	unop
Packit 6c4009
Packit 6c4009
1:	ldq_u	t0, 0(a0)	# e0    : clear the leading bits in the final
Packit 6c4009
	subq	t10, 1, t7	# .. e1 : word
Packit 6c4009
	or	t7, t10, t7	# e0    :
Packit 6c4009
	zap	t0, t7, t0	# e1 (stall)
Packit 6c4009
	stq_u	t0, 0(a0)	# e0    :
Packit 6c4009
Packit 6c4009
$zerocount:
Packit 6c4009
	ret			# .. e1 :
Packit 6c4009
Packit 6c4009
	END(strncpy)
Packit 6c4009
libc_hidden_builtin_def (strncpy)