2019-05-29 07:18:00 -07:00
/* SPDX-License-Identifier: GPL-2.0-only */
2017-07-10 18:03:19 -07:00
/ *
* Copyright ( C ) 2 0 1 3 R e g e n t s o f t h e U n i v e r s i t y o f C a l i f o r n i a
* /
# include < l i n u x / l i n k a g e . h >
# include < a s m / a s m . h >
/* void *memset(void *, int, size_t) */
2020-01-06 10:38:32 -08:00
ENTRY( _ _ m e m s e t )
WEAK( m e m s e t )
2017-07-10 18:03:19 -07:00
move t 0 , a0 / * P r e s e r v e r e t u r n v a l u e * /
/* Defer to byte-oriented fill for small sizes */
sltiu a3 , a2 , 1 6
bnez a3 , 4 f
/ *
* Round t o n e a r e s t X L E N - a l i g n e d a d d r e s s
* greater t h a n o r e q u a l t o s t a r t a d d r e s s
* /
addi a3 , t 0 , S Z R E G - 1
andi a3 , a3 , ~ ( S Z R E G - 1 )
beq a3 , t 0 , 2 f / * S k i p i f a l r e a d y a l i g n e d * /
/* Handle initial misalignment */
sub a4 , a3 , t 0
1 :
sb a1 , 0 ( t 0 )
addi t 0 , t 0 , 1
bltu t 0 , a3 , 1 b
sub a2 , a2 , a4 / * U p d a t e c o u n t * /
2 : /* Duff's device with 32 XLEN stores per iteration */
/* Broadcast value into all bytes */
andi a1 , a1 , 0 x f f
slli a3 , a1 , 8
or a1 , a3 , a1
slli a3 , a1 , 1 6
or a1 , a3 , a1
# ifdef C O N F I G _ 6 4 B I T
slli a3 , a1 , 3 2
or a1 , a3 , a1
# endif
/* Calculate end address */
andi a4 , a2 , ~ ( S Z R E G - 1 )
add a3 , t 0 , a4
andi a4 , a4 , 3 1 * S Z R E G / * C a l c u l a t e r e m a i n d e r * /
beqz a4 , 3 f / * S h o r t c u t i f n o r e m a i n d e r * /
neg a4 , a4
addi a4 , a4 , 3 2 * S Z R E G / * C a l c u l a t e i n i t i a l o f f s e t * /
/* Adjust start address with offset */
sub t 0 , t 0 , a4
/* Jump into loop body */
/* Assumes 32-bit instruction lengths */
la a5 , 3 f
# ifdef C O N F I G _ 6 4 B I T
srli a4 , a4 , 1
# endif
add a5 , a5 , a4
jr a5
3 :
REG_ S a1 , 0 ( t 0 )
REG_ S a1 , S Z R E G ( t 0 )
REG_ S a1 , 2 * S Z R E G ( t 0 )
REG_ S a1 , 3 * S Z R E G ( t 0 )
REG_ S a1 , 4 * S Z R E G ( t 0 )
REG_ S a1 , 5 * S Z R E G ( t 0 )
REG_ S a1 , 6 * S Z R E G ( t 0 )
REG_ S a1 , 7 * S Z R E G ( t 0 )
REG_ S a1 , 8 * S Z R E G ( t 0 )
REG_ S a1 , 9 * S Z R E G ( t 0 )
REG_ S a1 , 1 0 * S Z R E G ( t 0 )
REG_ S a1 , 1 1 * S Z R E G ( t 0 )
REG_ S a1 , 1 2 * S Z R E G ( t 0 )
REG_ S a1 , 1 3 * S Z R E G ( t 0 )
REG_ S a1 , 1 4 * S Z R E G ( t 0 )
REG_ S a1 , 1 5 * S Z R E G ( t 0 )
REG_ S a1 , 1 6 * S Z R E G ( t 0 )
REG_ S a1 , 1 7 * S Z R E G ( t 0 )
REG_ S a1 , 1 8 * S Z R E G ( t 0 )
REG_ S a1 , 1 9 * S Z R E G ( t 0 )
REG_ S a1 , 2 0 * S Z R E G ( t 0 )
REG_ S a1 , 2 1 * S Z R E G ( t 0 )
REG_ S a1 , 2 2 * S Z R E G ( t 0 )
REG_ S a1 , 2 3 * S Z R E G ( t 0 )
REG_ S a1 , 2 4 * S Z R E G ( t 0 )
REG_ S a1 , 2 5 * S Z R E G ( t 0 )
REG_ S a1 , 2 6 * S Z R E G ( t 0 )
REG_ S a1 , 2 7 * S Z R E G ( t 0 )
REG_ S a1 , 2 8 * S Z R E G ( t 0 )
REG_ S a1 , 2 9 * S Z R E G ( t 0 )
REG_ S a1 , 3 0 * S Z R E G ( t 0 )
REG_ S a1 , 3 1 * S Z R E G ( t 0 )
addi t 0 , t 0 , 3 2 * S Z R E G
bltu t 0 , a3 , 3 b
andi a2 , a2 , S Z R E G - 1 / * U p d a t e c o u n t * /
4 :
/* Handle trailing misalignment */
beqz a2 , 6 f
add a3 , t 0 , a2
5 :
sb a1 , 0 ( t 0 )
addi t 0 , t 0 , 1
bltu t 0 , a3 , 5 b
6 :
ret
2020-01-06 10:38:32 -08:00
END( _ _ m e m s e t )