1/* MD5 using sparc crypto opcodes.
2   Copyright (C) 2012-2022 Free Software Foundation, Inc.
3   This file is part of the GNU C Library.
4
5   The GNU C Library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9
10   The GNU C Library is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   Lesser General Public License for more details.
14
15   You should have received a copy of the GNU Lesser General Public
16   License along with the GNU C Library; if not, see
17   <https://www.gnu.org/licenses/>.  */
18
19#include <sysdep.h>
20
21#define ASI_PL 0x88
22
23#define MD5		\
24	.word	0x81b02800;
25
26	.text
27	.align	32
28ENTRY(__md5_process_block_crop)
29	/* %o0=buffer, %o1=len, %o2=CTX */
30	ld	[%o2 + 0x10], %g1
31	add	%g1, %o1, %o4
32	st	%o4, [%o2 + 0x10]
33	clr	%o5
34	cmp	%o4, %g1
35	movlu	%icc, 1, %o5
36#ifdef __arch64__
37	srlx	%o1, 32, %o4
38	add	%o5, %o4, %o5
39#endif
40	ld	[%o2 + 0x14], %o4
41	add	%o4, %o5, %o4
42	st	%o4, [%o2 + 0x14]
43	lda	[%o2] ASI_PL, %f0
44	add	%o2, 0x4, %g1
45	lda	[%g1] ASI_PL, %f1
46	add	%o2, 0x8, %g1
47	andcc	%o0, 0x7, %g0
48	lda	[%g1] ASI_PL, %f2
49	add	%o2, 0xc, %g1
50	bne,pn	%xcc, 10f
51	 lda	[%g1] ASI_PL, %f3
52
531:
54	ldd	[%o0 + 0x00], %f8
55	ldd	[%o0 + 0x08], %f10
56	ldd	[%o0 + 0x10], %f12
57	ldd	[%o0 + 0x18], %f14
58	ldd	[%o0 + 0x20], %f16
59	ldd	[%o0 + 0x28], %f18
60	ldd	[%o0 + 0x30], %f20
61	ldd	[%o0 + 0x38], %f22
62
63	MD5
64
65	subcc	%o1, 64, %o1
66	bne,pt	%xcc, 1b
67	 add	%o0, 0x40, %o0
68
695:
70	sta	%f0, [%o2] ASI_PL
71	add	%o2, 0x4, %g1
72	sta	%f1, [%g1] ASI_PL
73	add	%o2, 0x8, %g1
74	sta	%f2, [%g1] ASI_PL
75	add	%o2, 0xc, %g1
76	retl
77	 sta	%f3, [%g1] ASI_PL
7810:
79	alignaddr %o0, %g0, %o0
80
81	ldd	[%o0 + 0x00], %f10
821:
83	ldd	[%o0 + 0x08], %f12
84	ldd	[%o0 + 0x10], %f14
85	ldd	[%o0 + 0x18], %f16
86	ldd	[%o0 + 0x20], %f18
87	ldd	[%o0 + 0x28], %f20
88	ldd	[%o0 + 0x30], %f22
89	ldd	[%o0 + 0x38], %f24
90	ldd	[%o0 + 0x40], %f26
91
92	faligndata %f10, %f12, %f8
93	faligndata %f12, %f14, %f10
94	faligndata %f14, %f16, %f12
95	faligndata %f16, %f18, %f14
96	faligndata %f18, %f20, %f16
97	faligndata %f20, %f22, %f18
98	faligndata %f22, %f24, %f20
99	faligndata %f24, %f26, %f22
100
101	MD5
102
103	subcc	%o1, 64, %o1
104	fsrc2	%f26, %f10
105	bne,pt	%xcc, 1b
106	 add	%o0, 0x40, %o0
107
108	ba,a,pt	%xcc, 5b
109END(__md5_process_block_crop)
110