summaryrefslogtreecommitdiff
path: root/draw/imagescalearm.s
blob: 2b90582be80b3b84b2f95b3c31c551d2ec140b74 (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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
@ imagescalearm.s is a hand tuned assembler version
@ of some of the imagescale functions targetted
@ for ARM based systems (any architecture version).
@
@ Copyright (C) 2010 Robin Watts for Artifex Software LLC.
@ <robin.watts@artifex.com> or <robin.watts@wss.co.uk>

        .file "imagescalearm.s"
        .global	fz_srow4_arm
        .global	fz_scol4_arm

	.type	fz_srow4_arm, %function
        .text

	@ r0 = src
	@ r1 = dst
	@ r2 = w
	@ r3 = denom
fz_srow4_arm:
	STMFD	r13!,{r3-r7,r9-r10,r14}

	MOV	r12,#1<<16		@ r12 = (1<<16)
	MOV	r14,#0			@ r14 = will contain invdenom

	@ r14 = r12/r3
	CMP	r12,r3, LSL #16
	SUBHS	r12,r12,r3, LSL #16
	ADDHS	r14,r14,#1<<16
	CMP	r12,r3, LSL #15
	SUBHS	r12,r12,r3, LSL #15
	ADDHS	r14,r14,#1<<15
	CMP	r12,r3, LSL #14
	SUBHS	r12,r12,r3, LSL #14
	ADDHS	r14,r14,#1<<14
	CMP	r12,r3, LSL #13
	SUBHS	r12,r12,r3, LSL #13
	ADDHS	r14,r14,#1<<13
	CMP	r12,r3, LSL #12
	SUBHS	r12,r12,r3, LSL #12
	ADDHS	r14,r14,#1<<12
	CMP	r12,r3, LSL #11
	SUBHS	r12,r12,r3, LSL #11
	ADDHS	r14,r14,#1<<11
	CMP	r12,r3, LSL #10
	SUBHS	r12,r12,r3, LSL #10
	ADDHS	r14,r14,#1<<10
	CMP	r12,r3, LSL #9
	SUBHS	r12,r12,r3, LSL #9
	ADDHS	r14,r14,#1<<9
	CMP	r12,r3, LSL #8
	SUBHS	r12,r12,r3, LSL #8
	ADDHS	r14,r14,#1<<8
	CMP	r12,r3, LSL #7
	SUBHS	r12,r12,r3, LSL #7
	ADDHS	r14,r14,#1<<7
	CMP	r12,r3, LSL #6
	SUBHS	r12,r12,r3, LSL #6
	ADDHS	r14,r14,#1<<6
	CMP	r12,r3, LSL #5
	SUBHS	r12,r12,r3, LSL #5
	ADDHS	r14,r14,#1<<5
	CMP	r12,r3, LSL #4
	SUBHS	r12,r12,r3, LSL #4
	ADDHS	r14,r14,#1<<4
	CMP	r12,r3, LSL #3
	SUBHS	r12,r12,r3, LSL #3
	ADDHS	r14,r14,#1<<3
	CMP	r12,r3, LSL #2
	SUBHS	r12,r12,r3, LSL #2
	ADDHS	r14,r14,#1<<2
	CMP	r12,r3, LSL #1
	SUBHS	r12,r12,r3, LSL #1
	ADDHS	r14,r14,#1<<1
	CMP	r12,r3
	SUBHS	r12,r12,r3
	ADDHS	r14,r14,#1

	@ r2 = x = w
	@ r3 = left = denom
	MOV	r10,#1<<15		@ r10= 1<<15
	B	.L_enter_loop_r4	@ Enter the loop
.L_store_r4:
	ADD	r7, r7, r12		@ r7 = sum3 += r12
	MLA	r4, r14,r4, r10		@ r4 = sum0 * invdenom + (1<<15)
	MLA	r5, r14,r5, r10		@ r5 = sum1 * invdenom + (1<<15)
	MLA	r6, r14,r6, r10		@ r6 = sum2 * invdenom + (1<<15)
	MLA	r7, r14,r7, r10		@ r7 = sum3 * invdenom + (1<<15)
	MOV	r4, r4, LSR #16		@ r4 = r4 >> 16
	MOV	r5, r5, LSR #16		@ r5 = r5 >> 16
	MOV	r6, r6, LSR #16		@ r6 = r6 >> 16
	MOV	r7, r7, LSR #16		@ r7 = r7 >> 16
	STRB	r4, [r1], #1		@ *dst++ = r4
	STRB	r5, [r1], #1		@ *dst++ = r5
	STRB	r6, [r1], #1		@ *dst++ = r6
	STRB	r7, [r1], #1		@ *dst++ = r7
	SUBS	r2, r2, #1		@ x--
	BEQ	.L_end_r4
	LDR	r3, [r13]		@ r3 = left = denom
.L_enter_loop_r4:
	MOV	r4, #0			@ r4 = sum0 = 0
	MOV	r5, #0			@ r5 = sum1 = 0
	MOV	r6, #0			@ r6 = sum2 = 0
	MOV	r7, #0			@ r7 = sum3 = 0
.L_x_loop_r4:
	LDRB	r9, [r0], #1		@ r9 = src++
	LDRB	r12,[r0], #1		@ r12= src++
	SUBS	r3, r3, #1		@ r3 = --left
	ADD	r4, r4, r9		@ r4 = sum0 += r9
	LDRB	r9, [r0], #1		@ r9 = src++
	ADD	r5, r5, r12		@ r5 = sum1 += r12
	LDRB	r12,[r0], #1		@ r12= src++
	ADD	r6, r6, r9		@ r9 = sum2 += r9
	BEQ	.L_store_r4
	ADD	r7, r7, r12		@ r7 = sum3 += r12
	SUBS	r2, r2, #1		@ x--
	BNE	.L_x_loop_r4

	@ Trailers
	LDR	r0, [r13]		@ r0 = denom
	MOV	r12,#1<<16		@ r12 = (1<<16)
	MOV	r14,#0			@ r14 = will contain invleft
	SUB	r3, r0, r3		@ r3 = denom-left
	CMP	r12,r3, LSL #16
	SUBHS	r12,r12,r3, LSL #16
	ADDHS	r14,r14,#1<<16
	CMP	r12,r3, LSL #15
	SUBHS	r12,r12,r3, LSL #15
	ADDHS	r14,r14,#1<<15
	CMP	r12,r3, LSL #14
	SUBHS	r12,r12,r3, LSL #14
	ADDHS	r14,r14,#1<<14
	CMP	r12,r3, LSL #13
	SUBHS	r12,r12,r3, LSL #13
	ADDHS	r14,r14,#1<<13
	CMP	r12,r3, LSL #12
	SUBHS	r12,r12,r3, LSL #12
	ADDHS	r14,r14,#1<<12
	CMP	r12,r3, LSL #11
	SUBHS	r12,r12,r3, LSL #11
	ADDHS	r14,r14,#1<<11
	CMP	r12,r3, LSL #10
	SUBHS	r12,r12,r3, LSL #10
	ADDHS	r14,r14,#1<<10
	CMP	r12,r3, LSL #9
	SUBHS	r12,r12,r3, LSL #9
	ADDHS	r14,r14,#1<<9
	CMP	r12,r3, LSL #8
	SUBHS	r12,r12,r3, LSL #8
	ADDHS	r14,r14,#1<<8
	CMP	r12,r3, LSL #7
	SUBHS	r12,r12,r3, LSL #7
	ADDHS	r14,r14,#1<<7
	CMP	r12,r3, LSL #6
	SUBHS	r12,r12,r3, LSL #6
	ADDHS	r14,r14,#1<<6
	CMP	r12,r3, LSL #5
	SUBHS	r12,r12,r3, LSL #5
	ADDHS	r14,r14,#1<<5
	CMP	r12,r3, LSL #4
	SUBHS	r12,r12,r3, LSL #4
	ADDHS	r14,r14,#1<<4
	CMP	r12,r3, LSL #3
	SUBHS	r12,r12,r3, LSL #3
	ADDHS	r14,r14,#1<<3
	CMP	r12,r3, LSL #2
	SUBHS	r12,r12,r3, LSL #2
	ADDHS	r14,r14,#1<<2
	CMP	r12,r3, LSL #1
	SUBHS	r12,r12,r3, LSL #1
	ADDHS	r14,r14,#1<<1
	CMP	r12,r3
	SUBHS	r12,r12,r3
	ADDHS	r14,r14,#1

	MLA	r4, r14,r4, r10		@ r4 = sum0 * invleft + (1<<15)
	MLA	r5, r14,r5, r10		@ r5 = sum1 * invleft + (1<<15)
	MLA	r6, r14,r6, r10		@ r6 = sum2 * invleft + (1<<15)
	MLA	r7, r14,r7, r10		@ r7 = sum3 * invleft + (1<<15)
	MOV	r4, r4, LSR #16		@ r4 = r4 >> 16
	MOV	r5, r5, LSR #16		@ r5 = r5 >> 16
	MOV	r6, r6, LSR #16		@ r6 = r6 >> 16
	MOV	r7, r7, LSR #16		@ r7 = r7 >> 16
	STRB	r4, [r1], #1		@ *dst++ = r4
	STRB	r5, [r1], #1		@ *dst++ = r5
	STRB	r6, [r1], #1		@ *dst++ = r6
	STRB	r7, [r1], #1		@ *dst++ = r7
.L_end_r4:
	LDMFD	r13!,{r3-r7,r9-r10,PC}

	.fnend
	.size	fz_srow4_arm, .-fz_srow4_arm

	.type	fz_scol4_arm, %function
        .text

	@ r0 = src
	@ r1 = dst
	@ r2 = w
	@ r3 = denom
fz_scol4_arm:
	STMFD	r13!,{r3-r7,r9-r11,r14}

	MOV	r12,#1<<16		@ r12 = (1<<16)
	MOV	r14,#0			@ r14 = will contain invdenom

	@ r14 = r12/r3
	CMP	r12,r3, LSL #16
	SUBHS	r12,r12,r3, LSL #16
	ADDHS	r14,r14,#1<<16
	CMP	r12,r3, LSL #15
	SUBHS	r12,r12,r3, LSL #15
	ADDHS	r14,r14,#1<<15
	CMP	r12,r3, LSL #14
	SUBHS	r12,r12,r3, LSL #14
	ADDHS	r14,r14,#1<<14
	CMP	r12,r3, LSL #13
	SUBHS	r12,r12,r3, LSL #13
	ADDHS	r14,r14,#1<<13
	CMP	r12,r3, LSL #12
	SUBHS	r12,r12,r3, LSL #12
	ADDHS	r14,r14,#1<<12
	CMP	r12,r3, LSL #11
	SUBHS	r12,r12,r3, LSL #11
	ADDHS	r14,r14,#1<<11
	CMP	r12,r3, LSL #10
	SUBHS	r12,r12,r3, LSL #10
	ADDHS	r14,r14,#1<<10
	CMP	r12,r3, LSL #9
	SUBHS	r12,r12,r3, LSL #9
	ADDHS	r14,r14,#1<<9
	CMP	r12,r3, LSL #8
	SUBHS	r12,r12,r3, LSL #8
	ADDHS	r14,r14,#1<<8
	CMP	r12,r3, LSL #7
	SUBHS	r12,r12,r3, LSL #7
	ADDHS	r14,r14,#1<<7
	CMP	r12,r3, LSL #6
	SUBHS	r12,r12,r3, LSL #6
	ADDHS	r14,r14,#1<<6
	CMP	r12,r3, LSL #5
	SUBHS	r12,r12,r3, LSL #5
	ADDHS	r14,r14,#1<<5
	CMP	r12,r3, LSL #4
	SUBHS	r12,r12,r3, LSL #4
	ADDHS	r14,r14,#1<<4
	CMP	r12,r3, LSL #3
	SUBHS	r12,r12,r3, LSL #3
	ADDHS	r14,r14,#1<<3
	CMP	r12,r3, LSL #2
	SUBHS	r12,r12,r3, LSL #2
	ADDHS	r14,r14,#1<<2
	CMP	r12,r3, LSL #1
	SUBHS	r12,r12,r3, LSL #1
	ADDHS	r14,r14,#1<<1
	CMP	r12,r3
	SUBHS	r12,r12,r3
	ADDHS	r14,r14,#1

	@ r2 = x = w
	@ r3 = y = denom
	MOV	r11,r2, LSL #2		@ r11= w = w*n
	RSB	r11,r11,#0		@ r11=-w
	MOV	r10,#1<<15		@ r10= 1<<15
.L_x_loop_c4:
	MOV	r4, #0			@ r4 = sum0 = 0
	MOV	r5, #0			@ r5 = sum1 = 0
	MOV	r6, #0			@ r6 = sum2 = 0
	MOV	r7, #0			@ r7 = sum3 = 0
.L_y_loop_c4:
	LDRB	r9, [r0, #1]		@ r9 = src[1]
	LDRB	r12,[r0, #2]		@ r12= src[2]
	SUBS	r3, r3, #1		@ r3 = y--
	ADD	r5, r5, r9		@ r4 = sum1 += r9
	LDRB	r9, [r0, #3]		@ r9 = src[3]
	ADD	r6, r6, r12		@ r5 = sum2 += r12
	LDRB	r12,[r0], -r11		@ r12= src[0]	src += w
	ADD	r7, r7, r9		@ r9 = sum3 += r9
	ADD	r4, r4, r12		@ r7 = sum0 += r12
	BGT	.L_y_loop_c4

	LDR	r3, [r13]		@ r3 = y = denom
	MLA	r4, r14,r4, r10		@ r4 = sum0 * invdenom + (1<<15)
	MLA	r5, r14,r5, r10		@ r5 = sum1 * invdenom + (1<<15)
	MLA	r6, r14,r6, r10		@ r6 = sum2 * invdenom + (1<<15)
	MLA	r7, r14,r7, r10		@ r7 = sum3 * invdenom + (1<<15)
	MLA	r0, r3, r11,r0		@ r0 = src += -denom*w
	MOV	r4, r4, LSR #16		@ r4 = r4 >> 16
	MOV	r5, r5, LSR #16		@ r5 = r5 >> 16
	MOV	r6, r6, LSR #16		@ r6 = r6 >> 16
	MOV	r7, r7, LSR #16		@ r7 = r7 >> 16
	ADD	r0, r0, #4		@ r0 = src += n
	STRB	r4, [r1], #1		@ *dst++ = r4
	STRB	r5, [r1], #1		@ *dst++ = r5
	STRB	r6, [r1], #1		@ *dst++ = r6
	STRB	r7, [r1], #1		@ *dst++ = r7
	SUBS	r2, r2, #1		@ x--
	BNE	.L_x_loop_c4

.L_end_c4:
	LDMFD	r13!,{r3-r7,r9-r11,PC}

	.fnend
	.size	fz_scol4_arm, .-fz_scol4_arm