doc: Brush up QPaintEngine documentation for Qt 5
[profile/ivi/qtbase.git] / src / gui / painting / qdrawhelper_mips_dsp_asm.S
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 MIPS Technologies, www.mips.com, author Damir Tatalovic <dtatalovic@mips.com>
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.  For licensing terms and
14 ** conditions see http://qt.digia.com/licensing.  For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights.  These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file.  Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qt_mips_asm_dsp.h"
43
44 LEAF_MIPS_DSP(destfetchARGB32_asm_mips_dsp)
45 /*
46  * a0 - buffer address (dst)
47  * a1 - data address (src)
48  * a2 - length
49  */
50
51     beqz              a2, 2f
52      move             v0, a0         /* just return the address of buffer
53                                       * for storing returning values */
54     move              v0, a0
55     andi              t1, a2, 0x1
56     li                t7, 8388736    /* t7 = 0x800080 */
57     beqz              t1, 1f
58      nop
59     lw                t8, 0(a1)
60     addiu             a2, a2, -1
61     srl               t6, t8, 24     /* t6 = alpha */
62
63     preceu.ph.qbra    t0, t8
64     mul               t1, t0, t6
65     preceu.ph.qbla    t4, t8
66     mul               t5, t4, t6
67
68     preceu.ph.qbla    t2, t1
69     addq.ph           t3, t1, t2
70     addq.ph           t3, t3, t7
71     preceu.ph.qbla    t1, t3         /* t1 holds R & B blended with alpha
72                                       * | 0 | dRab | 0 | dBab | */
73     preceu.ph.qbla    t2, t5
74     addq.ph           t3, t2, t5
75     addq.ph           t4, t3, t7
76     preceu.ph.qbla    t2, t4         /* t2 holds A & G blended with alpha
77                                       * | 0 | dAab | 0 | dGab | */
78     andi              t2, t2, 255    /* t2 = 0xff */
79
80     sll               t0, t6, 24
81     sll               t3, t2, 8
82     or                t4, t0, t3
83     or                t0, t1, t4
84     sw                t0, 0(a0)
85     addiu             a0, a0, 4
86     addiu             a1, a1, 4
87     beqz              a2, 2f         /* there was only one member */
88      nop
89 1:
90     lw                t0, 0(a1)      /* t0 = src1 */
91     lw                t1, 4(a1)      /* t1 = src2 */
92     precrq.qb.ph      t4, t0, t1     /* t4 = a1 G1 a2 G2 */
93     preceu.ph.qbra    t3, t4         /* t3 = 0 G1 0 G2 */
94     preceu.ph.qbla    t2, t4         /* t2 = | 0 | a1 | 0 | a2 | */
95     srl               t5, t2, 8
96     or                t8, t2, t5     /* t8 = 0 a1 a1 a2 */
97     muleu_s.ph.qbr    t5, t8, t3
98
99     addiu             a2, a2, -2
100     addiu             a1, a1, 8
101     precrq.ph.w       t9, t0, t1
102     preceu.ph.qbra    t9, t9
103
104     preceu.ph.qbla    t6, t5
105     addq.ph           t5, t5, t6
106     addq.ph           t2, t5, t7
107     muleu_s.ph.qbr    t6, t8, t9
108     sll               t3, t1, 16
109     packrl.ph         t3, t0, t3
110     preceu.ph.qbra    t3, t3
111     muleu_s.ph.qbr    t8, t8, t3
112     preceu.ph.qbla    t3, t6
113     addq.ph           t3, t6, t3
114     addq.ph           t3, t3, t7
115     preceu.ph.qbla    t5, t8
116     addq.ph           t5, t8, t5
117     addq.ph           t5, t5, t7
118
119     precrq.ph.w       t0, t4, t3     /* t0 = | 0 |  a1 | 0 | dR1 | */
120     precrq.ph.w       t1, t2, t5     /* t1 = | 0 | dG1 | 0 | dB1 | */
121     precrq.qb.ph      t6, t0, t1     /* t6 = | a1 | dR1 | dG1 | dB1 | */
122     sll               t3, t3, 16
123     sll               t5, t5, 16
124     packrl.ph         t0, t4, t3
125     packrl.ph         t1, t2, t5
126     precrq.qb.ph      t8, t0, t1     /* t8 = | a2 | dR2 | dG2 | dB2 | */
127     sw                t6, 0(a0)
128     sw                t8, 4(a0)
129     bnez              a2, 1b
130      addiu            a0, a0, 8
131 2:
132     j                 ra
133      nop
134
135 END(destfetchARGB32_asm_mips_dsp)
136
137 LEAF_MIPS_DSP(qt_memfill32_asm_mips_dsp)
138 /*
139  * a0 - destination address (dst)
140  * a1 - value
141  * a2 - count
142  */
143
144     beqz      a2, 5f
145      nop
146     li        t8, 8
147     andi      t0, a2, 0x7    /* t0 holds how many counts exceeds 8 */
148     beqzl     t0, 2f         /* count is multiple of 8 (8, 16, 24, ....) */
149      addiu    a2, a2, -8
150     subu      a2, a2, t0
151 1:
152     sw        a1, 0(a0)
153     addiu     t0, t0, -1
154     bnez      t0, 1b
155      addiu    a0, a0, 4
156     bgeu      a2, t8, 2f
157      addiu    a2, a2, -8
158     b         5f
159      nop
160 2:
161     beqz      a2, 4f
162      nop
163 3:
164     pref      30, 32(a0)
165     addiu     a2, a2, -8
166     sw        a1, 0( a0)
167     sw        a1, 4(a0)
168     sw        a1, 8(a0)
169     sw        a1, 12(a0)
170     addiu     a0, a0, 32
171     sw        a1, -16(a0)
172     sw        a1, -12(a0)
173     sw        a1, -8(a0)
174     bnez      a2, 3b
175      sw       a1, -4(a0)
176 4:
177     sw        a1, 0(a0)
178     sw        a1, 4(a0)
179     sw        a1, 8(a0)
180     sw        a1, 12(a0)
181     addiu     a0, a0, 32
182     sw        a1, -16(a0)
183     sw        a1, -12(a0)
184     sw        a1, -8(a0)
185     sw        a1, -4(a0)
186 5:
187     jr        ra
188      nop
189
190 END(qt_memfill32_asm_mips_dsp)
191
192 LEAF_MIPS_DSP(comp_func_SourceOver_asm_mips_dsp)
193 /*
194  * a0 - uint *dest
195  * a1 - const uint *src
196  * a2 - int length
197  * a3 - uint const_alpha
198  */
199
200     beqz              a2, 5f
201      nop
202     li                t8, 0xff
203     li                t7, 8388736    /* t7 = 0x800080 */
204     bne               a3, t8, 4f
205      nop
206
207 /* part where const_alpha = 255 */
208     b                 2f
209      nop
210 1:
211     addiu             a0, a0, 4
212     addiu             a2, a2, -1
213     beqz              a2, 5f
214      nop
215 2:
216     lw                t0, 0(a1)      /* t0 = s = src[i] */
217     addiu             a1, a1, 4
218     nor               t1, t0, zero
219     srl               t1, t1, 24     /* t1 = ~qAlpha(s) */
220     bnez              t1, 3f
221      nop
222     sw                t0, 0(a0)      /* dst[i] = src[i] */
223     addiu             a2, a2, -1
224     bnez              a2, 2b
225      addiu            a0, a0, 4
226     b 5f
227      nop
228 3:
229     beqz              t0, 1b
230      nop
231
232     lw                t4, 0(a0)
233     replv.ph          t6, t1
234     muleu_s.ph.qbl    t2, t4, t6
235     muleu_s.ph.qbr    t3, t4, t6
236     addiu             a2, a2, -1
237     preceu.ph.qbla    t4, t2
238     addq.ph           t4, t2, t4
239     addq.ph           t4, t4, t7
240     preceu.ph.qbla    t5, t3
241     addq.ph           t5, t5, t3
242     addq.ph           t5, t5, t7
243     precrq.qb.ph      t8, t4, t5    /* t8 = | dsA | dsR | dsG | dsB | */
244     addu              t8, t0, t8    /* dst[i] =
245                                      * s + BYTE_MUL(dst[i],~qAlpha(s)) */
246     sw                t8, 0(a0)
247     bnez              a2, 2b
248      addiu            a0, a0, 4
249     b                 5f
250      nop
251 4:
252     lw                t0, 0(a0)     /* t0 - dst[i] "1" */
253     lw                t1, 0(a1)     /* t1 - src[i] "2" */
254     addiu             a1, a1, 4
255     addiu             a2, a2, -1
256     replv.ph          t6, a3        /* a1 = 0x00a00a */
257     muleu_s.ph.qbl    t2, t1, t6
258     muleu_s.ph.qbr    t3, t1, t6
259     preceu.ph.qbla    t4, t2
260     addq.ph           t4, t2, t4
261     addq.ph           t4, t4, t7
262     preceu.ph.qbla    t5, t3
263     addq.ph           t5, t5, t3
264     addq.ph           t5, t5, t7
265     precrq.qb.ph      t8, t4, t5    /* t8 = | dsA | dsR | dsG | dsB | */
266
267     nor               t6, t8, zero
268     srl               t6, t6, 24
269     replv.ph          t6, t6
270
271     muleu_s.ph.qbl    t2, t0, t6
272     muleu_s.ph.qbr    t3, t0, t6
273     preceu.ph.qbla    t4, t2
274     addq.ph           t4, t2, t4
275     addq.ph           t4, t4, t7
276     preceu.ph.qbla    t5, t3
277     addq.ph           t5, t5, t3
278     addq.ph           t5, t5, t7
279     precrq.qb.ph      t6, t4, t5    /* t6 = | ddA | ddR | ddG | ddB | */
280
281     addu              t0, t8, t6
282     sw                t0, 0(a0)
283     bnez              a2, 4b
284      addiu            a0, a0, 4
285 5:
286     jr                ra
287      nop
288
289 END(comp_func_SourceOver_asm_mips_dsp)
290
291 LEAF_MIPS_DSPR2(qt_destStoreARGB32_asm_mips_dsp)
292 /*
293  * a0 - uint * data
294  * a1 - const uint *buffer
295  * a2 - int length
296  */
297
298     blez      a2, 6f
299     move      v1, zero
300     li        t0, 255
301     lui       a3, 0xff
302     j         2f
303      lui      t2, 0xff00
304 1:
305     addiu     v1, v1, 1
306     sw        zero, 0(a0)
307     addiu     a1, a1, 4
308     beq       v1, a2, 6f
309     addiu     a0, a0, 4
310 2:
311     lw        v0, 0(a1)
312     srl       t3, v0, 0x18
313     beql      t3, t0, 5f
314     addiu     v1, v1, 1
315     beqz      t3, 1b
316
317     srl       t1, v0, 0x8
318     andi      t1, t1, 0xff
319
320     teq       t3, zero, 0x7
321     div       zero, a3, t3
322     move      t8, t3
323     andi      t6, v0, 0xff
324
325     srl       t3,v0,0x10
326     andi      t3,t3,0xff
327
328     and       t5, v0, t2
329     mflo      t4
330
331     mult      $ac0, t4, t6
332     mult      $ac1, t1, t4
333     mul       t4, t3, t4
334
335     sltiu     t8, t8, 2
336     beqz      t8, 3f
337      nop
338     mflo      t6, $ac0
339     mflo      t1, $ac1
340     sra       t6, t6, 0x10
341     sra       t1, t1, 0x8
342     b         4f
343      nop
344 3:
345     extr.w    t6, $ac0, 0x10
346     extr.w    t1, $ac1, 0x8
347 4:
348     and       v0, t4, a3
349     or        v0, v0, t6
350     or        v0, v0, t5
351     andi      t1, t1, 0xff00
352     or        v0, v0, t1
353     addiu     v1, v1, 1
354 5:
355     sw        v0, 0(a0)
356     addiu     a1, a1, 4
357     bne       v1, a2, 2b
358     addiu     a0, a0, 4
359 6:
360     jr        ra
361      nop
362
363 END(qt_destStoreARGB32_asm_mips_dsp)
364
365 LEAF_MIPS_DSP(comp_func_solid_Source_dsp_asm_x2)
366 /*
367  * a0 - const uint *dest
368  * a1 - int length
369  * a2 - uint color
370  * a3 - uint ialpha
371  */
372
373     beqz              a1, 2f
374      nop
375     replv.ph          a3, a3
376     li                t9, 8388736    /* t9 = 0x800080 */
377 1:
378     lw                t0, 0(a0)
379     lw                t1, 4(a0)
380     or                t2, t0, t1    /* if both dest are zero, no computation needed */
381     beqz              t2, 12f
382      addiu             a1, -2
383
384     BYTE_MUL_x2 t0, t1, t6, t7, a3, a3, t9, t2, t3, t4, t5, 0
385 11:
386     addu              t2, a2, t6
387     addu              t3, a2, t7
388     sw                t2, 0(a0)
389     sw                t3, 4(a0)
390     bnez              a1, 1b
391      addiu             a0, 8
392     b                 2f
393 12:
394     addu              t2, a2, t0
395     addu              t3, a2, t1
396     sw                t2, 0(a0)
397     sw                t3, 4(a0)
398     bnez              a1, 1b
399      addiu             a0, 8
400 2:
401     jr                ra
402      nop
403
404 END(comp_func_solid_Source_dsp_asm_x2)
405
406 LEAF_MIPS_DSP(comp_func_solid_DestinationOver_dsp_asm_x2)
407 /*
408  * a0 - uint *dest
409  * a1 - int length
410  * a2 - uint color
411  */
412
413     addiu             sp, sp, -8
414     sw                s0, 0(sp)
415     sw                s1, 4(sp)
416     beqz              a1, 2f
417      nop
418     beqz              a2, 2f
419      nop
420     li                t9, 8388736    /* t4 = 0x800080 */
421
422 1:
423     lw                t0, 0(a0)
424     lw                t1, 4(a0)
425     not               t2, t0
426     not               t3, t1
427     srl               t4, t2, 24
428     srl               t5, t3, 24
429     or                t2, t4, t5    /* if both dest are zero, no computation needed */
430     beqz              t2, 11f
431      addiu             a1, -2
432     replv.ph          t2, t4
433     replv.ph          t3, t5
434
435     BYTE_MUL_x2 a2, a2, t8, a3, t2, t3, t9, t4, t5, t6, t7
436
437     addu              t0, t0, t8
438     addu              t1, t1, a3
439 11:
440     sw                t0, 0(a0)
441     sw                t1, 4(a0)
442     bnez              a1, 1b
443      addiu             a0, 8
444
445 2:
446     lw                s0, 0(sp)
447     lw                s1, 4(sp)
448     addiu             sp, sp, 8
449     jr                ra
450      nop
451
452 END(comp_func_solid_DestinationOver_dsp_asm_x2)
453
454 LEAF_MIPS_DSP(comp_func_DestinationOver_dsp_asm_x2)
455 /*
456  * a0 - uint *dest
457  * a1 - uint *src
458  * a2 - int length
459  * a3 - uint const_alpha
460  */
461
462     .set              noat
463     addiu             sp, sp, -8
464     sw                s0, 0(sp)
465     sw                s1, 4(sp)
466     beqz              a2, 3f
467      nop
468     li                t9, 8388736    /* t4 = 0x800080 */
469     li                t0, 0xff
470     beq               a3, t0, 2f
471      nop
472
473 /* part where const_alpha != 255 */
474 1:
475     replv.ph          a3, a3
476 11:
477     lw                t0, 0(a1)     # src_1
478     lw                t1, 4(a1)     # src_2
479     addiu             a2, -2
480
481     BYTE_MUL_x2 t0, t1, t8, AT, a3, a3, t9, t4, t5, t6, t7, 0
482                                     # t8 = s1
483                                     # AT = s2
484     lw                t0, 0(a0)     # dest_1
485     lw                t1, 4(a0)     # dest_2
486     addiu             a1, 8
487     not               t2, t0
488     not               t3, t1
489     srl               t4, t2, 24
490     srl               t5, t3, 24
491     replv.ph          t2, t4        # qAlpha(~d) 1
492     replv.ph          t3, t5        # qAlpha(~d) 2
493
494     BYTE_MUL_x2 t8, AT, s0, s1, t2, t3, t9, t4, t5, t6, t7
495
496     addu              t0, t0, s0
497     addu              t1, t1, s1
498     sw                t0, 0(a0)
499     sw                t1, 4(a0)
500     bnez              a2, 11b
501      addiu             a0, 8
502     b                 3f
503      nop
504
505 /* part where const_alpha = 255 */
506 2:
507     lw                t0, 0(a0)     # dest 1
508     lw                t1, 4(a0)     # dest 2
509     lw                s0, 0(a1)     # src 1
510     lw                s1, 4(a1)     # src 2
511     not               t2, t0
512     not               t3, t1
513     srl               t4, t2, 24
514     srl               t5, t3, 24
515     replv.ph          t2, t4
516     replv.ph          t3, t5
517     addiu             a1, 8
518     addiu             a2, -2
519
520     BYTE_MUL_x2 s0, s1, t8, AT, t2, t3, t9, t4, t5, t6, t7
521
522     addu              t0, t0, t8
523     addu              t1, t1, AT
524     sw                t0, 0(a0)
525     sw                t1, 4(a0)
526     bnez              a2, 2b
527      addiu             a0, 8
528
529 3:
530     lw                s0, 0(sp)
531     lw                s1, 4(sp)
532     addiu             sp, sp, 8
533     jr                ra
534      nop
535     .set              at
536
537 END(comp_func_DestinationOver_dsp_asm_x2)
538
539 LEAF_MIPS_DSP(comp_func_solid_SourceIn_dsp_asm_x2)
540 /*
541  * a0 - uint *dest
542  * a1 - int length
543  * a2 - uint color
544  * a3 - uint const_alpha
545  */
546
547     .set              noat
548     addiu             sp, -12
549     sw                s0, 0(sp)
550     sw                s1, 4(sp)
551     sw                s2, 8(sp)
552     beqz              a1, 3f
553      nop
554     li                t9, 8388736             /* t9 = 0x800080 (rounding_factor) */
555     lui               t8, 0xff00
556     li                t0, 0xff
557     beq               a3, t0, 2f
558      ori               t8, t8, 0xff00         /* t8 = 0xff00ff00 (andi_factor) */
559
560 /* part where const_alpha != 255 */
561 1:
562     replv.ph          t0, a3
563     li                t5, 0xff
564     BYTE_MUL a2, a2, t0, t9, t1, t2, t3, t4    /* a2 = color ( = BYTE_MUL(color, const_alpha)); */
565     subu              t1, t5, a3               /* t1 = cia = 255 - const_alpha */
566 11:
567     lw                t2, 0(a0)                /* t2 = d */
568     lw                s0, 4(a0)
569     addiu             a1, -2
570     srl               t3, t2, 24               /* t3 = qAlpha(d) */
571     srl               s2, s0, 24
572
573     INTERPOLATE_PIXEL_255 a2, t3, t2, t1, AT, t9, t8, t4, t5, t6, t7
574     INTERPOLATE_PIXEL_255 a2, s2, s0, t1, s1, t9, t8, t4, t5, t6, t7
575
576     sw                AT, 0(a0)
577     sw                s1, 4(a0)
578     bnez              a1, 11b
579      addiu            a0, 8
580     b                 3f
581      nop
582
583 /* part where const_alpha = 255 */
584 2:
585     lw                t0, 0(a0)                /* dest 1 */
586     lw                t1, 4(a0)                /* dest 2 */
587     srl               t4, t0, 24
588     srl               t5, t1, 24
589     replv.ph          t2, t4
590     replv.ph          t3, t5
591     addiu             a1, -2
592
593     BYTE_MUL_x2 a2, a2, t8, AT, t2, t3, t9, t4, t5, t6, t7
594
595     sw                t8, 0(a0)
596     sw                AT, 4(a0)
597     bnez              a1, 2b
598      addiu             a0, 8
599
600 3:
601     lw                s0, 0(sp)
602     lw                s1, 4(sp)
603     lw                s2, 8(sp)
604     addiu             sp, 12
605     jr                ra
606      nop
607     .set              at
608
609 END(comp_func_solid_SourceIn_dsp_asm_x2)
610
611 LEAF_MIPS_DSP(comp_func_SourceIn_dsp_asm_x2)
612 /*
613  * a0 - uint *dest
614  * a1 - const uint *src
615  * a2 - int length
616  * a3 - uint const_alpha
617  */
618
619     .set              noat
620     addiu             sp, -16
621     sw                s0, 0(sp)
622     sw                s1, 4(sp)
623     sw                s2, 8(sp)
624     sw                s3, 12(sp)
625     beqz              a2, 3f
626      nop
627     li                t9, 8388736             /* t9 = 0x800080 (rounding_factor) */
628     lui               t8, 0xff00
629     li                t0, 0xff
630     beq               a3, t0, 2f
631      ori               t8, t8, 0xff00         /* t8 = 0xff00ff00 (andi_factor) */
632
633 /* part where const_alpha != 255 */
634 1:
635     li                t5, 0xff
636     subu              t7, t5, a3               /* t7 = cia = 255 - const_alpha */
637     replv.ph          a3, a3
638 11:
639     lw                t0, 0(a1)                /* t0 = src 1 */
640     lw                t1, 4(a1)                /* t1 = src 2 */
641     addiu             a2, -2
642
643     BYTE_MUL_x2 t0, t1, AT, s0, a3, a3, t9, t3, t4, t5, t6, 0
644
645     lw                t0, 0(a0)                /* t0 = dest 1 */
646     lw                t1, 4(a0)                /* t1 = dest 2 */
647     addiu             a1, 8
648
649     srl               t2, t0, 24               /* t2 = qAlpha(d) 1 */
650     srl               t3, t1, 24               /* t3 = qAlpha(d) 2 */
651
652     INTERPOLATE_PIXEL_255 AT, t2, t0, t7, s1, t9, t8, t4, t5, t6, s3
653     INTERPOLATE_PIXEL_255 s0, t3, t1, t7, s2, t9, t8, t4, t5, t6, s3
654
655     sw                s1, 0(a0)
656     sw                s2, 4(a0)
657     bnez              a2, 11b
658      addiu            a0, 8
659     b                 3f
660      nop
661
662 /* part where const_alpha = 255 */
663 2:
664     lw                t2, 0(a0)                /* dest 1 */
665     lw                t3, 4(a0)                /* dest 2 */
666     lw                t0, 0(a1)                /* src 1 */
667     lw                t1, 4(a1)                /* src 2 */
668     srl               t4, t2, 24
669     srl               t5, t3, 24
670     replv.ph          t2, t4
671     replv.ph          t3, t5
672     addiu             a2, -2
673
674     BYTE_MUL_x2 t0, t1, t8, AT, t2, t3, t9, t4, t5, t6, t7
675
676     addiu             a1, 8
677     sw                t8, 0(a0)
678     sw                AT, 4(a0)
679     bnez              a2, 2b
680      addiu             a0, 8
681
682 3:
683     lw                s0, 0(sp)
684     lw                s1, 4(sp)
685     lw                s2, 8(sp)
686     lw                s3, 12(sp)
687     addiu             sp, 16
688     jr                ra
689      nop
690     .set              at
691
692 END(comp_func_SourceIn_dsp_asm_x2)
693
694 LEAF_MIPS_DSP(comp_func_solid_DestinationIn_dsp_asm_x2)
695 /*
696  * a0 - uint *dest
697  * a1 - int length
698  * a2 - uint a
699  */
700
701     .set              noat
702     beqz              a1, 2f
703      nop
704     li                t9, 8388736             /* t9 = 0x800080 (rounding_factor) */
705     replv.ph          a2, a2
706 1:
707     lw                t0, 0(a0)
708     lw                t1, 4(a0)
709     addiu             a1, -2
710
711     BYTE_MUL_x2 t0, t1, t8, AT, a2, a2, t9, t4, t5, t6, t7, 0
712
713     sw                t8, 0(a0)
714     sw                AT, 4(a0)
715     bnez              a1, 1b
716      addiu            a0, 8
717 2:
718     jr                ra
719      nop
720     .set              at
721
722 END(comp_func_solid_DestinationIn_dsp_asm_x2)
723
724 LEAF_MIPS_DSP(comp_func_DestinationIn_dsp_asm_x2)
725 /*
726  * a0 - uint *dest
727  * a1 - const uint *src
728  * a2 - int length
729  * a3 - uint const_alpha
730  */
731
732     addiu             sp, -8
733     sw                s0, 0(sp)
734     sw                s1, 4(sp)
735     beqz              a2, 3f
736      nop
737     li                t9, 8388736             /* t9 = 0x800080 (rounding_factor) */
738     li                t0, 0xff
739     beq               a3, t0, 2f
740      nop
741
742 /* part where const_alpha != 255 */
743 1:
744     li                t5, 0xff
745     subu              t8, t5, a3               /* t8 = cia = 255 - const_alpha */
746     replv.ph          a3, a3
747 11:
748     lw                t0, 0(a1)                /* t0 = src 1 */
749     lw                t1, 4(a1)                /* t1 = src 2 */
750     addiu             a2, -2
751     srl               t0, t0, 24
752     srl               t1, t1, 24
753
754     BYTE_MUL_x2 t0, t1, s1, t7, a3, a3, t9, t3, t4, t5, t6, 0
755
756     lw                t0, 0(a0)                /* t0 = dest 1 */
757     lw                t1, 4(a0)                /* t1 = dest 2 */
758     addu              s1, s1, t8               /* a 1 */
759     addu              t7, t7, t8               /* a 2 */
760     replv.ph          t2, s1
761     replv.ph          t3, t7
762
763     BYTE_MUL_x2 t0, t1, s1, t7, t2, t3, t9, t4, t5, t6, s0
764
765     addiu             a1, 8
766     sw                s1, 0(a0)
767     sw                t7, 4(a0)
768     bnez              a2, 11b
769      addiu            a0, 8
770     b                 3f
771      nop
772
773 /* part where const_alpha = 255 */
774 2:
775     lw                t2, 0(a1)                /* src 1 */
776     lw                t3, 4(a1)                /* src 2 */
777     lw                t0, 0(a0)                /* dest 1 */
778     lw                t1, 4(a0)                /* dest 2 */
779     srl               t4, t2, 24
780     srl               t5, t3, 24
781     replv.ph          t2, t4                   /* t2 = qAlpha(src 1) */
782     replv.ph          t3, t5                   /* t3 = qAlpha(src 2) */
783     addiu             a2, -2
784
785     BYTE_MUL_x2 t0, t1, t8, s1, t2, t3, t9, t4, t5, t6, t7
786
787     addiu             a1, 8
788     sw                t8, 0(a0)
789     sw                s1, 4(a0)
790     bnez              a2, 2b
791      addiu             a0, 8
792
793 3:
794     lw                s0, 0(sp)
795     lw                s1, 4(sp)
796     addiu             sp, 8
797     jr                ra
798      nop
799
800 END(comp_func_DestinationIn_dsp_asm_x2)
801
802 LEAF_MIPS_DSP(comp_func_DestinationOut_dsp_asm_x2)
803 /*
804  * a0 - uint *dest
805  * a1 - const uint *src
806  * a2 - int length
807  * a3 - uint const_alpha
808  */
809
810     .set              noat
811     addiu             sp, -4
812     sw                s0, 0(sp)
813     beqz              a2, 3f
814      nop
815     li                t9, 8388736             /* t9 = 0x800080 (rounding_factor) */
816     li                t0, 0xff
817     beq               a3, t0, 2f
818      nop
819
820 /* part where const_alpha != 255 */
821 1:
822     li                t5, 0xff
823     subu              t8, t5, a3               /* t8 = cia = 255 - const_alpha */
824     replv.ph          a3, a3
825 11:
826     lw                t0, 0(a1)                /* t0 = src 1 */
827     lw                t1, 4(a1)                /* t1 = src 2 */
828     not               t0, t0
829     not               t1, t1
830     addiu             a2, -2
831     srl               t0, t0, 24
832     srl               t1, t1, 24
833
834     BYTE_MUL_x2       t0, t1, AT, t7, a3, a3, t9, t3, t4, t5, t6, 0
835
836     lw                t0, 0(a0)                /* t0 = dest 1 */
837     lw                t1, 4(a0)                /* t1 = dest 2 */
838     addu              AT, AT, t8               /* a 1 */
839     addu              t7, t7, t8               /* a 2 */
840     replv.ph          t2, AT
841     replv.ph          t3, t7
842
843     BYTE_MUL_x2 t0, t1, AT, t7, t2, t3, t9, t4, t5, t6, s0
844
845     addiu             a1, 8
846     sw                AT, 0(a0)
847     sw                t7, 4(a0)
848     bnez              a2, 11b
849      addiu            a0, 8
850     b                 3f
851      nop
852
853 /* part where const_alpha = 255 */
854 2:
855     lw                t2, 0(a1)                /* src 1 */
856     lw                t3, 4(a1)                /* src 2 */
857     not               t2, t2
858     not               t3, t3
859     lw                t0, 0(a0)                /* dest 1 */
860     lw                t1, 4(a0)                /* dest 2 */
861     srl               t4, t2, 24
862     srl               t5, t3, 24
863     replv.ph          t2, t4                   /* t2 = qAlpha(src 1) */
864     replv.ph          t3, t5                   /* t3 = qAlpha(src 2) */
865     addiu             a2, -2
866
867     BYTE_MUL_x2 t0, t1, t8, AT, t2, t3, t9, t4, t5, t6, t7
868
869     addiu             a1, 8
870     sw                t8, 0(a0)
871     sw                AT, 4(a0)
872     bnez              a2, 2b
873      addiu             a0, 8
874
875 3:
876     lw                s0, 0(sp)
877     addiu             sp, 4
878     jr                ra
879      nop
880     .set              at
881
882 END(comp_func_DestinationOut_dsp_asm_x2)
883
884 LEAF_MIPS_DSP(comp_func_solid_SourceAtop_dsp_asm_x2)
885 /*
886  * a0 - uint *dest
887  * a1 - int length
888  * a2 - uint color
889  * a3 - uint sia
890  */
891
892     .set              noat
893     addu              sp, -4
894     sw                s0, 0(sp)
895     beqz              a1, 2f
896      nop
897     li                t9, 8388736              /* t9 = 0x800080 (rounding_factor) */
898     lui               t8, 0xff00
899     ori               t8, t8, 0xff00           /* t8 = 0xff00ff00 (andi_factor) */
900 1:
901     lw                t0, 0(a0)                /* t0 = dest 1 */
902     lw                t1, 4(a0)                /* t1 = dest 2 */
903     addiu             a1, -2
904     srl               t2, t0, 24               /* t2 = qAlpha(dest 1) */
905     srl               t3, t1, 24               /* t3 = qAlpha(dest 2) */
906
907     INTERPOLATE_PIXEL_255 a2, t2, t0, a3, AT, t9, t8, t4, t5, t6, t7
908     INTERPOLATE_PIXEL_255 a2, t3, t1, a3, s0, t9, t8, t4, t5, t6, t7
909
910     sw                AT, 0(a0)
911     sw                s0, 4(a0)
912     bnez              a1, 1b
913      addiu            a0, 8
914 2:
915     lw                s0, 0(sp)
916     addiu             sp, 4
917     jr                ra
918      nop
919     .set              at
920
921 END(comp_func_solid_SourceAtop_dsp_asm_x2)
922
923 LEAF_MIPS_DSP(comp_func_SourceAtop_dsp_asm_x2)
924 /*
925  * a0 - uint *dest
926  * a1 - const uint *src
927  * a2 - int length
928  * a3 - uint const_alpha
929  */
930
931     .set              noat
932     addiu             sp, -20
933     sw                s0, 0(sp)
934     sw                s1, 4(sp)
935     sw                s2, 8(sp)
936     sw                s3, 12(sp)
937     sw                s4, 16(sp)
938     beqz              a2, 3f
939      nop
940     li                t9, 8388736             /* t9 = 0x800080 (rounding_factor) */
941     lui               t8, 0xff00
942     li                t0, 0xff
943     beq               a3, t0, 2f
944      ori               t8, t8, 0xff00         /* t8 = 0xff00ff00 (andi_factor) */
945
946 /* part where const_alpha != 255 */
947 1:
948     replv.ph          a3, a3
949 11:
950     lw                AT, 0(a1)                /* src 1 */
951     lw                s0, 4(a1)                /* src 2 */
952
953     BYTE_MUL_x2 AT, s0, t0, t1, a3, a3, t9, t3, t4, t5, t6, 0
954                                                /* t0 = s */
955
956     lw                t2, 0(a0)                /* t2 = dest 1 */
957     lw                t3, 4(a0)                /* t3 = dest 2 */
958
959     srl               t4, t2, 24               /* t4 = qAplpha(dest 1) */
960     srl               t5, t3, 24
961     not               t6, t0
962     not               t7, t1
963     srl               t6, t6, 24               /* t6 = qAlpha(~s) */
964     srl               t7, t7, 24
965     addiu             a2, -2
966
967     INTERPOLATE_PIXEL_255 t0, t4, t2, t6, AT, t9, t8, s1, s2, s3, s4
968     INTERPOLATE_PIXEL_255 t1, t5, t3, t7, s0, t9, t8, s1, s2, s3, s4
969
970     addiu             a1, 8
971     sw                AT, 0(a0)
972     sw                s0, 4(a0)
973     bnez              a2, 11b
974      addiu             a0, 8
975     b                 3f
976      nop
977
978 /* part where const_alpha = 255 */
979 2:
980     lw                t2, 0(a0)                /* dest 1 */
981     lw                t3, 4(a0)                /* dest 2 */
982     lw                t0, 0(a1)                /* src 1 */
983     lw                t1, 4(a1)                /* src 2 */
984     srl               t4, t2, 24
985     srl               t5, t3, 24
986     not               t6, t0
987     not               t7, t1
988     srl               t6, t6, 24
989     srl               t7, t7, 24
990     addiu             a2, -2
991
992     INTERPOLATE_PIXEL_255 t0, t4, t2, t6, AT, t9, t8, s1, s2, s3, s4
993     INTERPOLATE_PIXEL_255 t1, t5, t3, t7, s0, t9, t8, s1, s2, s3, s4
994
995     addiu             a1, 8
996     sw                AT, 0(a0)
997     sw                s0, 4(a0)
998     bnez              a2, 2b
999      addiu             a0, 8
1000
1001 3:
1002     lw                s0, 0(sp)
1003     lw                s1, 4(sp)
1004     lw                s2, 8(sp)
1005     lw                s3, 12(sp)
1006     lw                s4, 16(sp)
1007     addiu             sp, 20
1008     jr                 ra
1009      nop
1010     .set              at
1011
1012 END(comp_func_SourceAtop_dsp_asm_x2)
1013
1014 LEAF_MIPS_DSP(comp_func_solid_DestinationAtop_dsp_asm_x2)
1015 /*
1016  * a0 - uint *dest
1017  * a1 - int length
1018  * a2 - uint color
1019  * a3 - uint a
1020  */
1021
1022     .set              noat
1023     addiu             sp, -4
1024     sw                s0, 0(sp)
1025     beqz              a1, 2f
1026      nop
1027     li                t9, 8388736              /* t9 = 0x800080 (rounding_factor) */
1028     lui               t8, 0xff00
1029     ori               t8, t8, 0xff00           /* t8 = 0xff00ff00 (andi_factor) */
1030 1:
1031     lw                t0, 0(a0)                /* t0 = dest 1 */
1032     lw                t1, 4(a0)                /* t1 = dest 2 */
1033     addiu             a1, -2
1034     not               t2, t0
1035     not               t3, t1
1036     srl               t2, t2, 24               /* t2 = qAlpha(~(dest 1)) */
1037     srl               t3, t3, 24               /* t3 = qAlpha(~(dest 2)) */
1038
1039     INTERPOLATE_PIXEL_255 t0, a3, a2, t2, AT, t9, t8, t4, t5, t6, t7
1040     INTERPOLATE_PIXEL_255 t1, a3, a2, t3, s0, t9, t8, t4, t5, t6, t7
1041
1042     sw                AT, 0(a0)
1043     sw                s0, 4(a0)
1044     bnez              a1, 1b
1045      addiu            a0, 8
1046 2:
1047     lw                s0, 0(sp)
1048     addiu              sp, 4
1049     jr                ra
1050      nop
1051     .set              at
1052
1053 END(comp_func_solid_DestinationAtop_dsp_asm_x2)
1054
1055 LEAF_MIPS_DSP(comp_func_DestinationAtop_dsp_asm_x2)
1056 /*
1057  * a0 - uint *dest
1058  * a1 - const uint *src
1059  * a2 - int length
1060  * a3 - uint const_alpha
1061  */
1062
1063     .set              noat
1064     addiu             sp, -24
1065     sw                s0, 0(sp)
1066     sw                s1, 4(sp)
1067     sw                s2, 8(sp)
1068     sw                s3, 12(sp)
1069     sw                s4, 16(sp)
1070     sw                s5, 20(sp)
1071     beqz              a2, 3f
1072      nop
1073     li                t9, 8388736             /* t9 = 0x800080 (rounding_factor) */
1074     lui               t8, 0xff00
1075     li                t0, 0xff
1076     beq               a3, t0, 2f
1077      ori               t8, t8, 0xff00         /* t8 = 0xff00ff00 (andi_factor) */
1078
1079 /* part where const_alpha != 255 */
1080 1:
1081     li                s5, 0xff
1082     subu              s5, s5, a3               /* s5 = cia = 255 - const_alpha */
1083     replv.ph          a3, a3
1084 11:
1085     lw                AT, 0(a1)                /* src 1 */
1086     lw                s0, 4(a1)                /* src 2 */
1087
1088     BYTE_MUL_x2 AT, s0, t0, t1, a3, a3, t9, t3, t4, t5, t6, 0
1089                                                /* t0 = s */
1090
1091     lw                t2, 0(a0)                /* t2 = dest 1 */
1092     lw                t3, 4(a0)                /* t3 = dest 2 */
1093
1094     not               t4, t2
1095     not               t5, t3
1096     srl               t4, t4, 24               /* t4 = qAplpha(~(dest 1)) */
1097     srl               t5, t5, 24
1098     srl               t6, t0, 24
1099     srl               t7, t1, 24
1100     addu              t6, t6, s5               /* t6 = a = qAlpha(s1) + cia */
1101     addu              t7, t7, s5
1102     addiu             a2, -2
1103
1104     INTERPOLATE_PIXEL_255 t2, t6, t0, t4, AT, t9, t8, s1, s2, s3, s4
1105     INTERPOLATE_PIXEL_255 t3, t7, t1, t5, s0, t9, t8, s1, s2, s3, s4
1106
1107     addiu             a1, 8
1108     sw                AT, 0(a0)
1109     sw                s0, 4(a0)
1110     bnez              a2, 11b
1111      addiu             a0, 8
1112     b                 3f
1113      nop
1114
1115 /* part where const_alpha = 255 */
1116 2:
1117     lw                t2, 0(a0)                /* d1 */
1118     lw                t3, 4(a0)                /* d2 */
1119     lw                t0, 0(a1)                /* s1 */
1120     lw                t1, 4(a1)                /* s2 */
1121     srl               t4, t0, 24               /* t4 = qAlpha(s1) */
1122     srl               t5, t1, 24
1123     not               t6, t2
1124     not               t7, t3
1125     srl               t6, t6, 24               /* qAlpha(~d1) */
1126     srl               t7, t7, 24
1127     addiu             a2, -2
1128
1129     INTERPOLATE_PIXEL_255 t2, t4, t0, t6, AT, t9, t8, s1, s2, s3, s4
1130     INTERPOLATE_PIXEL_255 t3, t5, t1, t7, s0, t9, t8, s1, s2, s3, s4
1131
1132     addiu             a1, 8
1133     sw                AT, 0(a0)
1134     sw                s0, 4(a0)
1135     bnez              a2, 2b
1136      addiu             a0, 8
1137
1138 3:
1139     lw                s0, 0(sp)
1140     lw                s1, 4(sp)
1141     lw                s2, 8(sp)
1142     lw                s3, 12(sp)
1143     lw                s4, 16(sp)
1144     lw                s5, 20(sp)
1145     addiu             sp, 24
1146     jr                ra
1147      nop
1148     .set              at
1149
1150 END(comp_func_DestinationAtop_dsp_asm_x2)
1151
1152 LEAF_MIPS_DSP(comp_func_solid_XOR_dsp_asm_x2)
1153 /*
1154  * a0 - uint *dest
1155  * a1 - int length
1156  * a2 - uint color
1157  * a3 - uint sia
1158  */
1159
1160     .set              noat
1161     addu              sp, -4
1162     sw                s0, 0(sp)
1163     beqz              a1, 2f
1164      nop
1165     li                t9, 8388736              /* t9 = 0x800080 (rounding_factor) */
1166     lui               t8, 0xff00
1167     ori               t8, t8, 0xff00           /* t8 = 0xff00ff00 (andi_factor) */
1168 1:
1169     lw                t0, 0(a0)                /* t0 = dest 1 */
1170     lw                t1, 4(a0)                /* t1 = dest 2 */
1171     addiu             a1, -2
1172     not               t2, t0
1173     not               t3, t1
1174     srl               t2, t2, 24               /* t2 = qAlpha(~(dest 1)) */
1175     srl               t3, t3, 24               /* t3 = qAlpha(~(dest 2)) */
1176
1177     INTERPOLATE_PIXEL_255 a2, t2, t0, a3, AT, t9, t8, t4, t5, t6, t7
1178     INTERPOLATE_PIXEL_255 a2, t3, t1, a3, s0, t9, t8, t4, t5, t6, t7
1179
1180     sw                AT, 0(a0)
1181     sw                s0, 4(a0)
1182     bnez              a1, 1b
1183      addiu            a0, 8
1184 2:
1185     lw                s0, 0(sp)
1186     addu              sp, 4
1187     jr                ra
1188      nop
1189     .set              at
1190
1191 END(comp_func_solid_XOR_dsp_asm_x2)
1192
1193 LEAF_MIPS_DSP(comp_func_XOR_dsp_asm_x2)
1194 /*
1195  * a0 - uint *dest
1196  * a1 - const uint *src
1197  * a2 - int length
1198  * a3 - uint const_alpha
1199  */
1200
1201     .set              noat
1202     addiu             sp, -20
1203     sw                s0, 0(sp)
1204     sw                s1, 4(sp)
1205     sw                s2, 8(sp)
1206     sw                s3, 12(sp)
1207     sw                s4, 16(sp)
1208     beqz              a2, 3f
1209      nop
1210     li                t9, 8388736             /* t9 = 0x800080 (rounding_factor) */
1211     lui               t8, 0xff00
1212     li                t0, 0xff
1213     beq               a3, t0, 2f
1214      ori               t8, t8, 0xff00         /* t8 = 0xff00ff00 (andi_factor) */
1215
1216 /* part where const_alpha != 255 */
1217 1:
1218     replv.ph          a3, a3
1219 11:
1220     lw                AT, 0(a1)                /* src 1 */
1221     lw                s0, 4(a1)                /* src 2 */
1222
1223     BYTE_MUL_x2 AT, s0, t0, t1, a3, a3, t9, t3, t4, t5, t6, 0
1224                                                /* t0 = s1 */
1225                                                /* t1 = s2 */
1226
1227     lw                t2, 0(a0)                /* t2 = dest 1 */
1228     lw                t3, 4(a0)                /* t3 = dest 2 */
1229
1230     not               t4, t2
1231     not               t5, t3
1232     srl               t4, t4, 24               /* t4 = qAplpha(~(dest 1)) */
1233     srl               t5, t5, 24
1234     not               t6, t0
1235     not               t7, t1
1236     srl               t6, t6, 24               /* t6 = qAlpha(~s) */
1237     srl               t7, t7, 24
1238     addiu             a2, -2
1239
1240     INTERPOLATE_PIXEL_255 t0, t4, t2, t6, AT, t9, t8, s1, s2, s3, s4
1241     INTERPOLATE_PIXEL_255 t1, t5, t3, t7, s0, t9, t8, s1, s2, s3, s4
1242
1243     addiu             a1, 8
1244     sw                AT, 0(a0)
1245     sw                s0, 4(a0)
1246     bnez              a2, 11b
1247      addiu             a0, 8
1248     b                 3f
1249      nop
1250
1251 /* part where const_alpha = 255 */
1252 2:
1253     lw                t2, 0(a0)                /* d1 */
1254     lw                t3, 4(a0)                /* d2 */
1255     lw                t0, 0(a1)                /* s1 */
1256     lw                t1, 4(a1)                /* s2 */
1257     not               t4, t0
1258     not               t5, t1
1259     srl               t4, t4, 24               /* t4 = qAlpha(~s1) */
1260     srl               t5, t5, 24
1261     not               t6, t2
1262     not               t7, t3
1263     srl               t6, t6, 24               /* qAlpha(~d1) */
1264     srl               t7, t7, 24
1265     addiu             a2, -2
1266
1267     INTERPOLATE_PIXEL_255 t0, t6, t2, t4, AT, t9, t8, s1, s2, s3, s4
1268     INTERPOLATE_PIXEL_255 t1, t7, t3, t5, s0, t9, t8, s1, s2, s3, s4
1269
1270     addiu             a1, 8
1271     sw                AT, 0(a0)
1272     sw                s0, 4(a0)
1273     bnez              a2, 2b
1274      addiu             a0, 8
1275
1276 3:
1277     lw                s0, 0(sp)
1278     lw                s1, 4(sp)
1279     lw                s2, 8(sp)
1280     lw                s3, 12(sp)
1281     lw                s4, 16(sp)
1282     addiu             sp, 20
1283     jr                ra
1284      nop
1285     .set              at
1286
1287 END(comp_func_XOR_dsp_asm_x2)
1288
1289 LEAF_MIPS_DSP(comp_func_solid_SourceOut_dsp_asm_x2)
1290 /*
1291  * a0 - uint *dest
1292  * a1 - int length
1293  * a2 - uint color
1294  * a3 - uint const_alpha
1295  */
1296
1297     .set              noat
1298     addiu             sp, -12
1299     sw                s0, 0(sp)
1300     sw                s1, 4(sp)
1301     sw                s2, 8(sp)
1302     beqz              a1, 3f
1303      nop
1304     li                t9, 8388736             /* t9 = 0x800080 (rounding_factor) */
1305     lui               t8, 0xff00
1306     li                t0, 0xff
1307     beq               a3, t0, 2f
1308      ori               t8, t8, 0xff00         /* t8 = 0xff00ff00 (andi_factor) */
1309
1310 /* part where const_alpha != 255 */
1311 1:
1312     replv.ph          t0, a3
1313     li                t5, 0xff
1314     BYTE_MUL a2, a2, t0, t9, t1, t2, t3, t4    /* a2 = color ( = BYTE_MUL(color, const_alpha)); */
1315     subu              t1, t5, a3               /* t1 = cia = 255 - const_alpha */
1316 11:
1317     lw                t2, 0(a0)                /* t2 = d1 */
1318     lw                s0, 4(a0)                /* s0 = d2 */
1319     addiu             a1, -2
1320     not               t3, t2
1321     not               s2, s0
1322     srl               t3, t3, 24               /* t3 = qAlpha(~d1) */
1323     srl               s2, s2, 24               /* s2 = qAlpha(~d2) */
1324
1325     INTERPOLATE_PIXEL_255 a2, t3, t2, t1, AT, t9, t8, t4, t5, t6, t7
1326     INTERPOLATE_PIXEL_255 a2, s2, s0, t1, s1, t9, t8, t4, t5, t6, t7
1327
1328     sw                AT, 0(a0)
1329     sw                s1, 4(a0)
1330     bnez              a1, 11b
1331      addiu            a0, 8
1332     b                 3f
1333      nop
1334
1335 /* part where const_alpha = 255 */
1336 2:
1337     lw                t0, 0(a0)                /* dest 1 */
1338     lw                t1, 4(a0)                /* dest 2 */
1339     not               t4, t0
1340     not               t5, t1
1341     srl               t4, t4, 24
1342     srl               t5, t5, 24
1343     replv.ph          t2, t4
1344     replv.ph          t3, t5
1345     addiu             a1, -2
1346
1347     BYTE_MUL_x2 a2, a2, t8, AT, t2, t3, t9, t4, t5, t6, t7
1348
1349     sw                t8, 0(a0)
1350     sw                AT, 4(a0)
1351     bnez              a1, 2b
1352      addiu             a0, 8
1353
1354 3:
1355     lw                s0, 0(sp)
1356     lw                s1, 4(sp)
1357     lw                s2, 8(sp)
1358     addiu             sp, 12
1359     jr                ra
1360      nop
1361     .set              at
1362
1363 END(comp_func_solid_SourceOut_dsp_asm_x2)
1364
1365 LEAF_MIPS_DSP(comp_func_SourceOut_dsp_asm_x2)
1366 /*
1367  * a0 - uint *dest
1368  * a1 - const uint *src
1369  * a2 - int length
1370  * a3 - uint const_alpha
1371  */
1372
1373     .set              noat
1374     addiu             sp, -16
1375     sw                s0, 0(sp)
1376     sw                s1, 4(sp)
1377     sw                s2, 8(sp)
1378     sw                s3, 12(sp)
1379     beqz              a2, 3f
1380      nop
1381     li                t9, 8388736             /* t9 = 0x800080 (rounding_factor) */
1382     lui               t8, 0xff00
1383     li                t0, 0xff
1384     beq               a3, t0, 2f
1385      ori               t8, t8, 0xff00         /* t8 = 0xff00ff00 (andi_factor) */
1386
1387 /* part where const_alpha != 255 */
1388 1:
1389     li                t5, 0xff
1390     subu              t7, t5, a3               /* t7 = cia = 255 - const_alpha */
1391     replv.ph          a3, a3
1392 11:
1393     lw                t0, 0(a1)                /* t0 = src 1 */
1394     lw                t1, 4(a1)                /* t1 = src 2 */
1395     addiu             a2, -2
1396
1397     BYTE_MUL_x2 t0, t1, AT, s0, a3, a3, t9, t3, t4, t5, t6, 0
1398
1399     lw                t0, 0(a0)                /* t0 = dest 1 */
1400     lw                t1, 4(a0)                /* t1 = dest 2 */
1401     addiu             a1, 8
1402
1403     not               t2, t0
1404     not               t3, t1
1405     srl               t2, t2, 24               /* t2 = qAlpha(~d1) */
1406     srl               t3, t3, 24               /* t3 = qAlpha(~d2) */
1407
1408     INTERPOLATE_PIXEL_255 AT, t2, t0, t7, s1, t9, t8, t4, t5, t6, s3
1409     INTERPOLATE_PIXEL_255 s0, t3, t1, t7, s2, t9, t8, t4, t5, t6, s3
1410
1411     sw                s1, 0(a0)
1412     sw                s2, 4(a0)
1413     bnez              a2, 11b
1414      addiu            a0, 8
1415     b                 3f
1416      nop
1417
1418 /* part where const_alpha = 255 */
1419 2:
1420     lw                t2, 0(a0)                /* dest 1 */
1421     lw                t3, 4(a0)                /* dest 2 */
1422     lw                t0, 0(a1)                /* src 1 */
1423     lw                t1, 4(a1)                /* src 2 */
1424     not               t4, t2
1425     not               t5, t3
1426     srl               t4, t4, 24               /* qAlpha(~d1) */
1427     srl               t5, t5, 24               /* qAlpha(~d2) */
1428     replv.ph          t2, t4
1429     replv.ph          t3, t5
1430     addiu             a2, -2
1431
1432     BYTE_MUL_x2 t0, t1, t8, AT, t2, t3, t9, t4, t5, t6, t7
1433
1434     addiu             a1, 8
1435     sw                t8, 0(a0)
1436     sw                AT, 4(a0)
1437     bnez              a2, 2b
1438      addiu             a0, 8
1439
1440 3:
1441     lw                s0, 0(sp)
1442     lw                s1, 4(sp)
1443     lw                s2, 8(sp)
1444     lw                s3, 12(sp)
1445     addiu             sp, 16
1446     jr                 ra
1447      nop
1448     .set              at
1449
1450 END(comp_func_SourceOut_dsp_asm_x2)
1451
1452 LEAF_MIPS_DSP(comp_func_Source_dsp_asm_x2)
1453 /*
1454  * a0 - uint *dest
1455  * a1 - const uint *src
1456  * a2 - int length
1457  * a3 - uint const_alpha
1458  */
1459
1460     .set              noat
1461     addiu             sp, -8
1462     sw                s0, 0(sp)
1463     sw                s1, 4(sp)
1464     beqz              a2, 2f
1465      nop
1466     li                t9, 8388736              /* t9 = 0x800080 (rounding_factor) */
1467     lui               t8, 0xff00
1468     ori               t8, t8, 0xff00           /* t8 = 0xff00ff00 (andi_factor) */
1469     li                t7, 0xff
1470     subu              t7, t7, a3               /* t7 = ialpha */
1471 1:
1472     lw                t0, 0(a0)                /* t0 = dest 1 */
1473     lw                t1, 4(a0)                /* t1 = dest 2 */
1474     lw                t2, 0(a1)                /* t2 = src 1 */
1475     lw                t3, 4(a1)                /* t3 = src 2 */
1476     addiu             a2, -2
1477     addiu             a1, 8
1478
1479     INTERPOLATE_PIXEL_255 t2, a3, t0, t7, AT, t9, t8, t4, t5, t6, s1
1480     INTERPOLATE_PIXEL_255 t3, a3, t1, t7, s0, t9, t8, t4, t5, t6, s1
1481
1482     sw                AT, 0(a0)
1483     sw                s0, 4(a0)
1484     bnez              a2, 1b
1485      addiu            a0, 8
1486 2:
1487     lw                s0, 0(sp)
1488     lw                s1, 4(sp)
1489     addiu             sp, 8
1490     jr                ra
1491      nop
1492     .set              at
1493
1494 END(comp_func_Source_dsp_asm_x2)
1495
1496 LEAF_MIPS_DSP(qt_blend_argb32_on_argb32_mips_dsp_asm_x2)
1497 /*
1498  * a0 - uint *dest
1499  * a1 - const uint *src
1500  * a2 - int length
1501  * a3 - uint const_alpha
1502  */
1503
1504     .set              noat
1505     addiu             sp, -12
1506     sw                s0, 0(sp)
1507     sw                s1, 4(sp)
1508     sw                s2, 8(sp)
1509     beqz              a2, 2f
1510      nop
1511     replv.ph          a3, a3
1512     li                t9, 8388736             /* t9 = 0x800080 (rounding_factor) */
1513
1514 1:
1515     lw                t0, 0(a1)                /* t0 = src 1 */
1516     lw                t1, 4(a1)                /* t1 = src 2 */
1517     addiu             a2, -2
1518
1519     BYTE_MUL_x2       t0, t1, AT, t7, a3, a3, t9, t3, t4, t5, t6, 0
1520
1521     lw                t0, 0(a0)                /* t0 = dest 1 */
1522     lw                t1, 4(a0)                /* t1 = dest 2 */
1523     not               s1, AT
1524     not               s2, t7
1525     srl               s1, s1, 24               /* s1 = qAlpha(~s1) */
1526     srl               s2, s2, 24               /* s2 = qAlpha(~s2) */
1527     replv.ph          s1, s1
1528     replv.ph          s2, s2
1529
1530     BYTE_MUL_x2 t0, t1, t2, t3, s1, s2, t9, t4, t5, t6, s0
1531
1532     addiu             a1, 8
1533     addu              AT, AT, t2
1534     addu              t7, t7, t3
1535     sw                AT, 0(a0)
1536     sw                t7, 4(a0)
1537     bnez              a2, 1b
1538      addiu            a0, 8
1539
1540 2:
1541     lw                s0, 0(sp)
1542     lw                s1, 4(sp)
1543     lw                s2, 8(sp)
1544     addiu             sp, 12
1545     jr                ra
1546      nop
1547     .set              at
1548
1549 END(qt_blend_argb32_on_argb32_mips_dsp_asm_x2)
1550
1551 LEAF_MIPS_DSP(qt_blend_argb32_on_argb32_const_alpha_256_mips_dsp_asm)
1552 /*
1553  * a0 - uint *dest
1554  * a1 - const uint *src
1555  * a2 - int length
1556  */
1557
1558     beqz              a2, 5f
1559      nop
1560     li                t7, 8388736    /* t7 = 0x800080 */
1561     b                 2f
1562      nop
1563 1:
1564     addiu             a0, a0, 4
1565     addiu             a2, a2, -1
1566     beqz              a2, 5f
1567      nop
1568 2:
1569     lw                t0, 0(a1)      /* t0 = s = src[i] */
1570     addiu             a1, a1, 4
1571     nor               t1, t0, zero
1572     srl               t1, t1, 24     /* t1 = ~qAlpha(s) */
1573     bnez              t1, 3f
1574      nop
1575     sw                t0, 0(a0)      /* dst[i] = src[i] */
1576     addiu             a2, a2, -1
1577     bnez              a2, 2b
1578      addiu            a0, a0, 4
1579     b 5f
1580      nop
1581 3:
1582     beqz              t0, 1b
1583      replv.ph          t6, t1        /* | 0 | qAlpha(~s) | 0 | qAlpha(~s) | */
1584
1585     lw                t4, 0(a0)
1586     addiu             a2, a2, -1
1587     beqz              t4, 31f
1588      move             t8, zero
1589
1590     BYTE_MUL t4, t8, t6, t7, t1, t2, t3, t4
1591 31:
1592     addu              t8, t0, t8    /* dst[i] =
1593                                      * s + BYTE_MUL(dst[i],~qAlpha(s)) */
1594     sw                t8, 0(a0)
1595     bnez              a2, 2b
1596      addiu            a0, a0, 4
1597     b                 5f
1598      nop
1599 5:
1600     jr                ra
1601      nop
1602
1603 END(qt_blend_argb32_on_argb32_const_alpha_256_mips_dsp_asm)