xref: /linux/arch/arc/lib/strlen.S (revision 86effd0dc675c36caed7b954d7f4f63b77c353b5)
15210d1e6SVineet Gupta/*
25210d1e6SVineet Gupta * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
35210d1e6SVineet Gupta *
45210d1e6SVineet Gupta * This program is free software; you can redistribute it and/or modify
55210d1e6SVineet Gupta * it under the terms of the GNU General Public License version 2 as
65210d1e6SVineet Gupta * published by the Free Software Foundation.
75210d1e6SVineet Gupta */
85210d1e6SVineet Gupta
9ec7ac6afSVineet Gupta#include <linux/linkage.h>
105210d1e6SVineet Gupta
11*86effd0dSVineet GuptaENTRY_CFI(strlen)
125210d1e6SVineet Gupta	or	r3,r0,7
135210d1e6SVineet Gupta	ld	r2,[r3,-7]
145210d1e6SVineet Gupta	ld.a	r6,[r3,-3]
155210d1e6SVineet Gupta	mov	r4,0x01010101
165210d1e6SVineet Gupta	; uses long immediate
175210d1e6SVineet Gupta#ifdef __LITTLE_ENDIAN__
185210d1e6SVineet Gupta	asl_s	r1,r0,3
195210d1e6SVineet Gupta	btst_s	r0,2
205210d1e6SVineet Gupta	asl	r7,r4,r1
215210d1e6SVineet Gupta	ror	r5,r4
225210d1e6SVineet Gupta	sub	r1,r2,r7
235210d1e6SVineet Gupta	bic_s	r1,r1,r2
245210d1e6SVineet Gupta	mov.eq	r7,r4
255210d1e6SVineet Gupta	sub	r12,r6,r7
265210d1e6SVineet Gupta	bic	r12,r12,r6
275210d1e6SVineet Gupta	or.eq	r12,r12,r1
285210d1e6SVineet Gupta	and	r12,r12,r5
295210d1e6SVineet Gupta	brne	r12,0,.Learly_end
305210d1e6SVineet Gupta#else /* BIG ENDIAN */
315210d1e6SVineet Gupta	ror	r5,r4
325210d1e6SVineet Gupta	btst_s	r0,2
335210d1e6SVineet Gupta	mov_s	r1,31
345210d1e6SVineet Gupta	sub3	r7,r1,r0
355210d1e6SVineet Gupta	sub	r1,r2,r4
365210d1e6SVineet Gupta	bic_s	r1,r1,r2
375210d1e6SVineet Gupta	bmsk	r1,r1,r7
385210d1e6SVineet Gupta	sub	r12,r6,r4
395210d1e6SVineet Gupta	bic	r12,r12,r6
405210d1e6SVineet Gupta	bmsk.ne	r12,r12,r7
415210d1e6SVineet Gupta	or.eq	r12,r12,r1
425210d1e6SVineet Gupta	and	r12,r12,r5
435210d1e6SVineet Gupta	brne	r12,0,.Learly_end
445210d1e6SVineet Gupta#endif /* ENDIAN */
455210d1e6SVineet Gupta
465210d1e6SVineet Gupta.Loop:
475210d1e6SVineet Gupta	ld_s	r2,[r3,4]
485210d1e6SVineet Gupta	ld.a	r6,[r3,8]
495210d1e6SVineet Gupta	; stall for load result
505210d1e6SVineet Gupta	sub	r1,r2,r4
515210d1e6SVineet Gupta	bic_s	r1,r1,r2
525210d1e6SVineet Gupta	sub	r12,r6,r4
535210d1e6SVineet Gupta	bic	r12,r12,r6
545210d1e6SVineet Gupta	or	r12,r12,r1
555210d1e6SVineet Gupta	and	r12,r12,r5
565210d1e6SVineet Gupta	breq r12,0,.Loop
575210d1e6SVineet Gupta.Lend:
585210d1e6SVineet Gupta	and.f	r1,r1,r5
595210d1e6SVineet Gupta	sub.ne	r3,r3,4
605210d1e6SVineet Gupta	mov.eq	r1,r12
615210d1e6SVineet Gupta#ifdef __LITTLE_ENDIAN__
625210d1e6SVineet Gupta	sub_s	r2,r1,1
635210d1e6SVineet Gupta	bic_s	r2,r2,r1
645210d1e6SVineet Gupta	norm	r1,r2
655210d1e6SVineet Gupta	sub_s	r0,r0,3
665210d1e6SVineet Gupta	lsr_s	r1,r1,3
675210d1e6SVineet Gupta	sub	    r0,r3,r0
685210d1e6SVineet Gupta	j_s.d	[blink]
695210d1e6SVineet Gupta	sub	    r0,r0,r1
705210d1e6SVineet Gupta#else /* BIG ENDIAN */
715210d1e6SVineet Gupta	lsr_s	r1,r1,7
725210d1e6SVineet Gupta	mov.eq	r2,r6
735210d1e6SVineet Gupta	bic_s	r1,r1,r2
745210d1e6SVineet Gupta	norm	r1,r1
755210d1e6SVineet Gupta	sub	    r0,r3,r0
765210d1e6SVineet Gupta	lsr_s	r1,r1,3
775210d1e6SVineet Gupta	j_s.d	[blink]
785210d1e6SVineet Gupta	add	    r0,r0,r1
795210d1e6SVineet Gupta#endif /* ENDIAN */
805210d1e6SVineet Gupta.Learly_end:
815210d1e6SVineet Gupta	b.d	.Lend
825210d1e6SVineet Gupta	sub_s.ne r1,r1,r1
83*86effd0dSVineet GuptaEND_CFI(strlen)
84