|
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 a character. Optimized for the Alpha
|
|
Packit |
6c4009 |
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 memset, @function
|
|
Packit |
6c4009 |
.globl memset
|
|
Packit |
6c4009 |
.usepv memset, 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 |
a1 == replicated source character */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.align 3
|
|
Packit |
6c4009 |
memset_loop:
|
|
Packit |
6c4009 |
beq t3, $tail
|
|
Packit |
6c4009 |
blbc t3, 0f # skip single store if count even
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
stq_u a1, 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 a1, 0(a0) # e0 : store two words
|
|
Packit |
6c4009 |
subq t3, 2, t3 # .. e1 :
|
|
Packit |
6c4009 |
stq_u a1, 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 |
.align 3
|
|
Packit |
6c4009 |
1: ldq_u t0, 0(a0) # e1 : yes, load original data
|
|
Packit |
6c4009 |
mskql a1, t4, t1 # .. e0 :
|
|
Packit |
6c4009 |
mskqh t0, t4, t0 # e0 :
|
|
Packit |
6c4009 |
or t0, t1, t0 # e1 (stall)
|
|
Packit |
6c4009 |
stq_u t0, 0(a0) # e0 :
|
|
Packit |
6c4009 |
ret # .. e1 :
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
memset:
|
|
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 |
and a1, 0xff, a1 # e0 : zero extend input character
|
|
Packit |
6c4009 |
mov a0, v0 # .. e1 : move return value in place
|
|
Packit |
6c4009 |
sll a1, 8, t0 # e0 : begin replicating the char
|
|
Packit |
6c4009 |
beq a2, $done # .. e1 : early exit for zero-length store
|
|
Packit |
6c4009 |
or t0, a1, a1 # e0 :
|
|
Packit |
6c4009 |
and a0, 7, t1 # .. e1 : dest misalignment
|
|
Packit |
6c4009 |
sll a1, 16, t0 # e0 :
|
|
Packit |
6c4009 |
addq a2, t1, a2 # .. e1 : add dest misalignment to count
|
|
Packit |
6c4009 |
or t0, a1, a1 # e0 :
|
|
Packit |
6c4009 |
srl a2, 3, t3 # .. e1 : loop = count >> 3
|
|
Packit |
6c4009 |
sll a1, 32, t0 # e0 :
|
|
Packit |
6c4009 |
and a2, 7, t4 # .. e1 : find number of bytes in tail
|
|
Packit |
6c4009 |
or t0, a1, a1 # e0 : character replication done
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
beq t1, memset_loop # .. e1 : aligned head, jump right in
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
ldq_u t0, 0(a0) # e1 : load original data to mask into
|
|
Packit |
6c4009 |
mskqh a1, a0, t1 # .. e0 :
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
cmpult a2, 8, t2 # e0 : is this a sub-word set?
|
|
Packit |
6c4009 |
bne t2, $oneq # .. e1 (zdb)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
mskql t0, a0, t0 # e0 : we span words. finish this partial
|
|
Packit |
6c4009 |
subq t3, 1, t3 # .. e1 :
|
|
Packit |
6c4009 |
addq a0, 8, a0 # e0 :
|
|
Packit |
6c4009 |
or t0, t1, t0 # .. e1 :
|
|
Packit |
6c4009 |
stq_u t0, -8(a0) # e0 :
|
|
Packit |
6c4009 |
br memset_loop # .. e1 :
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.align 3
|
|
Packit |
6c4009 |
$oneq:
|
|
Packit |
6c4009 |
mskql t1, a2, t1 # e0 : entire operation within one word
|
|
Packit |
6c4009 |
mskql t0, a0, t2 # e0 :
|
|
Packit |
6c4009 |
mskqh t0, a2, t3 # e0 :
|
|
Packit |
6c4009 |
or t1, t2, t0 # .. e1 :
|
|
Packit |
6c4009 |
or t0, t3, t0 # e1 :
|
|
Packit |
6c4009 |
stq_u t0, 0(a0) # e0 (stall)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
$done: ret
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
cfi_endproc
|
|
Packit |
6c4009 |
libc_hidden_builtin_def (memset)
|