xref: /linux/arch/arc/lib/strlen.S (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1*d2912cb1SThomas Gleixner/* SPDX-License-Identifier: GPL-2.0-only */
25210d1e6SVineet Gupta/*
35210d1e6SVineet Gupta * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
45210d1e6SVineet Gupta */
55210d1e6SVineet Gupta
6ec7ac6afSVineet Gupta#include <linux/linkage.h>
75210d1e6SVineet Gupta
886effd0dSVineet GuptaENTRY_CFI(strlen)
95210d1e6SVineet Gupta	or	r3,r0,7
105210d1e6SVineet Gupta	ld	r2,[r3,-7]
115210d1e6SVineet Gupta	ld.a	r6,[r3,-3]
125210d1e6SVineet Gupta	mov	r4,0x01010101
135210d1e6SVineet Gupta	; uses long immediate
145210d1e6SVineet Gupta#ifdef __LITTLE_ENDIAN__
155210d1e6SVineet Gupta	asl_s	r1,r0,3
165210d1e6SVineet Gupta	btst_s	r0,2
175210d1e6SVineet Gupta	asl	r7,r4,r1
185210d1e6SVineet Gupta	ror	r5,r4
195210d1e6SVineet Gupta	sub	r1,r2,r7
205210d1e6SVineet Gupta	bic_s	r1,r1,r2
215210d1e6SVineet Gupta	mov.eq	r7,r4
225210d1e6SVineet Gupta	sub	r12,r6,r7
235210d1e6SVineet Gupta	bic	r12,r12,r6
245210d1e6SVineet Gupta	or.eq	r12,r12,r1
255210d1e6SVineet Gupta	and	r12,r12,r5
265210d1e6SVineet Gupta	brne	r12,0,.Learly_end
275210d1e6SVineet Gupta#else /* BIG ENDIAN */
285210d1e6SVineet Gupta	ror	r5,r4
295210d1e6SVineet Gupta	btst_s	r0,2
305210d1e6SVineet Gupta	mov_s	r1,31
315210d1e6SVineet Gupta	sub3	r7,r1,r0
325210d1e6SVineet Gupta	sub	r1,r2,r4
335210d1e6SVineet Gupta	bic_s	r1,r1,r2
345210d1e6SVineet Gupta	bmsk	r1,r1,r7
355210d1e6SVineet Gupta	sub	r12,r6,r4
365210d1e6SVineet Gupta	bic	r12,r12,r6
375210d1e6SVineet Gupta	bmsk.ne	r12,r12,r7
385210d1e6SVineet Gupta	or.eq	r12,r12,r1
395210d1e6SVineet Gupta	and	r12,r12,r5
405210d1e6SVineet Gupta	brne	r12,0,.Learly_end
415210d1e6SVineet Gupta#endif /* ENDIAN */
425210d1e6SVineet Gupta
435210d1e6SVineet Gupta.Loop:
445210d1e6SVineet Gupta	ld_s	r2,[r3,4]
455210d1e6SVineet Gupta	ld.a	r6,[r3,8]
465210d1e6SVineet Gupta	; stall for load result
475210d1e6SVineet Gupta	sub	r1,r2,r4
485210d1e6SVineet Gupta	bic_s	r1,r1,r2
495210d1e6SVineet Gupta	sub	r12,r6,r4
505210d1e6SVineet Gupta	bic	r12,r12,r6
515210d1e6SVineet Gupta	or	r12,r12,r1
525210d1e6SVineet Gupta	and	r12,r12,r5
535210d1e6SVineet Gupta	breq r12,0,.Loop
545210d1e6SVineet Gupta.Lend:
555210d1e6SVineet Gupta	and.f	r1,r1,r5
565210d1e6SVineet Gupta	sub.ne	r3,r3,4
575210d1e6SVineet Gupta	mov.eq	r1,r12
585210d1e6SVineet Gupta#ifdef __LITTLE_ENDIAN__
595210d1e6SVineet Gupta	sub_s	r2,r1,1
605210d1e6SVineet Gupta	bic_s	r2,r2,r1
615210d1e6SVineet Gupta	norm	r1,r2
625210d1e6SVineet Gupta	sub_s	r0,r0,3
635210d1e6SVineet Gupta	lsr_s	r1,r1,3
645210d1e6SVineet Gupta	sub	    r0,r3,r0
655210d1e6SVineet Gupta	j_s.d	[blink]
665210d1e6SVineet Gupta	sub	    r0,r0,r1
675210d1e6SVineet Gupta#else /* BIG ENDIAN */
685210d1e6SVineet Gupta	lsr_s	r1,r1,7
695210d1e6SVineet Gupta	mov.eq	r2,r6
705210d1e6SVineet Gupta	bic_s	r1,r1,r2
715210d1e6SVineet Gupta	norm	r1,r1
725210d1e6SVineet Gupta	sub	    r0,r3,r0
735210d1e6SVineet Gupta	lsr_s	r1,r1,3
745210d1e6SVineet Gupta	j_s.d	[blink]
755210d1e6SVineet Gupta	add	    r0,r0,r1
765210d1e6SVineet Gupta#endif /* ENDIAN */
775210d1e6SVineet Gupta.Learly_end:
785210d1e6SVineet Gupta	b.d	.Lend
795210d1e6SVineet Gupta	sub_s.ne r1,r1,r1
8086effd0dSVineet GuptaEND_CFI(strlen)
81