xref: /linux/arch/arc/lib/memcmp.S (revision ec7ac6afd07b2d958aab9dfc0a686300b856922a)
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
9*ec7ac6afSVineet Gupta#include <linux/linkage.h>
105210d1e6SVineet Gupta
115210d1e6SVineet Gupta#ifdef __LITTLE_ENDIAN__
125210d1e6SVineet Gupta#define WORD2 r2
135210d1e6SVineet Gupta#define SHIFT r3
145210d1e6SVineet Gupta#else /* BIG ENDIAN */
155210d1e6SVineet Gupta#define WORD2 r3
165210d1e6SVineet Gupta#define SHIFT r2
175210d1e6SVineet Gupta#endif
185210d1e6SVineet Gupta
19*ec7ac6afSVineet GuptaENTRY(memcmp)
205210d1e6SVineet Gupta	or	r12,r0,r1
215210d1e6SVineet Gupta	asl_s	r12,r12,30
225210d1e6SVineet Gupta	sub	r3,r2,1
235210d1e6SVineet Gupta	brls	r2,r12,.Lbytewise
245210d1e6SVineet Gupta	ld	r4,[r0,0]
255210d1e6SVineet Gupta	ld	r5,[r1,0]
265210d1e6SVineet Gupta	lsr.f	lp_count,r3,3
275210d1e6SVineet Gupta	lpne	.Loop_end
285210d1e6SVineet Gupta	ld_s	WORD2,[r0,4]
295210d1e6SVineet Gupta	ld_s	r12,[r1,4]
305210d1e6SVineet Gupta	brne	r4,r5,.Leven
315210d1e6SVineet Gupta	ld.a	r4,[r0,8]
325210d1e6SVineet Gupta	ld.a	r5,[r1,8]
335210d1e6SVineet Gupta	brne	WORD2,r12,.Lodd
345210d1e6SVineet Gupta.Loop_end:
355210d1e6SVineet Gupta	asl_s	SHIFT,SHIFT,3
365210d1e6SVineet Gupta	bhs_s	.Last_cmp
375210d1e6SVineet Gupta	brne	r4,r5,.Leven
385210d1e6SVineet Gupta	ld	r4,[r0,4]
395210d1e6SVineet Gupta	ld	r5,[r1,4]
405210d1e6SVineet Gupta#ifdef __LITTLE_ENDIAN__
415210d1e6SVineet Gupta	nop_s
425210d1e6SVineet Gupta	; one more load latency cycle
435210d1e6SVineet Gupta.Last_cmp:
445210d1e6SVineet Gupta	xor	r0,r4,r5
455210d1e6SVineet Gupta	bset	r0,r0,SHIFT
465210d1e6SVineet Gupta	sub_s	r1,r0,1
475210d1e6SVineet Gupta	bic_s	r1,r1,r0
485210d1e6SVineet Gupta	norm	r1,r1
495210d1e6SVineet Gupta	b.d	.Leven_cmp
505210d1e6SVineet Gupta	and	r1,r1,24
515210d1e6SVineet Gupta.Leven:
525210d1e6SVineet Gupta	xor	r0,r4,r5
535210d1e6SVineet Gupta	sub_s	r1,r0,1
545210d1e6SVineet Gupta	bic_s	r1,r1,r0
555210d1e6SVineet Gupta	norm	r1,r1
565210d1e6SVineet Gupta	; slow track insn
575210d1e6SVineet Gupta	and	r1,r1,24
585210d1e6SVineet Gupta.Leven_cmp:
595210d1e6SVineet Gupta	asl	r2,r4,r1
605210d1e6SVineet Gupta	asl	r12,r5,r1
615210d1e6SVineet Gupta	lsr_s	r2,r2,1
625210d1e6SVineet Gupta	lsr_s	r12,r12,1
635210d1e6SVineet Gupta	j_s.d	[blink]
645210d1e6SVineet Gupta	sub	r0,r2,r12
655210d1e6SVineet Gupta	.balign	4
665210d1e6SVineet Gupta.Lodd:
675210d1e6SVineet Gupta	xor	r0,WORD2,r12
685210d1e6SVineet Gupta	sub_s	r1,r0,1
695210d1e6SVineet Gupta	bic_s	r1,r1,r0
705210d1e6SVineet Gupta	norm	r1,r1
715210d1e6SVineet Gupta	; slow track insn
725210d1e6SVineet Gupta	and	r1,r1,24
735210d1e6SVineet Gupta	asl_s	r2,r2,r1
745210d1e6SVineet Gupta	asl_s	r12,r12,r1
755210d1e6SVineet Gupta	lsr_s	r2,r2,1
765210d1e6SVineet Gupta	lsr_s	r12,r12,1
775210d1e6SVineet Gupta	j_s.d	[blink]
785210d1e6SVineet Gupta	sub	r0,r2,r12
795210d1e6SVineet Gupta#else /* BIG ENDIAN */
805210d1e6SVineet Gupta.Last_cmp:
815210d1e6SVineet Gupta	neg_s	SHIFT,SHIFT
825210d1e6SVineet Gupta	lsr	r4,r4,SHIFT
835210d1e6SVineet Gupta	lsr	r5,r5,SHIFT
845210d1e6SVineet Gupta	; slow track insn
855210d1e6SVineet Gupta.Leven:
865210d1e6SVineet Gupta	sub.f	r0,r4,r5
875210d1e6SVineet Gupta	mov.ne	r0,1
885210d1e6SVineet Gupta	j_s.d	[blink]
895210d1e6SVineet Gupta	bset.cs	r0,r0,31
905210d1e6SVineet Gupta.Lodd:
915210d1e6SVineet Gupta	cmp_s	WORD2,r12
925210d1e6SVineet Gupta
935210d1e6SVineet Gupta	mov_s	r0,1
945210d1e6SVineet Gupta	j_s.d	[blink]
955210d1e6SVineet Gupta	bset.cs	r0,r0,31
965210d1e6SVineet Gupta#endif /* ENDIAN */
975210d1e6SVineet Gupta	.balign	4
985210d1e6SVineet Gupta.Lbytewise:
995210d1e6SVineet Gupta	breq	r2,0,.Lnil
1005210d1e6SVineet Gupta	ldb	r4,[r0,0]
1015210d1e6SVineet Gupta	ldb	r5,[r1,0]
1025210d1e6SVineet Gupta	lsr.f	lp_count,r3
1035210d1e6SVineet Gupta	lpne	.Lbyte_end
1045210d1e6SVineet Gupta	ldb_s	r3,[r0,1]
1055210d1e6SVineet Gupta	ldb	r12,[r1,1]
1065210d1e6SVineet Gupta	brne	r4,r5,.Lbyte_even
1075210d1e6SVineet Gupta	ldb.a	r4,[r0,2]
1085210d1e6SVineet Gupta	ldb.a	r5,[r1,2]
1095210d1e6SVineet Gupta	brne	r3,r12,.Lbyte_odd
1105210d1e6SVineet Gupta.Lbyte_end:
1115210d1e6SVineet Gupta	bcc	.Lbyte_even
1125210d1e6SVineet Gupta	brne	r4,r5,.Lbyte_even
1135210d1e6SVineet Gupta	ldb_s	r3,[r0,1]
1145210d1e6SVineet Gupta	ldb_s	r12,[r1,1]
1155210d1e6SVineet Gupta.Lbyte_odd:
1165210d1e6SVineet Gupta	j_s.d	[blink]
1175210d1e6SVineet Gupta	sub	r0,r3,r12
1185210d1e6SVineet Gupta.Lbyte_even:
1195210d1e6SVineet Gupta	j_s.d	[blink]
1205210d1e6SVineet Gupta	sub	r0,r4,r5
1215210d1e6SVineet Gupta.Lnil:
1225210d1e6SVineet Gupta	j_s.d	[blink]
1235210d1e6SVineet Gupta	mov	r0,0
124*ec7ac6afSVineet GuptaEND(memcmp)
125