xref: /kernel/linux/linux-5.10/arch/nds32/lib/memset.S (revision 8c2ecf20)
18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci// Copyright (C) 2005-2017 Andes Technology Corporation
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#include <linux/linkage.h>
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci	.text
78c2ecf20Sopenharmony_ciENTRY(memset)
88c2ecf20Sopenharmony_ci	move	$r5, $r0		! Return value
98c2ecf20Sopenharmony_ci	beqz	$r2, end_memset		! Exit when len = 0
108c2ecf20Sopenharmony_ci	srli	$p1, $r2, 2		! $p1 is how many words to copy
118c2ecf20Sopenharmony_ci	andi	$r2, $r2, 3		! How many bytes are less than a word
128c2ecf20Sopenharmony_ci	beqz	$p1, byte_set		! When n is less than a word
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci	! set $r1 from ??????ab to abababab
158c2ecf20Sopenharmony_ci	andi	$r1, $r1, #0x00ff	! $r1 = 000000ab
168c2ecf20Sopenharmony_ci	slli	$p0, $r1, #8		! $p0 = 0000ab00
178c2ecf20Sopenharmony_ci	or	$r1, $r1, $p0		! $r1 = 0000abab
188c2ecf20Sopenharmony_ci	slli	$p0, $r1, #16		! $p0 = abab0000
198c2ecf20Sopenharmony_ci	or	$r1, $r1, $p0		! $r1 = abababab
208c2ecf20Sopenharmony_ciword_set:
218c2ecf20Sopenharmony_ci	addi	$p1, $p1, #-1		! How many words left to copy
228c2ecf20Sopenharmony_ci	smw.bim	$r1, [$r0], $r1		! Copy the word to det
238c2ecf20Sopenharmony_ci	bnez	$p1, word_set		! Still words to set, continue looping
248c2ecf20Sopenharmony_ci	beqz	$r2, end_memset		! No left byte to set
258c2ecf20Sopenharmony_cibyte_set:				! Less than 4 bytes left to set
268c2ecf20Sopenharmony_ci	addi	$r2, $r2, #-1		! Decrease len by 1
278c2ecf20Sopenharmony_ci	sbi.bi	$r1, [$r0], #1		! Set data of the next byte to $r1
288c2ecf20Sopenharmony_ci	bnez	$r2, byte_set		! Still bytes left to set
298c2ecf20Sopenharmony_ciend_memset:
308c2ecf20Sopenharmony_ci	move	$r0, $r5
318c2ecf20Sopenharmony_ci	ret
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ciENDPROC(memset)
34