1/* Compare two memory blocks for differences in the first COUNT bytes.
2   For SPARC v9.
3   Copyright (C) 1998-2022 Free Software Foundation, Inc.
4   This file is part of the GNU C Library.
5
6   The GNU C Library is free software; you can redistribute it and/or
7   modify it under the terms of the GNU Lesser General Public
8   License as published by the Free Software Foundation; either
9   version 2.1 of the License, or (at your option) any later version.
10
11   The GNU C Library is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   Lesser General Public License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with the GNU C Library; if not, see
18   <https://www.gnu.org/licenses/>.  */
19
20#include <sysdep.h>
21#include <asm/asi.h>
22#ifndef XCC
23#define XCC xcc
24#define USE_BPR
25	.register	%g2, #scratch
26	.register	%g3, #scratch
27#endif
28
29	.text
30	.align		32
31ENTRY(memcmp)
32#ifdef USE_BPR
33	brz,pn		%o2, 3f				/* CTI+IEU1	Group		*/
34#else
35	tst		%o2				/* IEU1		Group		*/
36	be,pn		%XCC, 3f			/* CTI				*/
37#endif
38	 andcc		%o0, 7, %g0			/* IEU1		Group		*/
39	bne,pn		%icc, 8f			/* CTI				*/
401:	 andcc		%o1, 7, %g1			/* IEU1		Group		*/
41
42	bne,pn		%icc, 10f			/* CTI				*/
43	 mov		64, %g3				/* IEU0				*/
44	ldx		[%o0], %g1			/* Load		Group		*/
45	sub		%o1, %o0, %o1			/* IEU0				*/
46
47	ldx		[%o0 + %o1], %g2		/* Load		Group		*/
48	add		%o0, 8, %o0			/* IEU0				*/
492:	mov		%g1, %o3			/* IEU0		Group		*/
50	subcc		%o2, 8, %o2			/* IEU1				*/
51
52	bcs,pn		%XCC, 5f			/* CTI				*/
53	 ldxa		[%o0] ASI_PNF, %g1		/* Load		Group		*/
54	mov		%g2, %o4			/* IEU0				*/
55	ldxa		[%o0 + %o1] ASI_PNF, %g2	/* Load		Group		*/
56
57	cmp		%o3, %o4			/* IEU1				*/
58	be,pt		%xcc, 2b			/* CTI				*/
59	 add		%o0, 8, %o0			/* IEU0				*/
607:	mov		-1, %o0				/* IEU1				*/
61
62	retl						/* CTI+IEU1	Group		*/
63	 movgu		%xcc, 1, %o0			/* Single	Group		*/
643:	retl						/* CTI+IEU1	Group		*/
65	 clr		%o0				/* IEU0				*/
66
67	.align		16
685:	mov		%g2, %o4			/* IEU0				*/
696:	cmp		%o2, -8				/* IEU1				*/
70	be,pn		%XCC, 3b			/* CTI				*/
71	 sub		%g0, %o2, %o2			/* IEU0		Group		*/
72
73	sllx		%o2, 3, %o2			/* IEU0		Group		*/
74	srlx		%o3, %o2, %o3			/* IEU0		Group		*/
75	srlx		%o4, %o2, %o4			/* IEU0		Group		*/
76	clr		%o0				/* IEU1				*/
77
78	cmp		%o3, %o4			/* IEU1		Group		*/
79	movgu		%xcc, 1, %o0			/* Single	Group		*/
80	retl						/* CTI+IEU1	Group		*/
81	 movlu		%xcc, -1, %o0			/* Single	Group		*/
82
838:	ldub		[%o0], %o3			/* Load				*/
84	add		%o0, 1, %o0			/* IEU0				*/
85	ldub		[%o1], %o4			/* Load		Group		*/
86	add		%o1, 1, %o1			/* IEU0				*/
87
889:	cmp		%o3, %o4			/* IEU1		Group		*/
89	bne,pn		%xcc, 12f			/* CTI				*/
90	 subcc		%o2, 1, %o2			/* IEU1		Group		*/
91	be,pn		%XCC, 3b			/* CTI				*/
92
93	 lduba		[%o0] ASI_PNF, %o3		/* Load				*/
94	andcc		%o0, 7, %g0			/* IEU1		Group		*/
95	be,pn		%icc, 1b			/* CTI				*/
96	 lduba		[%o1] ASI_PNF, %o4		/* Load				*/
97
98	add		%o0, 1, %o0			/* IEU0		Group		*/
99	ba,pt		%xcc, 9b			/* CTI				*/
100	 add		%o1, 1, %o1			/* IEU1				*/
101
102	.align		16
10312:	mov		-1, %o0				/* IEU0		Group		*/
104	cmp		%o3, %o4			/* IEU1				*/
105	retl						/* CTI+IEU1	Group		*/
106	 movgu		%xcc, 1, %o0			/* Single	Group		*/
107
108	.align		16
109	nop						/* Stub				*/
11010:	sllx		%g1, 3, %g2			/* IEU0		Group		*/
111	sub		%o1, %g1, %o1			/* IEU1				*/
112	sub		%g3, %g2, %g3			/* IEU0		Group		*/
113
114	ldxa		[%o0] ASI_PNF, %g5		/* Load				*/
115	sub		%o1, %o0, %o1			/* IEU1				*/
116	ldxa		[%o0 + %o1] ASI_PNF, %g4	/* Load		Group		*/
117	add		%o0, 8, %o0			/* IEU0				*/
118
11911:	sllx		%g4, %g2, %o4			/* IEU0		Group		*/
120	ldxa		[%o0 + %o1] ASI_PNF, %g4	/* Load				*/
121	srlx		%g4, %g3, %o5			/* IEU0		Group		*/
122	mov		%g5, %o3			/* IEU1				*/
123
124	ldxa		[%o0] ASI_PNF, %g5		/* Load				*/
125	subcc		%o2, 8, %o2			/* IEU1		Group		*/
126	bcs,pn		%XCC, 6b			/* CTI				*/
127	 or		%o4, %o5, %o4			/* IEU0				*/
128
129	cmp		%o3, %o4			/* IEU1		Group		*/
130	be,pt		%xcc, 11b			/* CTI				*/
131	 add		%o0, 8, %o0			/* IEU0				*/
132	mov		-1, %o0				/* IEU0				*/
133
134	retl						/* CTI+IEU1	Group		*/
135	 movgu		%xcc, 1, %o0			/* Single	Group		*/
136END(memcmp)
137
138#undef bcmp
139weak_alias (memcmp, bcmp)
140#undef __memcmpeq
141strong_alias (memcmp, __memcmpeq)
142libc_hidden_builtin_def (memcmp)
143libc_hidden_def (__memcmpeq)
144