Blame sysdeps/alpha/bzero.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
/* Fill a block of memory with zeros.  Optimized for the Alpha architecture:
Packit 6c4009
Packit 6c4009
   - memory accessed as aligned quadwords only
Packit 6c4009
   - destination memory not read unless needed for good cache behaviour
Packit 6c4009
   - basic blocks arranged to optimize branch prediction for full-quadword
Packit 6c4009
     aligned memory blocks.
Packit 6c4009
   - partial head and tail quadwords constructed with byte-mask instructions
Packit 6c4009
Packit 6c4009
   This is generally scheduled for the EV5 (got to look out for my own
Packit 6c4009
   interests :-), but with EV4 needs in mind.  There *should* be no more
Packit 6c4009
   stalls for the EV4 than there are for the EV5.
Packit 6c4009
*/
Packit 6c4009
Packit 6c4009
Packit 6c4009
#include <sysdep.h>
Packit 6c4009
Packit 6c4009
	.set noat
Packit 6c4009
	.set noreorder
Packit 6c4009
Packit 6c4009
	.text
Packit 6c4009
	.type	__bzero, @function
Packit 6c4009
	.globl	__bzero
Packit 6c4009
	.usepv	__bzero, USEPV_PROF
Packit 6c4009
Packit 6c4009
	cfi_startproc
Packit 6c4009
Packit 6c4009
	/* On entry to this basic block:
Packit 6c4009
	   t3 == loop counter
Packit 6c4009
	   t4 == bytes in partial final word
Packit 6c4009
	   a0 == possibly misaligned destination pointer  */
Packit 6c4009
Packit 6c4009
	.align 3
Packit 6c4009
bzero_loop:
Packit 6c4009
	beq	t3, $tail	#
Packit 6c4009
	blbc	t3, 0f		# skip single store if count even
Packit 6c4009
Packit 6c4009
	stq_u	zero, 0(a0)	# e0    : store one word
Packit 6c4009
	subq	t3, 1, t3	# .. e1 :
Packit 6c4009
	addq	a0, 8, a0	# e0    :
Packit 6c4009
	beq	t3, $tail	# .. e1 :
Packit 6c4009
Packit 6c4009
0:	stq_u	zero, 0(a0)	# e0    : store two words
Packit 6c4009
	subq	t3, 2, t3	# .. e1 :
Packit 6c4009
	stq_u	zero, 8(a0)	# e0    :
Packit 6c4009
	addq	a0, 16, a0	# .. e1 :
Packit 6c4009
	bne	t3, 0b		# e1    :
Packit 6c4009
Packit 6c4009
$tail:	bne	t4, 1f		# is there a tail to do?
Packit 6c4009
	ret			# no
Packit 6c4009
Packit 6c4009
1:	ldq_u	t0, 0(a0)	# yes, load original data
Packit 6c4009
	mskqh	t0, t4, t0	#
Packit 6c4009
	stq_u	t0, 0(a0)	#
Packit 6c4009
	ret			#
Packit 6c4009
Packit 6c4009
__bzero:
Packit 6c4009
#ifdef PROF
Packit 6c4009
	ldgp	gp, 0(pv)
Packit 6c4009
	lda	AT, _mcount
Packit 6c4009
	jsr	AT, (AT), _mcount
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
	mov	a0, v0		# e0    : move return value in place
Packit 6c4009
	beq	a1, $done	# .. e1 : early exit for zero-length store
Packit 6c4009
	and	a0, 7, t1	# e0    :
Packit 6c4009
	addq	a1, t1, a1	# e1    : add dest misalignment to count
Packit 6c4009
	srl	a1, 3, t3	# e0    : loop = count >> 3
Packit 6c4009
	and	a1, 7, t4	# .. e1 : find number of bytes in tail
Packit 6c4009
	unop			#       :
Packit 6c4009
	beq	t1, bzero_loop	# e1    : aligned head, jump right in
Packit 6c4009
Packit 6c4009
	ldq_u	t0, 0(a0)	# e0    : load original data to mask into
Packit 6c4009
	cmpult	a1, 8, t2	# .. e1 : is this a sub-word set?
Packit 6c4009
	bne	t2, $oneq	# e1    :
Packit 6c4009
Packit 6c4009
	mskql	t0, a0, t0	# e0    : we span words.  finish this partial
Packit 6c4009
	subq	t3, 1, t3	# e0    :
Packit 6c4009
	addq	a0, 8, a0	# .. e1 :
Packit 6c4009
	stq_u	t0, -8(a0)	# e0    :
Packit 6c4009
	br 	bzero_loop	# .. e1 :
Packit 6c4009
Packit 6c4009
	.align 3
Packit 6c4009
$oneq:
Packit 6c4009
	mskql	t0, a0, t2	# e0    :
Packit 6c4009
	mskqh	t0, a1, t3	# e0    :
Packit 6c4009
	or	t2, t3, t0	# e1    :
Packit 6c4009
	stq_u	t0, 0(a0)	# e0    :
Packit 6c4009
Packit 6c4009
$done:	ret
Packit 6c4009
Packit 6c4009
	cfi_endproc
Packit 6c4009
weak_alias (__bzero, bzero)