18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#include <linux/linkage.h>
58c2ecf20Sopenharmony_ci#include "sysdep.h"
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ciENTRY(strlen)
88c2ecf20Sopenharmony_ci	/* Check if the start addr is aligned.  */
98c2ecf20Sopenharmony_ci	mov	r3, r0
108c2ecf20Sopenharmony_ci	andi	r1, r0, 3
118c2ecf20Sopenharmony_ci	movi	r2, 4
128c2ecf20Sopenharmony_ci	movi	r0, 0
138c2ecf20Sopenharmony_ci	bnez	r1, .L_start_not_aligned
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci	LABLE_ALIGN
168c2ecf20Sopenharmony_ci.L_start_addr_aligned:
178c2ecf20Sopenharmony_ci	/* Check if all the bytes in the word are not zero.  */
188c2ecf20Sopenharmony_ci	ldw	r1, (r3)
198c2ecf20Sopenharmony_ci	tstnbz	r1
208c2ecf20Sopenharmony_ci	bf	.L_string_tail
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci	ldw	r1, (r3, 4)
238c2ecf20Sopenharmony_ci	addi	r0, 4
248c2ecf20Sopenharmony_ci	tstnbz	r1
258c2ecf20Sopenharmony_ci	bf	.L_string_tail
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci	ldw	r1, (r3, 8)
288c2ecf20Sopenharmony_ci	addi	r0, 4
298c2ecf20Sopenharmony_ci	tstnbz	r1
308c2ecf20Sopenharmony_ci	bf	.L_string_tail
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci	ldw	r1, (r3, 12)
338c2ecf20Sopenharmony_ci	addi	r0, 4
348c2ecf20Sopenharmony_ci	tstnbz	r1
358c2ecf20Sopenharmony_ci	bf	.L_string_tail
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci	ldw	r1, (r3, 16)
388c2ecf20Sopenharmony_ci	addi	r0, 4
398c2ecf20Sopenharmony_ci	tstnbz	r1
408c2ecf20Sopenharmony_ci	bf	.L_string_tail
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	ldw	r1, (r3, 20)
438c2ecf20Sopenharmony_ci	addi	r0, 4
448c2ecf20Sopenharmony_ci	tstnbz	r1
458c2ecf20Sopenharmony_ci	bf	.L_string_tail
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	ldw	r1, (r3, 24)
488c2ecf20Sopenharmony_ci	addi	r0, 4
498c2ecf20Sopenharmony_ci	tstnbz	r1
508c2ecf20Sopenharmony_ci	bf	.L_string_tail
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci	ldw	r1, (r3, 28)
538c2ecf20Sopenharmony_ci	addi	r0, 4
548c2ecf20Sopenharmony_ci	tstnbz	r1
558c2ecf20Sopenharmony_ci	bf	.L_string_tail
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	addi	r0, 4
588c2ecf20Sopenharmony_ci	addi	r3, 32
598c2ecf20Sopenharmony_ci	br	.L_start_addr_aligned
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci.L_string_tail:
628c2ecf20Sopenharmony_ci# ifdef __CSKYBE__
638c2ecf20Sopenharmony_ci	xtrb0	r3, r1
648c2ecf20Sopenharmony_ci	bez	r3, .L_return
658c2ecf20Sopenharmony_ci	addi	r0, 1
668c2ecf20Sopenharmony_ci	xtrb1	r3, r1
678c2ecf20Sopenharmony_ci	bez	r3, .L_return
688c2ecf20Sopenharmony_ci	addi	r0, 1
698c2ecf20Sopenharmony_ci	xtrb2	r3, r1
708c2ecf20Sopenharmony_ci	bez	r3, .L_return
718c2ecf20Sopenharmony_ci	addi	r0, 1
728c2ecf20Sopenharmony_ci# else
738c2ecf20Sopenharmony_ci	xtrb3	r3, r1
748c2ecf20Sopenharmony_ci	bez	r3, .L_return
758c2ecf20Sopenharmony_ci	addi	r0, 1
768c2ecf20Sopenharmony_ci	xtrb2	r3, r1
778c2ecf20Sopenharmony_ci	bez	r3, .L_return
788c2ecf20Sopenharmony_ci	addi	r0, 1
798c2ecf20Sopenharmony_ci	xtrb1	r3, r1
808c2ecf20Sopenharmony_ci	bez	r3, .L_return
818c2ecf20Sopenharmony_ci	addi	r0, 1
828c2ecf20Sopenharmony_ci# endif	/* !__CSKYBE__ */
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci.L_return:
858c2ecf20Sopenharmony_ci	rts
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci.L_start_not_aligned:
888c2ecf20Sopenharmony_ci	sub	r2, r2, r1
898c2ecf20Sopenharmony_ci.L_start_not_aligned_loop:
908c2ecf20Sopenharmony_ci	ldb	r1, (r3)
918c2ecf20Sopenharmony_ci	PRE_BNEZAD (r2)
928c2ecf20Sopenharmony_ci	addi	r3, 1
938c2ecf20Sopenharmony_ci	bez	r1, .L_return
948c2ecf20Sopenharmony_ci	addi	r0, 1
958c2ecf20Sopenharmony_ci	BNEZAD (r2, .L_start_not_aligned_loop)
968c2ecf20Sopenharmony_ci	br	.L_start_addr_aligned
978c2ecf20Sopenharmony_ciENDPROC(strlen)
98