summaryrefslogtreecommitdiffstats
path: root/src/gui/painting/qdrawhelper_armv6_rvct.inc
blob: f6c23d05d2962b77ed8891ef3b09b8da93e3e053 (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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
;/****************************************************************************
;**
;** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
;** Contact: Nokia Corporation (qt-info@nokia.com)
;**
;** This file is part of the QtGui module of the Qt Toolkit.
;**
;** $QT_BEGIN_LICENSE:LGPL$
;** No Commercial Usage
;** This file contains pre-release code and may not be distributed.
;** You may use this file in accordance with the terms and conditions
;** contained in the either Technology Preview License Agreement or the
;** Beta Release License Agreement.
;**
;** GNU Lesser General Public License Usage
;** Alternatively, this file may be used under the terms of the GNU Lesser
;** General Public License version 2.1 as published by the Free Software
;** Foundation and appearing in the file LICENSE.LGPL included in the
;** packaging of this file.  Please review the following information to
;** ensure the GNU Lesser General Public License version 2.1 requirements
;** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
;**
;** In addition, as a special exception, Nokia gives you certain
;** additional rights. These rights are described in the Nokia Qt LGPL
;** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
;** package.
;**
;** GNU General Public License Usage
;** Alternatively, this file may be used under the terms of the GNU
;** General Public License version 3.0 as published by the Free Software
;** Foundation and appearing in the file LICENSE.GPL included in the
;** packaging of this file.  Please review the following information to
;** ensure the GNU General Public License version 3.0 requirements will be
;** met: http://www.gnu.org/copyleft/gpl.html.
;**
;** If you are unsure which license is appropriate for your use, please
;** contact the sales department at http://www.qtsoftware.com/contact.
;** $QT_END_LICENSE$
;**
;****************************************************************************/

;
;  W A R N I N G
;  -------------
;
; This file is not part of the Qt API.  It exists purely as an
; implementation detail.  This header file may change from version to
; version without notice, or even be removed.
;
; We mean it.
;

;-----------------------------------------------------------------------------
; Globals.
; Earch marcro expects that caller has loaded 0x800080 to r14.
;-----------------------------------------------------------------------------

ComponentHalf	EQU	0x800080

;-----------------------------------------------------------------------------
; ARM assembly implementations of accelerated graphics operations.
;
; Conventions:
;
; 	- r0 = Target buffer pointer
;	- r1 = Source buffer pointer
; 	- r2 = Length of the buffer to blend
;	- r3 = Constant alpha for source buffer
;
;-----------------------------------------------------------------------------

; A macro for transparently defining ARM functions
		MACRO
$func	Function
		AREA Function_$func, CODE
		GLOBAL $func
		ALIGN 4
		CODE32
$func
		MEND


;-----------------------------------------------------------------------------
; Armv6 boosted implementation of BYTE_MUL(...) function found in qdrawhelper_p.h.
;
;  @param dst	Destination register where to store the result
;  @param x     Value to multiply
;  @param a     Multiplicator byte
;  @param r14   Component half 0x800080
;
;  @note Trashes x, r8
;-----------------------------------------------------------------------------
		MACRO
		ByteMul $dst, $x, $a

		; static inline uint BYTE_MUL(uint x, uint a)

		; uint r8 = (x & 0xff00ff) * a + 0x800080
		uxtb16	r8, $x	; r8 = r8 & 0x00FF00FF
		mla		r8, r8, $a, r14

		; x = ((r >> 8) & 0xff00ff) * a + 0x800080
		uxtb16	$x, $x, ror #8
		mla		$x, $x, $a, r14


		; r8 = (r8 + ((r8 >> 8) & 0xff00ff) ) >> 8
		; r8 &= 0xff00ff
		uxtab16	r8, r8, r8, ror #8
		uxtb16	r8, r8, ror #8

		; x = x + ((x >>8) & 0xff00ff)
		uxtab16	$x, $x, $x, ror #8

		; x &= 0xff00ff00
		; x |= r8
		uxtb16	$x, $x, ror #8
		orr		$dst, r8, $x, lsl #8

		MEND

;-----------------------------------------------------------------------------
; Armv6 boosted implementation of INTERPOLATE_PIXEL_255(...) function found in
; qdrawhelper_p.h.
;
;  @param dst	Destination register where to store the result
;  @param x     First value to multiply
;  @param a		Multiplicator byte for first value
;  @param y     Second value to multiply
;  @param b     Multiplicator byte for second value
;  @param r14   Component half 0x800080
;
;
;  @note Trashes x, r8, r14
;-----------------------------------------------------------------------------
		MACRO
		InterpolatePixel255 $dst, $x, $a, $y, $b

		; static inline uint INTERPOLATE_PIXEL_255(uint x, uint a, uint y, uint b)

		; First calculate the parts where we need 0x800080

		; uint r8 = (((x & 0xff00ff) * a) + 0x800080)
		uxtb16	r8, $x	; r8 = r8 & 0x00FF00FF
		mla		r8, r8, $a, r14

		; x = ((((x >> 8) & 0xff00ff) * a) + 0x800080)
		uxtb16	$x, $x, ror #8
		mla		$x, $x, $a, r14

		; Now we are trashing r14 to free it for other purposes

		; uint r14 = (y & 0xff00ff) * b
		uxtb16	r14, $y	; r14 = y & 0x00FF00FF
		mul		r14, r14, $b

		; r8 = r8 + r14
		add		r8, r8, r14

		; r8 = (r8 + ((r8 >> 8) & 0xff00ff) ) >> 8
		; r8 &= 0xff00ff
		uxtab16	r8, r8, r8, ror #8
		uxtb16	r8, r8, ror #8

		; r14 = ((y >> 8) & 0xff00ff) * b
		uxtb16	r14, $y, ror #8	; r14 = ((y >> 8) & 0xFF00FF)
		mul		r14, r14, $b

		; x = x + r14
		add		$x, $x, r14

		; x = x + ((x >>8) & 0xff00ff)
		uxtab16	$x, $x, $x, ror #8

		; x &= 0xff00ff00
		; x |= r8
		uxtb16	$x, $x, ror #8
		orr		$dst, r8, $x, lsl #8

		MEND

;-----------------------------------------------------------------------------
;
;-----------------------------------------------------------------------------
		MACRO
$label	Blend4Pixels $BlendPixel

		; Blend first 4 pixels

		ldmia	r1!, {r4-r7}
		ldm		r0, {r9-r12}

b4p1_$label	$BlendPixel r9, r4, r3
b4p2_$label	$BlendPixel r10, r5, r3
b4p3_$label	$BlendPixel r11, r6, r3
b4p4_$label	$BlendPixel r12, r7, r3

		stmia 	r0!, {r9-r12}

		MEND

;-----------------------------------------------------------------------------
;
;-----------------------------------------------------------------------------
		MACRO
$label	Blend8Pixels $BlendPixel

b8p1_$label Blend4Pixels $BlendPixel
b8p2_$label Blend4Pixels $BlendPixel

		MEND

;-----------------------------------------------------------------------------
;
;-----------------------------------------------------------------------------
		MACRO
$label	Blend16Pixels $BlendPixel

b16p1_$label Blend8Pixels $BlendPixel
b16p2_$label Blend8Pixels $BlendPixel

		MEND

;-----------------------------------------------------------------------------
;
;-----------------------------------------------------------------------------
		MACRO
$label	Blend32Pixels $BlendPixel

b32p1_$label Blend16Pixels $BlendPixel
b32p2_$label Blend16Pixels $BlendPixel

		MEND

;-----------------------------------------------------------------------------
; A macro for source over compositing one row of pixels and saving the results
; to destination buffer.
;
; @param dest			Destination	buffer						(r0)
; @param src			Source buffer							(r1)
; @param length			Length									(r2)
; @param const_alpha	Constant alpha					  		(r3)
; @param r14 			Component Half (0x800080)		  		(r14)
;
;  @note Advances r0, r1
;  @note Trashes r2, r4-r12
;-----------------------------------------------------------------------------
		MACRO
$label	BlendRow $BlendPixel

		pld		[r1]

bloop_$label
		; Blend 32 pixels per loop iteration
		subs	r2, r2, #32
		bmi		b_remaining_$label

brp1_$label	Blend32Pixels $BlendPixel

		b		bloop_$label

b_remaining_$label

		; Remaining 31 pixels

		addmi	r2, r2, #32

		; Blend 16 pixels
		tst		r2, #16
		beq		b_remaining8_$label

brp2_$label Blend16Pixels $BlendPixel

b_remaining8_$label

		; Blend 8 pixels
		tst		r2, #8
		beq		b_remaining4_$label

brp3_$label Blend8Pixels $BlendPixel

b_remaining4_$label

		; Blend 4 pixels
		tst		r2, #4
		beq		b_remaining3_$label

brp4_$label Blend4Pixels $BlendPixel

b_remaining3_$label

		; Remaining 3 pixels

		tst		r2, #2
		beq		b_last_$label

		ldmia 	r1!, {r4-r5}
		ldm	  	r0,  {r9-r10}

brp5_$label	$BlendPixel r9, r4, r3
brp6_$label	$BlendPixel r10, r5, r3

		stmia 	r0!, {r9-r10}

b_last_$label

		tst		r2, #1
		beq		bexit_$label

		ldr		r4, [r1]
		ldr		r9, [r0]

bpl_$label	$BlendPixel r9, r4, r3

		str 	r9, [r0]

bexit_$label

		MEND

;-----------------------------------------------------------------------------
; A macro for source over compositing one row of pixels and saving the results
; to destination buffer. Restores all registers.
;
; @param dest			Destination	buffer						(r0)
; @param src			Source buffer							(r1)
; @param length			Length									(r2)
; @param const_alpha	Constant alpha					  		(r3)
; @param r14 			Component Half (0x800080)		  		(r14)
;
;  @note Advances r0, r1
;  @note Trashes r2, r4-r12
;-----------------------------------------------------------------------------
		MACRO
$label	BlendRowSafe $BlendPixel

		stmfd	sp!, {r0-r6} ; Preserves registers only up to r6

brs_$label  BlendRow $BlendPixel

		ldmfd	sp!, {r0-r6}

		MEND


;-----------------------------------------------------------------------------
; Pix Copy.
; NOTE! Cache line size of ARM1136JF-S and ARM1136J-S is 32 bytes (8 pixels).
;
; @param dst			Destination	pixels						(r0)
; @param src			Source pixels							(r1)
; @param len			Length									(r2)
;
;  @note Trashes r3-r10
;-----------------------------------------------------------------------------
		MACRO
$label	PixCpy $dst, $src, $len

		pld		[$src]

pcpy_loop_$label
		; Copy 8 pixels per loop iteration
		pld		[$src, #96]
		subs	$len, $len, #8
		ldmgeia	$src!, {r3-r10}
		stmgeia	$dst!, {r3-r10}
		bgt		pcpy_loop_$label

pcpy_remaining_$label

		; Copy up to 7 remaining pixels

		; Copy 4 pixels
		tst		$len, #4
		ldmneia	$src!, {r3-r6}
		stmneia	$dst!, {r3-r6}

		tst		$len, #2
		ldmneia	$src!, {r3-r4}
		stmneia	$dst!, {r3-r4}

		tst		$len, #1
		ldrne	r3, [$src]
		strne 	r3, [$dst]

		MEND

;-----------------------------------------------------------------------------
; General Pix Copy. Maximum 8 pixels at time. Restores all registers.
;
; @param dst			Destination	pixels						(r0)
; @param src			Source pixels							(r1)
; @param len			Length									(r2)
;
;  @note Trashes r3-r10
;-----------------------------------------------------------------------------
		MACRO
$label	PixCpySafe $dst, $src, $len

		stmfd	sp!, {r0-r6} ; Preserves registers only up to r6

pcs_$label  PixCpy $dst, $src, $len

		ldmfd	sp!, {r0-r6}		; pop

		MEND


;-----------------------------------------------------------------------------
; A macro for source over compositing one pixel and saving the result to
; dst register.
;
;  @param dst      Destination register, must contain destination pixel upon entry
;  @param src 	   Source register, must contain source pixel upon entry
;  @param const_alpha Constant source alpha
;  @param r14	   Component half 0x800080
;
;  @note Trashes const_alpha, r8
;-----------------------------------------------------------------------------
		MACRO
$label	PixelSourceOver $dst, $src, $const_alpha

		; Negate src and extract alpha
		mvn		$const_alpha, $src ; bitwise not
		uxtb	$const_alpha, $const_alpha, ror #24	; r3 = ((r3 & 0xFF000000) >> 24);

		;cmp		$const_alpha, #255	; test for full transparency ( negated )
		;beq		exit_$label
		cmp     $const_alpha, #0	            ; test for full opacity ( negated )
		moveq	$dst, $src
		beq		exit_$label

		ByteMul	$dst, $dst, $const_alpha
		add		$dst, $src, $dst

exit_$label
		MEND

;-----------------------------------------------------------------------------
; A macro for source over compositing one pixel and saving the result to
; dst register.
;
;  @param dst      Destination register, must contain destination pixel upon entry
;  @param src 	   Source register, must contain source pixel upon entry
;  @param const_alpha Constant source alpha
;  @param r14	   Component half 0x800080
;
;  @note Trashes src, const_alpha, r8
;-----------------------------------------------------------------------------
		MACRO
$label	PixelSourceOverConstAlpha $dst, $src, $const_alpha

		; store alpha because we are going to trash it
		stmfd	sp!, {$const_alpha}

		ByteMul	$src, $src, $const_alpha

		; Negate src and extract alpha
		mvn		$const_alpha, $src ; bitwise not
		uxtb	$const_alpha, $const_alpha, ror #24	; r3 = ((r3 & 0xFF000000) >> 24);

		ByteMul	$dst, $dst, $const_alpha

		add		$dst, $src, $dst

		; recover alpha
		ldmfd	sp!, {$const_alpha}

		MEND

;-----------------------------------------------------------------------------
; A macro for source over compositing one pixel and saving the result to
; a register.
;
;  @param dst      Destination register, must contain destination pixel upon entry
;  @param src 	   Source register, must contain source pixel upon entry
;  @param const_alpha Constant source alpha
;  @param r14	   Component half 0x800080
;
;  @note Trashes src, r8
;-----------------------------------------------------------------------------
		MACRO
$label	PixelSourceConstAlpha $dst, $src, $const_alpha

		; store r2 and r14 because we are going to trash them
		stmfd	sp!, {r2, r14}

		rsb		r2, $const_alpha, #255
		InterpolatePixel255 $dst, $src, $const_alpha, $dst, r2

		; recover r2 and r14
		ldmfd	sp!, {r2, r14}

		MEND

		END ; File end