summaryrefslogtreecommitdiffstats
path: root/arch/sparc/lib/checksum_64.S
blob: 9700ef1730df63fb91bc5b8c14d9a91587143b5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/* SPDX-License-Identifier: GPL-2.0 */
/* checksum.S: Sparc V9 optimized checksum code.
 *
 *  Copyright(C) 1995 Linus Torvalds
 *  Copyright(C) 1995 Miguel de Icaza
 *  Copyright(C) 1996, 2000 David S. Miller
 *  Copyright(C) 1997 Jakub Jelinek
 *
 * derived from:
 *	Linux/Alpha checksum c-code
 *      Linux/ix86 inline checksum assembly
 *      RFC1071 Computing the Internet Checksum (esp. Jacobsons m68k code)
 *	David Mosberger-Tang for optimized reference c-code
 *	BSD4.4 portable checksum routine
 */

#include <asm/export.h>
	.text

csum_partial_fix_alignment:
	/* We checked for zero length already, so there must be
	 * at least one byte.
	 */
	be,pt		%icc, 1f
	 nop
	ldub		[%o0 + 0x00], %o4
	add		%o0, 1, %o0
	sub		%o1, 1, %o1
1:	andcc		%o0, 0x2, %g0
	be,pn		%icc, csum_partial_post_align
	 cmp		%o1, 2
	blu,pn		%icc, csum_partial_end_cruft
	 nop
	lduh		[%o0 + 0x00], %o5
	add		%o0, 2, %o0
	sub		%o1, 2, %o1
	ba,pt		%xcc, csum_partial_post_align
	 add		%o5, %o4, %o4

	.align		32
	.globl		csum_partial
	.type		csum_partial,#function
	EXPORT_SYMBOL(csum_partial)
csum_partial:		/* %o0=buff, %o1=len, %o2=sum */
	prefetch	[%o0 + 0x000], #n_reads
	clr		%o4
	prefetch	[%o0 + 0x040], #n_reads
	brz,pn		%o1, csum_partial_finish
	 andcc		%o0, 0x3, %g0

	/* We "remember" whether the lowest bit in the address
	 * was set in %g7.  Because if it is, we have to swap
	 * upper and lower 8 bit fields of the sum we calculate.
	*/
	bne,pn		%icc, csum_partial_fix_alignment
	 andcc		%o0, 0x1, %g7

csum_partial_post_align:
	prefetch	[%o0 + 0x080], #n_reads
	andncc		%o1, 0x3f, %o3

	prefetch	[%o0 + 0x0c0], #n_reads
	sub		%o1, %o3, %o1
	brz,pn		%o3, 2f
	 prefetch	[%o0 + 0x100], #n_reads

	/* So that we don't need to use the non-pairing
	 * add-with-carry instructions we accumulate 32-bit
	 * values into a 64-bit register.  At the end of the
	 * loop we fold it down to 32-bits and so on.
	 */
	prefetch	[%o0 + 0x140], #n_reads
1:	lduw		[%o0 + 0x00], %o5
	lduw		[%o0 + 0x04], %g1
	lduw		[%o0 + 0x08], %g2
	add		%o4, %o5, %o4
	lduw		[%o0 + 0x0c], %g3
	add		%o4, %g1, %o4
	lduw		[%o0 + 0x10], %o5
	add		%o4, %g2, %o4
	lduw		[%o0 + 0x14], %g1
	add		%o4, %g3, %o4
	lduw		[%o0 + 0x18], %g2
	add		%o4, %o5, %o4
	lduw		[%o0 + 0x1c], %g3
	add		%o4, %g1, %o4
	lduw		[%o0 + 0x20], %o5
	add		%o4, %g2, %o4
	lduw		[%o0 + 0x24], %g1
	add		%o4, %g3, %o4
	lduw		[%o0 + 0x28], %g2
	add		%o4, %o5, %o4
	lduw		[%o0 + 0x2c], %g3
	add		%o4, %g1, %o4
	lduw		[%o0 + 0x30], %o5
	add		%o4, %g2, %o4
	lduw		[%o0 + 0x34], %g1
	add		%o4, %g3, %o4
	lduw		[%o0 + 0x38], %g2
	add		%o4, %o5, %o4
	lduw		[%o0 + 0x3c], %g3
	add		%o4, %g1, %o4
	prefetch	[%o0 + 0x180], #n_reads
	add		%o4, %g2, %o4
	subcc		%o3, 0x40, %o3
	add		%o0, 0x40, %o0
	bne,pt		%icc, 1b
	 add		%o4, %g3, %o4

2:	and		%o1, 0x3c, %o3
	brz,pn		%o3, 2f
	 sub		%o1, %o3, %o1
1:	lduw		[%o0 + 0x00], %o5
	subcc		%o3, 0x4, %o3
	add		%o0, 0x4, %o0
	bne,pt		%icc, 1b
	 add		%o4, %o5, %o4

2:
	/* fold 64-->32 */
	srlx		%o4, 32, %o5
	srl		%o4, 0, %o4
	add		%o4, %o5, %o4
	srlx		%o4, 32, %o5
	srl		%o4, 0, %o4
	add		%o4, %o5, %o4

	/* fold 32-->16 */
	sethi		%hi(0xffff0000), %g1
	srl		%o4, 16, %o5
	andn		%o4, %g1, %g2
	add		%o5, %g2, %o4
	srl		%o4, 16, %o5
	andn		%o4, %g1, %g2
	add		%o5, %g2, %o4

csum_partial_end_cruft:
	/* %o4 has the 16-bit sum we have calculated so-far.  */
	cmp		%o1, 2
	blu,pt		%icc, 1f
	 nop
	lduh		[%o0 + 0x00], %o5
	sub		%o1, 2, %o1
	add		%o0, 2, %o0
	add		%o4, %o5, %o4
1:	brz,pt		%o1, 1f
	 nop
	ldub		[%o0 + 0x00], %o5
	sub		%o1, 1, %o1
	add		%o0, 1, %o0
	sllx		%o5, 8, %o5
	add		%o4, %o5, %o4
1:
	/* fold 32-->16 */
	sethi		%hi(0xffff0000), %g1
	srl		%o4, 16, %o5
	andn		%o4, %g1, %g2
	add		%o5, %g2, %o4
	srl		%o4, 16, %o5
	andn		%o4, %g1, %g2
	add		%o5, %g2, %o4

1:	brz,pt		%g7, 1f
	 nop

	/* We started with an odd byte, byte-swap the result.  */
	srl		%o4, 8, %o5
	and		%o4, 0xff, %g1
	sll		%g1, 8, %g1
	or		%o5, %g1, %o4

1:	addcc		%o2, %o4, %o2
	addc		%g0, %o2, %o2

csum_partial_finish:
	retl
	 srl		%o2, 0, %o0
OpenPOWER on IntegriCloud