summaryrefslogtreecommitdiff
path: root/gfx/cairo/libpixman/src/pixman-mips-dspr2-asm.S
blob: 9dad163b792e9fc690a385d4650551aff4be9e7c (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
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
/*
 * Copyright (c) 2012
 *      MIPS Technologies, Inc., California.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its
 *    contributors may be used to endorse or promote products derived from
 *    this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * Author:  Nemanja Lukic (nemanja.lukic@rt-rk.com)
 */

#include "pixman-private.h"
#include "pixman-mips-dspr2-asm.h"

LEAF_MIPS_DSPR2(pixman_fill_buff16_mips)
/*
 * a0 - *dest
 * a1 - count (bytes)
 * a2 - value to fill buffer with
 */

    beqz     a1, 3f
     andi    t1, a0, 0x0002
    beqz     t1, 0f          /* check if address is 4-byte aligned */
     nop
    sh       a2, 0(a0)
    addiu    a0, a0, 2
    addiu    a1, a1, -2
0:
    srl      t1, a1, 5       /* t1 how many multiples of 32 bytes */
    replv.ph a2, a2          /* replicate fill value (16bit) in a2 */
    beqz     t1, 2f
     nop
1:
    addiu    t1, t1, -1
    beqz     t1, 11f
     addiu   a1, a1, -32
    pref     30, 32(a0)
    sw       a2, 0(a0)
    sw       a2, 4(a0)
    sw       a2, 8(a0)
    sw       a2, 12(a0)
    sw       a2, 16(a0)
    sw       a2, 20(a0)
    sw       a2, 24(a0)
    sw       a2, 28(a0)
    b        1b
     addiu   a0, a0, 32
11:
    sw       a2, 0(a0)
    sw       a2, 4(a0)
    sw       a2, 8(a0)
    sw       a2, 12(a0)
    sw       a2, 16(a0)
    sw       a2, 20(a0)
    sw       a2, 24(a0)
    sw       a2, 28(a0)
    addiu    a0, a0, 32
2:
    blez     a1, 3f
     addiu   a1, a1, -2
    sh       a2, 0(a0)
    b        2b
     addiu   a0, a0, 2
3:
    jr       ra
     nop

END(pixman_fill_buff16_mips)

LEAF_MIPS32R2(pixman_fill_buff32_mips)
/*
 * a0 - *dest
 * a1 - count (bytes)
 * a2 - value to fill buffer with
 */

    beqz     a1, 3f
     nop
    srl      t1, a1, 5 /* t1 how many multiples of 32 bytes */
    beqz     t1, 2f
     nop
1:
    addiu    t1, t1, -1
    beqz     t1, 11f
     addiu   a1, a1, -32
    pref     30, 32(a0)
    sw       a2, 0(a0)
    sw       a2, 4(a0)
    sw       a2, 8(a0)
    sw       a2, 12(a0)
    sw       a2, 16(a0)
    sw       a2, 20(a0)
    sw       a2, 24(a0)
    sw       a2, 28(a0)
    b        1b
     addiu   a0, a0, 32
11:
    sw       a2, 0(a0)
    sw       a2, 4(a0)
    sw       a2, 8(a0)
    sw       a2, 12(a0)
    sw       a2, 16(a0)
    sw       a2, 20(a0)
    sw       a2, 24(a0)
    sw       a2, 28(a0)
    addiu    a0, a0, 32
2:
    blez     a1, 3f
     addiu   a1, a1, -4
    sw       a2, 0(a0)
    b        2b
     addiu   a0, a0, 4
3:
    jr       ra
     nop

END(pixman_fill_buff32_mips)

LEAF_MIPS_DSPR2(pixman_composite_src_8888_0565_asm_mips)
/*
 * a0 - dst (r5g6b5)
 * a1 - src (a8r8g8b8)
 * a2 - w
 */

    beqz     a2, 3f
     nop
    addiu    t1, a2, -1
    beqz     t1, 2f
     nop
    li       t4, 0xf800f800
    li       t5, 0x07e007e0
    li       t6, 0x001f001f
1:
    lw       t0, 0(a1)
    lw       t1, 4(a1)
    addiu    a1, a1, 8
    addiu    a2, a2, -2

    CONVERT_2x8888_TO_2x0565 t0, t1, t2, t3, t4, t5, t6, t7, t8

    sh       t2, 0(a0)
    sh       t3, 2(a0)

    addiu    t2, a2, -1
    bgtz     t2, 1b
     addiu   a0, a0, 4
2:
    beqz     a2, 3f
     nop
    lw       t0, 0(a1)

    CONVERT_1x8888_TO_1x0565 t0, t1, t2, t3

    sh       t1, 0(a0)
3:
    j        ra
     nop

END(pixman_composite_src_8888_0565_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_src_0565_8888_asm_mips)
/*
 * a0 - dst (a8r8g8b8)
 * a1 - src (r5g6b5)
 * a2 - w
 */

    beqz     a2, 3f
     nop
    addiu    t1, a2, -1
    beqz     t1, 2f
     nop
    li       t4, 0x07e007e0
    li       t5, 0x001F001F
1:
    lhu      t0, 0(a1)
    lhu      t1, 2(a1)
    addiu    a1, a1, 4
    addiu    a2, a2, -2

    CONVERT_2x0565_TO_2x8888 t0, t1, t2, t3, t4, t5, t6, t7, t8, t9

    sw       t2, 0(a0)
    sw       t3, 4(a0)

    addiu    t2, a2, -1
    bgtz     t2, 1b
     addiu   a0, a0, 8
2:
    beqz     a2, 3f
     nop
    lhu      t0, 0(a1)

    CONVERT_1x0565_TO_1x8888 t0, t1, t2, t3

    sw       t1, 0(a0)
3:
    j        ra
     nop

END(pixman_composite_src_0565_8888_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_src_x888_8888_asm_mips)
/*
 * a0 - dst (a8r8g8b8)
 * a1 - src (x8r8g8b8)
 * a2 - w
 */

    beqz     a2, 4f
     nop
    li       t9, 0xff000000
    srl      t8, a2, 3    /* t1 = how many multiples of 8 src pixels */
    beqz     t8, 3f       /* branch if less than 8 src pixels */
     nop
1:
    addiu    t8, t8, -1
    beqz     t8, 2f
     addiu   a2, a2, -8
    pref     0, 32(a1)
    lw       t0, 0(a1)
    lw       t1, 4(a1)
    lw       t2, 8(a1)
    lw       t3, 12(a1)
    lw       t4, 16(a1)
    lw       t5, 20(a1)
    lw       t6, 24(a1)
    lw       t7, 28(a1)
    addiu    a1, a1, 32
    or       t0, t0, t9
    or       t1, t1, t9
    or       t2, t2, t9
    or       t3, t3, t9
    or       t4, t4, t9
    or       t5, t5, t9
    or       t6, t6, t9
    or       t7, t7, t9
    pref     30, 32(a0)
    sw       t0, 0(a0)
    sw       t1, 4(a0)
    sw       t2, 8(a0)
    sw       t3, 12(a0)
    sw       t4, 16(a0)
    sw       t5, 20(a0)
    sw       t6, 24(a0)
    sw       t7, 28(a0)
    b        1b
     addiu   a0, a0, 32
2:
    lw       t0, 0(a1)
    lw       t1, 4(a1)
    lw       t2, 8(a1)
    lw       t3, 12(a1)
    lw       t4, 16(a1)
    lw       t5, 20(a1)
    lw       t6, 24(a1)
    lw       t7, 28(a1)
    addiu    a1, a1, 32
    or       t0, t0, t9
    or       t1, t1, t9
    or       t2, t2, t9
    or       t3, t3, t9
    or       t4, t4, t9
    or       t5, t5, t9
    or       t6, t6, t9
    or       t7, t7, t9
    sw       t0, 0(a0)
    sw       t1, 4(a0)
    sw       t2, 8(a0)
    sw       t3, 12(a0)
    sw       t4, 16(a0)
    sw       t5, 20(a0)
    sw       t6, 24(a0)
    sw       t7, 28(a0)
    beqz     a2, 4f
     addiu   a0, a0, 32
3:
    lw       t0, 0(a1)
    addiu    a1, a1, 4
    addiu    a2, a2, -1
    or       t1, t0, t9
    sw       t1, 0(a0)
    bnez     a2, 3b
     addiu   a0, a0, 4
4:
    jr       ra
     nop

END(pixman_composite_src_x888_8888_asm_mips)

#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
LEAF_MIPS_DSPR2(pixman_composite_src_0888_8888_rev_asm_mips)
/*
 * a0 - dst (a8r8g8b8)
 * a1 - src (b8g8r8)
 * a2 - w
 */

    beqz              a2, 6f
     nop

    lui               t8, 0xff00;
    srl               t9, a2, 2   /* t9 = how many multiples of 4 src pixels */
    beqz              t9, 4f      /* branch if less than 4 src pixels */
     nop

    li                t0, 0x1
    li                t1, 0x2
    li                t2, 0x3
    andi              t3, a1, 0x3
    beq               t3, t0, 1f
     nop
    beq               t3, t1, 2f
     nop
    beq               t3, t2, 3f
     nop

0:
    beqz              t9, 4f
     addiu            t9, t9, -1
    lw                t0, 0(a1)            /* t0 = R2 | B1 | G1 | R1 */
    lw                t1, 4(a1)            /* t1 = G3 | R3 | B2 | G2 */
    lw                t2, 8(a1)            /* t2 = B4 | G4 | R4 | B3 */

    addiu             a1, a1, 12
    addiu             a2, a2, -4

    wsbh              t0, t0               /* t0 = B1 | R2 | R1 | G1 */
    wsbh              t1, t1               /* t1 = R3 | G3 | G2 | B2 */
    wsbh              t2, t2               /* t2 = G4 | B4 | B3 | R4 */

    packrl.ph         t3, t1, t0           /* t3 = G2 | B2 | B1 | R2 */
    packrl.ph         t4, t0, t0           /* t4 = R1 | G1 | B1 | R2 */
    rotr              t3, t3, 16           /* t3 = B1 | R2 | G2 | B2 */
    or                t3, t3, t8           /* t3 = FF | R2 | G2 | B2 */
    srl               t4, t4, 8            /* t4 =  0 | R1 | G1 | B1 */
    or                t4, t4, t8           /* t4 = FF | R1 | G1 | B1 */
    packrl.ph         t5, t2, t1           /* t5 = B3 | R4 | R3 | G3 */
    rotr              t5, t5, 24           /* t5 = R4 | R3 | G3 | B3 */
    or                t5, t5, t8           /* t5 = FF | R3 | G3 | B3 */
    rotr              t2, t2, 16           /* t2 = B3 | R4 | G4 | B4 */
    or                t2, t2, t8           /* t5 = FF | R3 | G3 | B3 */

    sw                t4, 0(a0)
    sw                t3, 4(a0)
    sw                t5, 8(a0)
    sw                t2, 12(a0)
    b                 0b
     addiu            a0, a0, 16

1:
    lbu               t6, 0(a1)            /* t6 =  0 |  0 |  0 | R1 */
    lhu               t7, 1(a1)            /* t7 =  0 |  0 | B1 | G1 */
    sll               t6, t6, 16           /* t6 =  0 | R1 |  0 | 0  */
    wsbh              t7, t7               /* t7 =  0 |  0 | G1 | B1 */
    or                t7, t6, t7           /* t7 =  0 | R1 | G1 | B1 */
11:
    beqz              t9, 4f
     addiu            t9, t9, -1
    lw                t0, 3(a1)            /* t0 = R3 | B2 | G2 | R2 */
    lw                t1, 7(a1)            /* t1 = G4 | R4 | B3 | G3 */
    lw                t2, 11(a1)           /* t2 = B5 | G5 | R5 | B4 */

    addiu             a1, a1, 12
    addiu             a2, a2, -4

    wsbh              t0, t0               /* t0 = B2 | R3 | R2 | G2 */
    wsbh              t1, t1               /* t1 = R4 | G4 | G3 | B3 */
    wsbh              t2, t2               /* t2 = G5 | B5 | B4 | R5 */

    packrl.ph         t3, t1, t0           /* t3 = G3 | B3 | B2 | R3 */
    packrl.ph         t4, t2, t1           /* t4 = B4 | R5 | R4 | G4 */
    rotr              t0, t0, 24           /* t0 = R3 | R2 | G2 | B2 */
    rotr              t3, t3, 16           /* t3 = B2 | R3 | G3 | B3 */
    rotr              t4, t4, 24           /* t4 = R5 | R4 | G4 | B4 */
    or                t7, t7, t8           /* t7 = FF | R1 | G1 | B1 */
    or                t0, t0, t8           /* t0 = FF | R2 | G2 | B2 */
    or                t3, t3, t8           /* t1 = FF | R3 | G3 | B3 */
    or                t4, t4, t8           /* t3 = FF | R4 | G4 | B4 */

    sw                t7, 0(a0)
    sw                t0, 4(a0)
    sw                t3, 8(a0)
    sw                t4, 12(a0)
    rotr              t7, t2, 16           /* t7 = xx | R5 | G5 | B5 */
    b                 11b
     addiu            a0, a0, 16

2:
    lhu               t7, 0(a1)            /* t7 =  0 |  0 | G1 | R1 */
    wsbh              t7, t7               /* t7 =  0 |  0 | R1 | G1 */
21:
    beqz              t9, 4f
     addiu            t9, t9, -1
    lw                t0, 2(a1)            /* t0 = B2 | G2 | R2 | B1 */
    lw                t1, 6(a1)            /* t1 = R4 | B3 | G3 | R3 */
    lw                t2, 10(a1)           /* t2 = G5 | R5 | B4 | G4 */

    addiu             a1, a1, 12
    addiu             a2, a2, -4

    wsbh              t0, t0               /* t0 = G2 | B2 | B1 | R2 */
    wsbh              t1, t1               /* t1 = B3 | R4 | R3 | G3 */
    wsbh              t2, t2               /* t2 = R5 | G5 | G4 | B4 */

    precr_sra.ph.w    t7, t0, 0            /* t7 = R1 | G1 | B1 | R2 */
    rotr              t0, t0, 16           /* t0 = B1 | R2 | G2 | B2 */
    packrl.ph         t3, t2, t1           /* t3 = G4 | B4 | B3 | R4 */
    rotr              t1, t1, 24           /* t1 = R4 | R3 | G3 | B3 */
    srl               t7, t7, 8            /* t7 =  0 | R1 | G1 | B1 */
    rotr              t3, t3, 16           /* t3 = B3 | R4 | G4 | B4 */
    or                t7, t7, t8           /* t7 = FF | R1 | G1 | B1 */
    or                t0, t0, t8           /* t0 = FF | R2 | G2 | B2 */
    or                t1, t1, t8           /* t1 = FF | R3 | G3 | B3 */
    or                t3, t3, t8           /* t3 = FF | R4 | G4 | B4 */

    sw                t7, 0(a0)
    sw                t0, 4(a0)
    sw                t1, 8(a0)
    sw                t3, 12(a0)
    srl               t7, t2, 16           /* t7 =  0 |  0 | R5 | G5 */
    b                 21b
     addiu            a0, a0, 16

3:
    lbu               t7, 0(a1)            /* t7 =  0 |  0 |  0 | R1 */
31:
    beqz              t9, 4f
     addiu            t9, t9, -1
    lw                t0, 1(a1)            /* t0 = G2 | R2 | B1 | G1 */
    lw                t1, 5(a1)            /* t1 = B3 | G3 | R3 | B2 */
    lw                t2, 9(a1)            /* t2 = R5 | B4 | G4 | R4 */

    addiu             a1, a1, 12
    addiu             a2, a2, -4

    wsbh              t0, t0               /* t0 = R2 | G2 | G1 | B1 */
    wsbh              t1, t1               /* t1 = G3 | B3 | B2 | R3 */
    wsbh              t2, t2               /* t2 = B4 | R5 | R4 | G4 */

    precr_sra.ph.w    t7, t0, 0            /* t7 = xx | R1 | G1 | B1 */
    packrl.ph         t3, t1, t0           /* t3 = B2 | R3 | R2 | G2 */
    rotr              t1, t1, 16           /* t1 = B2 | R3 | G3 | B3 */
    rotr              t4, t2, 24           /* t4 = R5 | R4 | G4 | B4 */
    rotr              t3, t3, 24           /* t3 = R3 | R2 | G2 | B2 */
    or                t7, t7, t8           /* t7 = FF | R1 | G1 | B1 */
    or                t3, t3, t8           /* t3 = FF | R2 | G2 | B2 */
    or                t1, t1, t8           /* t1 = FF | R3 | G3 | B3 */
    or                t4, t4, t8           /* t4 = FF | R4 | G4 | B4 */

    sw                t7, 0(a0)
    sw                t3, 4(a0)
    sw                t1, 8(a0)
    sw                t4, 12(a0)
    srl               t7, t2, 16           /* t7 =  0 |  0 | xx | R5 */
    b                 31b
     addiu            a0, a0, 16

4:
    beqz              a2, 6f
     nop
5:
    lbu               t0, 0(a1)            /* t0 =  0 | 0 | 0 | R */
    lbu               t1, 1(a1)            /* t1 =  0 | 0 | 0 | G */
    lbu               t2, 2(a1)            /* t2 =  0 | 0 | 0 | B */
    addiu             a1, a1, 3

    sll               t0, t0, 16           /* t2 =  0 | R | 0 | 0 */
    sll               t1, t1, 8            /* t1 =  0 | 0 | G | 0 */

    or                t2, t2, t1           /* t2 =  0 | 0 | G | B */
    or                t2, t2, t0           /* t2 =  0 | R | G | B */
    or                t2, t2, t8           /* t2 = FF | R | G | B */

    sw                t2, 0(a0)
    addiu             a2, a2, -1
    bnez              a2, 5b
     addiu            a0, a0, 4
6:
    j                 ra
     nop

END(pixman_composite_src_0888_8888_rev_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_src_0888_0565_rev_asm_mips)
/*
 * a0 - dst (r5g6b5)
 * a1 - src (b8g8r8)
 * a2 - w
 */

    SAVE_REGS_ON_STACK 0, v0, v1
    beqz              a2, 6f
     nop

    li                t6, 0xf800f800
    li                t7, 0x07e007e0
    li                t8, 0x001F001F
    srl               t9, a2, 2   /* t9 = how many multiples of 4 src pixels */
    beqz              t9, 4f      /* branch if less than 4 src pixels */
     nop

    li                t0, 0x1
    li                t1, 0x2
    li                t2, 0x3
    andi              t3, a1, 0x3
    beq               t3, t0, 1f
     nop
    beq               t3, t1, 2f
     nop
    beq               t3, t2, 3f
     nop

0:
    beqz              t9, 4f
     addiu            t9, t9, -1
    lw                t0, 0(a1)            /* t0 = R2 | B1 | G1 | R1 */
    lw                t1, 4(a1)            /* t1 = G3 | R3 | B2 | G2 */
    lw                t2, 8(a1)            /* t2 = B4 | G4 | R4 | B3 */

    addiu             a1, a1, 12
    addiu             a2, a2, -4

    wsbh              t0, t0               /* t0 = B1 | R2 | R1 | G1 */
    wsbh              t1, t1               /* t1 = R3 | G3 | G2 | B2 */
    wsbh              t2, t2               /* t2 = G4 | B4 | B3 | R4 */

    packrl.ph         t3, t1, t0           /* t3 = G2 | B2 | B1 | R2 */
    packrl.ph         t4, t0, t0           /* t4 = R1 | G1 | B1 | R2 */
    rotr              t3, t3, 16           /* t3 = B1 | R2 | G2 | B2 */
    srl               t4, t4, 8            /* t4 =  0 | R1 | G1 | B1 */
    packrl.ph         t5, t2, t1           /* t5 = B3 | R4 | R3 | G3 */
    rotr              t5, t5, 24           /* t5 = R4 | R3 | G3 | B3 */
    rotr              t2, t2, 16           /* t2 = B3 | R4 | G4 | B4 */

    CONVERT_2x8888_TO_2x0565 t4, t3, t4, t3, t6, t7, t8, v0, v1
    CONVERT_2x8888_TO_2x0565 t5, t2, t5, t2, t6, t7, t8, v0, v1

    sh                t4, 0(a0)
    sh                t3, 2(a0)
    sh                t5, 4(a0)
    sh                t2, 6(a0)
    b                 0b
     addiu            a0, a0, 8

1:
    lbu               t4, 0(a1)            /* t4 =  0 |  0 |  0 | R1 */
    lhu               t5, 1(a1)            /* t5 =  0 |  0 | B1 | G1 */
    sll               t4, t4, 16           /* t4 =  0 | R1 |  0 | 0  */
    wsbh              t5, t5               /* t5 =  0 |  0 | G1 | B1 */
    or                t5, t4, t5           /* t5 =  0 | R1 | G1 | B1 */
11:
    beqz              t9, 4f
     addiu            t9, t9, -1
    lw                t0, 3(a1)            /* t0 = R3 | B2 | G2 | R2 */
    lw                t1, 7(a1)            /* t1 = G4 | R4 | B3 | G3 */
    lw                t2, 11(a1)           /* t2 = B5 | G5 | R5 | B4 */

    addiu             a1, a1, 12
    addiu             a2, a2, -4

    wsbh              t0, t0               /* t0 = B2 | R3 | R2 | G2 */
    wsbh              t1, t1               /* t1 = R4 | G4 | G3 | B3 */
    wsbh              t2, t2               /* t2 = G5 | B5 | B4 | R5 */

    packrl.ph         t3, t1, t0           /* t3 = G3 | B3 | B2 | R3 */
    packrl.ph         t4, t2, t1           /* t4 = B4 | R5 | R4 | G4 */
    rotr              t0, t0, 24           /* t0 = R3 | R2 | G2 | B2 */
    rotr              t3, t3, 16           /* t3 = B2 | R3 | G3 | B3 */
    rotr              t4, t4, 24           /* t4 = R5 | R4 | G4 | B4 */

    CONVERT_2x8888_TO_2x0565 t5, t0, t5, t0, t6, t7, t8, v0, v1
    CONVERT_2x8888_TO_2x0565 t3, t4, t3, t4, t6, t7, t8, v0, v1

    sh                t5, 0(a0)
    sh                t0, 2(a0)
    sh                t3, 4(a0)
    sh                t4, 6(a0)
    rotr              t5, t2, 16           /* t5 = xx | R5 | G5 | B5 */
    b                 11b
     addiu            a0, a0, 8

2:
    lhu               t5, 0(a1)            /* t5 =  0 |  0 | G1 | R1 */
    wsbh              t5, t5               /* t5 =  0 |  0 | R1 | G1 */
21:
    beqz              t9, 4f
     addiu            t9, t9, -1
    lw                t0, 2(a1)            /* t0 = B2 | G2 | R2 | B1 */
    lw                t1, 6(a1)            /* t1 = R4 | B3 | G3 | R3 */
    lw                t2, 10(a1)           /* t2 = G5 | R5 | B4 | G4 */

    addiu             a1, a1, 12
    addiu             a2, a2, -4

    wsbh              t0, t0               /* t0 = G2 | B2 | B1 | R2 */
    wsbh              t1, t1               /* t1 = B3 | R4 | R3 | G3 */
    wsbh              t2, t2               /* t2 = R5 | G5 | G4 | B4 */

    precr_sra.ph.w    t5, t0, 0            /* t5 = R1 | G1 | B1 | R2 */
    rotr              t0, t0, 16           /* t0 = B1 | R2 | G2 | B2 */
    packrl.ph         t3, t2, t1           /* t3 = G4 | B4 | B3 | R4 */
    rotr              t1, t1, 24           /* t1 = R4 | R3 | G3 | B3 */
    srl               t5, t5, 8            /* t5 =  0 | R1 | G1 | B1 */
    rotr              t3, t3, 16           /* t3 = B3 | R4 | G4 | B4 */

    CONVERT_2x8888_TO_2x0565 t5, t0, t5, t0, t6, t7, t8, v0, v1
    CONVERT_2x8888_TO_2x0565 t1, t3, t1, t3, t6, t7, t8, v0, v1

    sh                t5, 0(a0)
    sh                t0, 2(a0)
    sh                t1, 4(a0)
    sh                t3, 6(a0)
    srl               t5, t2, 16           /* t5 =  0 |  0 | R5 | G5 */
    b                 21b
     addiu            a0, a0, 8

3:
    lbu               t5, 0(a1)            /* t5 =  0 |  0 |  0 | R1 */
31:
    beqz              t9, 4f
     addiu            t9, t9, -1
    lw                t0, 1(a1)            /* t0 = G2 | R2 | B1 | G1 */
    lw                t1, 5(a1)            /* t1 = B3 | G3 | R3 | B2 */
    lw                t2, 9(a1)            /* t2 = R5 | B4 | G4 | R4 */

    addiu             a1, a1, 12
    addiu             a2, a2, -4

    wsbh              t0, t0               /* t0 = R2 | G2 | G1 | B1 */
    wsbh              t1, t1               /* t1 = G3 | B3 | B2 | R3 */
    wsbh              t2, t2               /* t2 = B4 | R5 | R4 | G4 */

    precr_sra.ph.w    t5, t0, 0            /* t5 = xx | R1 | G1 | B1 */
    packrl.ph         t3, t1, t0           /* t3 = B2 | R3 | R2 | G2 */
    rotr              t1, t1, 16           /* t1 = B2 | R3 | G3 | B3 */
    rotr              t4, t2, 24           /* t4 = R5 | R4 | G4 | B4 */
    rotr              t3, t3, 24           /* t3 = R3 | R2 | G2 | B2 */

    CONVERT_2x8888_TO_2x0565 t5, t3, t5, t3, t6, t7, t8, v0, v1
    CONVERT_2x8888_TO_2x0565 t1, t4, t1, t4, t6, t7, t8, v0, v1

    sh                t5, 0(a0)
    sh                t3, 2(a0)
    sh                t1, 4(a0)
    sh                t4, 6(a0)
    srl               t5, t2, 16           /* t5 =  0 |  0 | xx | R5 */
    b                 31b
     addiu            a0, a0, 8

4:
    beqz              a2, 6f
     nop
5:
    lbu               t0, 0(a1)            /* t0 =  0 | 0 | 0 | R */
    lbu               t1, 1(a1)            /* t1 =  0 | 0 | 0 | G */
    lbu               t2, 2(a1)            /* t2 =  0 | 0 | 0 | B */
    addiu             a1, a1, 3

    sll               t0, t0, 16           /* t2 =  0 | R | 0 | 0 */
    sll               t1, t1, 8            /* t1 =  0 | 0 | G | 0 */

    or                t2, t2, t1           /* t2 =  0 | 0 | G | B */
    or                t2, t2, t0           /* t2 =  0 | R | G | B */

    CONVERT_1x8888_TO_1x0565 t2, t3, t4, t5

    sh                t3, 0(a0)
    addiu             a2, a2, -1
    bnez              a2, 5b
     addiu            a0, a0, 2
6:
    RESTORE_REGS_FROM_STACK 0, v0, v1
    j                 ra
     nop

END(pixman_composite_src_0888_0565_rev_asm_mips)
#endif

LEAF_MIPS_DSPR2(pixman_composite_src_pixbuf_8888_asm_mips)
/*
 * a0 - dst  (a8b8g8r8)
 * a1 - src  (a8r8g8b8)
 * a2 - w
 */

    SAVE_REGS_ON_STACK 0, v0
    li       v0, 0x00ff00ff

    beqz     a2, 3f
     nop
    addiu    t1, a2, -1
    beqz     t1, 2f
     nop
1:
    lw       t0, 0(a1)
    lw       t1, 4(a1)
    addiu    a1, a1, 8
    addiu    a2, a2, -2
    srl      t2, t0, 24
    srl      t3, t1, 24

    MIPS_2xUN8x4_MUL_2xUN8 t0, t1, t2, t3, t0, t1, v0, t4, t5, t6, t7, t8, t9

    sll      t0, t0, 8
    sll      t1, t1, 8
    andi     t2, t2, 0xff
    andi     t3, t3, 0xff
    or       t0, t0, t2
    or       t1, t1, t3
    wsbh     t0, t0
    wsbh     t1, t1
    rotr     t0, t0, 16
    rotr     t1, t1, 16
    sw       t0, 0(a0)
    sw       t1, 4(a0)

    addiu    t2, a2, -1
    bgtz     t2, 1b
     addiu   a0, a0, 8
2:
    beqz     a2, 3f
     nop
    lw       t0, 0(a1)
    srl      t1, t0, 24

    MIPS_UN8x4_MUL_UN8 t0, t1, t0, v0, t3, t4, t5

    sll      t0, t0, 8
    andi     t1, t1, 0xff
    or       t0, t0, t1
    wsbh     t0, t0
    rotr     t0, t0, 16
    sw       t0, 0(a0)
3:
    RESTORE_REGS_FROM_STACK 0, v0
    j        ra
     nop

END(pixman_composite_src_pixbuf_8888_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_src_rpixbuf_8888_asm_mips)
/*
 * a0 - dst  (a8r8g8b8)
 * a1 - src  (a8r8g8b8)
 * a2 - w
 */

    SAVE_REGS_ON_STACK 0, v0
    li       v0, 0x00ff00ff

    beqz     a2, 3f
     nop
    addiu    t1, a2, -1
    beqz     t1, 2f
     nop
1:
    lw       t0, 0(a1)
    lw       t1, 4(a1)
    addiu    a1, a1, 8
    addiu    a2, a2, -2
    srl      t2, t0, 24
    srl      t3, t1, 24

    MIPS_2xUN8x4_MUL_2xUN8 t0, t1, t2, t3, t0, t1, v0, t4, t5, t6, t7, t8, t9

    sll      t0, t0, 8
    sll      t1, t1, 8
    andi     t2, t2, 0xff
    andi     t3, t3, 0xff
    or       t0, t0, t2
    or       t1, t1, t3
    rotr     t0, t0, 8
    rotr     t1, t1, 8
    sw       t0, 0(a0)
    sw       t1, 4(a0)

    addiu    t2, a2, -1
    bgtz     t2, 1b
     addiu   a0, a0, 8
2:
    beqz     a2, 3f
     nop
    lw       t0, 0(a1)
    srl      t1, t0, 24

    MIPS_UN8x4_MUL_UN8 t0, t1, t0, v0, t3, t4, t5

    sll      t0, t0, 8
    andi     t1, t1, 0xff
    or       t0, t0, t1
    rotr     t0, t0, 8
    sw       t0, 0(a0)
3:
    RESTORE_REGS_FROM_STACK 0, v0
    j        ra
     nop

END(pixman_composite_src_rpixbuf_8888_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_src_n_8_8888_asm_mips)
/*
 * a0 - dst  (a8r8g8b8)
 * a1 - src  (32bit constant)
 * a2 - mask (a8)
 * a3 - w
 */


    SAVE_REGS_ON_STACK 0, v0
    li       v0, 0x00ff00ff

    beqz     a3, 3f
     nop
    addiu    t1, a3, -1
    beqz     t1, 2f
     nop

1:
                       /* a1 = source      (32bit constant) */
    lbu      t0, 0(a2) /* t2 = mask        (a8) */
    lbu      t1, 1(a2) /* t3 = mask        (a8) */
    addiu    a2, a2, 2

    MIPS_2xUN8x4_MUL_2xUN8 a1, a1, t0, t1, t2, t3, v0, t4, t5, t6, t7, t8, t9

    sw       t2, 0(a0)
    sw       t3, 4(a0)
    addiu    a3, a3, -2
    addiu    t2, a3, -1
    bgtz     t2, 1b
     addiu   a0, a0, 8

    beqz     a3, 3f
     nop

2:
    lbu      t0, 0(a2)
    addiu    a2, a2, 1

    MIPS_UN8x4_MUL_UN8 a1, t0, t1, v0, t3, t4, t5

    sw       t1, 0(a0)
    addiu    a3, a3, -1
    addiu    a0, a0, 4

3:
    RESTORE_REGS_FROM_STACK 0, v0
    j        ra
     nop

END(pixman_composite_src_n_8_8888_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_src_n_8_8_asm_mips)
/*
 * a0 - dst  (a8)
 * a1 - src  (32bit constant)
 * a2 - mask (a8)
 * a3 - w
 */

    li                t9, 0x00ff00ff
    beqz              a3, 3f
     nop
    srl               t7, a3, 2   /* t7 = how many multiples of 4 dst pixels */
    beqz              t7, 1f      /* branch if less than 4 src pixels */
     nop

    srl               t8, a1, 24
    replv.ph          t8, t8

0:
    beqz              t7, 1f
     addiu            t7, t7, -1
    lbu               t0, 0(a2)
    lbu               t1, 1(a2)
    lbu               t2, 2(a2)
    lbu               t3, 3(a2)

    addiu             a2, a2, 4

    precr_sra.ph.w    t1, t0, 0
    precr_sra.ph.w    t3, t2, 0
    precr.qb.ph       t0, t3, t1

    muleu_s.ph.qbl    t2, t0, t8
    muleu_s.ph.qbr    t3, t0, t8
    shra_r.ph         t4, t2, 8
    shra_r.ph         t5, t3, 8
    and               t4, t4, t9
    and               t5, t5, t9
    addq.ph           t2, t2, t4
    addq.ph           t3, t3, t5
    shra_r.ph         t2, t2, 8
    shra_r.ph         t3, t3, 8
    precr.qb.ph       t2, t2, t3

    sb                t2, 0(a0)
    srl               t2, t2, 8
    sb                t2, 1(a0)
    srl               t2, t2, 8
    sb                t2, 2(a0)
    srl               t2, t2, 8
    sb                t2, 3(a0)
    addiu             a3, a3, -4
    b                 0b
     addiu            a0, a0, 4

1:
    beqz              a3, 3f
     nop
    srl               t8, a1, 24
2:
    lbu               t0, 0(a2)
    addiu             a2, a2, 1

    mul               t2, t0, t8
    shra_r.ph         t3, t2, 8
    andi              t3, t3, 0x00ff
    addq.ph           t2, t2, t3
    shra_r.ph         t2, t2, 8

    sb                t2, 0(a0)
    addiu             a3, a3, -1
    bnez              a3, 2b
     addiu            a0, a0, 1

3:
    j                 ra
     nop

END(pixman_composite_src_n_8_8_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_over_n_8888_8888_ca_asm_mips)
/*
 * a0 - dst  (a8r8g8b8)
 * a1 - src  (32bit constant)
 * a2 - mask (a8r8g8b8)
 * a3 - w
 */

    beqz         a3, 8f
     nop
    SAVE_REGS_ON_STACK 8, s0, s1, s2, s3, s4, s5

    li           t6, 0xff
    addiu        t7, zero, -1 /* t7 = 0xffffffff */
    srl          t8, a1, 24   /* t8 = srca */
    li           t9, 0x00ff00ff

    addiu        t1, a3, -1
    beqz         t1, 4f       /* last pixel */
     nop

0:
    lw           t0, 0(a2)    /* t0 = mask */
    lw           t1, 4(a2)    /* t1 = mask */
    addiu        a3, a3, -2   /* w = w - 2 */
    or           t2, t0, t1
    beqz         t2, 3f      /* if (t0 == 0) && (t1 == 0) */
     addiu       a2, a2, 8
    and          t2, t0, t1
    beq          t2, t7, 1f  /* if (t0 == 0xffffffff) && (t1 == 0xffffffff) */
     nop

//if(ma)
    lw           t2, 0(a0)    /* t2 = dst */
    lw           t3, 4(a0)    /* t3 = dst */
    MIPS_2xUN8x4_MUL_2xUN8x4 a1, a1, t0, t1, t4, t5, t9, s0, s1, s2, s3, s4, s5
    MIPS_2xUN8x4_MUL_2xUN8   t0, t1, t8, t8, t0, t1, t9, s0, s1, s2, s3, s4, s5
    not          t0, t0
    not          t1, t1
    MIPS_2xUN8x4_MUL_2xUN8x4 t2, t3, t0, t1, t2, t3, t9, s0, s1, s2, s3, s4, s5
    addu_s.qb    t2, t4, t2
    addu_s.qb    t3, t5, t3
    sw           t2, 0(a0)
    sw           t3, 4(a0)
    addiu        t1, a3, -1
    bgtz         t1, 0b
     addiu       a0, a0, 8
    b            4f
     nop
1:
//if (t0 == 0xffffffff) && (t1 == 0xffffffff):
    beq          t8, t6, 2f   /* if (srca == 0xff) */
     nop
    lw           t2, 0(a0)    /* t2 = dst */
    lw           t3, 4(a0)    /* t3 = dst */
    not          t0, a1
    not          t1, a1
    srl          t0, t0, 24
    srl          t1, t1, 24
    MIPS_2xUN8x4_MUL_2xUN8 t2, t3, t0, t1, t2, t3, t9, s0, s1, s2, s3, s4, s5
    addu_s.qb    t2, a1, t2
    addu_s.qb    t3, a1, t3
    sw           t2, 0(a0)
    sw           t3, 4(a0)
    addiu        t1, a3, -1
    bgtz         t1, 0b
     addiu       a0, a0, 8
    b            4f
     nop
2:
    sw           a1, 0(a0)
    sw           a1, 4(a0)
3:
    addiu        t1, a3, -1
    bgtz         t1, 0b
     addiu       a0, a0, 8

4:
    beqz         a3, 7f
     nop
                              /* a1 = src */
    lw           t0, 0(a2)    /* t0 = mask */
    beqz         t0, 7f       /* if (t0 == 0) */
     nop
    beq          t0, t7, 5f  /* if (t0 == 0xffffffff) */
     nop
//if(ma)
    lw           t1, 0(a0)    /* t1 = dst */
    MIPS_UN8x4_MUL_UN8x4  a1, t0, t2, t9, t3, t4, t5, s0
    MIPS_UN8x4_MUL_UN8    t0, t8, t0, t9, t3, t4, t5
    not          t0, t0
    MIPS_UN8x4_MUL_UN8x4  t1, t0, t1, t9, t3, t4, t5, s0
    addu_s.qb    t1, t2, t1
    sw           t1, 0(a0)
    RESTORE_REGS_FROM_STACK 8, s0, s1, s2, s3, s4, s5
    j            ra
     nop
5:
//if (t0 == 0xffffffff)
    beq          t8, t6, 6f   /* if (srca == 0xff) */
     nop
    lw           t1, 0(a0)    /* t1 = dst */
    not          t0, a1
    srl          t0, t0, 24
    MIPS_UN8x4_MUL_UN8 t1, t0, t1, t9, t2, t3, t4
    addu_s.qb    t1, a1, t1
    sw           t1, 0(a0)
    RESTORE_REGS_FROM_STACK 8, s0, s1, s2, s3, s4, s5
    j            ra
     nop
6:
    sw           a1, 0(a0)
7:
    RESTORE_REGS_FROM_STACK 8, s0, s1, s2, s3, s4, s5
8:
    j            ra
     nop

END(pixman_composite_over_n_8888_8888_ca_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_over_n_8888_0565_ca_asm_mips)
/*
 * a0 - dst  (r5g6b5)
 * a1 - src  (32bit constant)
 * a2 - mask (a8r8g8b8)
 * a3 - w
 */

    beqz         a3, 8f
     nop
    SAVE_REGS_ON_STACK 20, s0, s1, s2, s3, s4, s5, s6, s7, s8

    li           t6, 0xff
    addiu        t7, zero, -1 /* t7 = 0xffffffff */
    srl          t8, a1, 24   /* t8 = srca */
    li           t9, 0x00ff00ff
    li           s6, 0xf800f800
    li           s7, 0x07e007e0
    li           s8, 0x001F001F

    addiu        t1, a3, -1
    beqz         t1, 4f       /* last pixel */
     nop

0:
    lw           t0, 0(a2)    /* t0 = mask */
    lw           t1, 4(a2)    /* t1 = mask */
    addiu        a3, a3, -2   /* w = w - 2 */
    or           t2, t0, t1
    beqz         t2, 3f      /* if (t0 == 0) && (t1 == 0) */
     addiu       a2, a2, 8
    and          t2, t0, t1
    beq          t2, t7, 1f  /* if (t0 == 0xffffffff) && (t1 == 0xffffffff) */
     nop

//if(ma)
    lhu          t2, 0(a0)    /* t2 = dst */
    lhu          t3, 2(a0)    /* t3 = dst */
    MIPS_2xUN8x4_MUL_2xUN8x4 a1, a1, t0, t1, t4, t5, t9, s0, s1, s2, s3, s4, s5
    MIPS_2xUN8x4_MUL_2xUN8   t0, t1, t8, t8, t0, t1, t9, s0, s1, s2, s3, s4, s5
    not          t0, t0
    not          t1, t1
    CONVERT_2x0565_TO_2x8888 t2, t3, t2, t3, s7, s8, s0, s1, s2, s3
    MIPS_2xUN8x4_MUL_2xUN8x4 t2, t3, t0, t1, t2, t3, t9, s0, s1, s2, s3, s4, s5
    addu_s.qb    t2, t4, t2
    addu_s.qb    t3, t5, t3
    CONVERT_2x8888_TO_2x0565 t2, t3, t2, t3, s6, s7, s8, s0, s1
    sh           t2, 0(a0)
    sh           t3, 2(a0)
    addiu        t1, a3, -1
    bgtz         t1, 0b
     addiu       a0, a0, 4
    b            4f
     nop
1:
//if (t0 == 0xffffffff) && (t1 == 0xffffffff):
    beq          t8, t6, 2f   /* if (srca == 0xff) */
     nop
    lhu          t2, 0(a0)    /* t2 = dst */
    lhu          t3, 2(a0)    /* t3 = dst */
    not          t0, a1
    not          t1, a1
    srl          t0, t0, 24
    srl          t1, t1, 24
    CONVERT_2x0565_TO_2x8888 t2, t3, t2, t3, s7, s8, s0, s1, s2, s3
    MIPS_2xUN8x4_MUL_2xUN8   t2, t3, t0, t1, t2, t3, t9, s0, s1, s2, s3, s4, s5
    addu_s.qb    t2, a1, t2
    addu_s.qb    t3, a1, t3
    CONVERT_2x8888_TO_2x0565 t2, t3, t2, t3, s6, s7, s8, s0, s1
    sh           t2, 0(a0)
    sh           t3, 2(a0)
    addiu        t1, a3, -1
    bgtz         t1, 0b
     addiu       a0, a0, 4
    b            4f
     nop
2:
    CONVERT_1x8888_TO_1x0565 a1, t2, s0, s1
    sh           t2, 0(a0)
    sh           t2, 2(a0)
3:
    addiu        t1, a3, -1
    bgtz         t1, 0b
     addiu       a0, a0, 4

4:
    beqz         a3, 7f
     nop
                              /* a1 = src */
    lw           t0, 0(a2)    /* t0 = mask */
    beqz         t0, 7f       /* if (t0 == 0) */
     nop
    beq          t0, t7, 5f  /* if (t0 == 0xffffffff) */
     nop
//if(ma)
    lhu          t1, 0(a0)    /* t1 = dst */
    MIPS_UN8x4_MUL_UN8x4     a1, t0, t2, t9, t3, t4, t5, s0
    MIPS_UN8x4_MUL_UN8       t0, t8, t0, t9, t3, t4, t5
    not          t0, t0
    CONVERT_1x0565_TO_1x8888 t1, s1, s2, s3
    MIPS_UN8x4_MUL_UN8x4     s1, t0, s1, t9, t3, t4, t5, s0
    addu_s.qb    s1, t2, s1
    CONVERT_1x8888_TO_1x0565 s1, t1, s0, s2
    sh           t1, 0(a0)
    RESTORE_REGS_FROM_STACK 20, s0, s1, s2, s3, s4, s5, s6, s7, s8
    j            ra
     nop
5:
//if (t0 == 0xffffffff)
    beq          t8, t6, 6f   /* if (srca == 0xff) */
     nop
    lhu          t1, 0(a0)    /* t1 = dst */
    not          t0, a1
    srl          t0, t0, 24
    CONVERT_1x0565_TO_1x8888 t1, s1, s2, s3
    MIPS_UN8x4_MUL_UN8       s1, t0, s1, t9, t2, t3, t4
    addu_s.qb    s1, a1, s1
    CONVERT_1x8888_TO_1x0565 s1, t1, s0, s2
    sh           t1, 0(a0)
    RESTORE_REGS_FROM_STACK 20, s0, s1, s2, s3, s4, s5, s6, s7, s8
    j            ra
     nop
6:
    CONVERT_1x8888_TO_1x0565 a1, t1, s0, s2
    sh           t1, 0(a0)
7:
    RESTORE_REGS_FROM_STACK 20, s0, s1, s2, s3, s4, s5, s6, s7, s8
8:
    j            ra
     nop

END(pixman_composite_over_n_8888_0565_ca_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_over_n_8_8_asm_mips)
/*
 * a0 - dst  (a8)
 * a1 - src  (32bit constant)
 * a2 - mask (a8)
 * a3 - w
 */

    SAVE_REGS_ON_STACK 0, v0
    li                t9, 0x00ff00ff
    beqz              a3, 3f
     nop
    srl               v0, a3, 2   /* v0 = how many multiples of 4 dst pixels */
    beqz              v0, 1f      /* branch if less than 4 src pixels */
     nop

    srl               t8, a1, 24
    replv.ph          t8, t8

0:
    beqz              v0, 1f
     addiu            v0, v0, -1
    lbu               t0, 0(a2)
    lbu               t1, 1(a2)
    lbu               t2, 2(a2)
    lbu               t3, 3(a2)
    lbu               t4, 0(a0)
    lbu               t5, 1(a0)
    lbu               t6, 2(a0)
    lbu               t7, 3(a0)

    addiu             a2, a2, 4

    precr_sra.ph.w    t1, t0, 0
    precr_sra.ph.w    t3, t2, 0
    precr_sra.ph.w    t5, t4, 0
    precr_sra.ph.w    t7, t6, 0

    precr.qb.ph       t0, t3, t1
    precr.qb.ph       t1, t7, t5

    muleu_s.ph.qbl    t2, t0, t8
    muleu_s.ph.qbr    t3, t0, t8
    shra_r.ph         t4, t2, 8
    shra_r.ph         t5, t3, 8
    and               t4, t4, t9
    and               t5, t5, t9
    addq.ph           t2, t2, t4
    addq.ph           t3, t3, t5
    shra_r.ph         t2, t2, 8
    shra_r.ph         t3, t3, 8
    precr.qb.ph       t0, t2, t3
    not               t6, t0

    preceu.ph.qbl     t7, t6
    preceu.ph.qbr     t6, t6

    muleu_s.ph.qbl    t2, t1, t7
    muleu_s.ph.qbr    t3, t1, t6
    shra_r.ph         t4, t2, 8
    shra_r.ph         t5, t3, 8
    and               t4, t4, t9
    and               t5, t5, t9
    addq.ph           t2, t2, t4
    addq.ph           t3, t3, t5
    shra_r.ph         t2, t2, 8
    shra_r.ph         t3, t3, 8
    precr.qb.ph       t1, t2, t3

    addu_s.qb         t2, t0, t1

    sb                t2, 0(a0)
    srl               t2, t2, 8
    sb                t2, 1(a0)
    srl               t2, t2, 8
    sb                t2, 2(a0)
    srl               t2, t2, 8
    sb                t2, 3(a0)
    addiu             a3, a3, -4
    b                 0b
     addiu            a0, a0, 4

1:
    beqz              a3, 3f
     nop
    srl               t8, a1, 24
2:
    lbu               t0, 0(a2)
    lbu               t1, 0(a0)
    addiu             a2, a2, 1

    mul               t2, t0, t8
    shra_r.ph         t3, t2, 8
    andi              t3, t3, 0x00ff
    addq.ph           t2, t2, t3
    shra_r.ph         t2, t2, 8
    not               t3, t2
    andi              t3, t3, 0x00ff


    mul               t4, t1, t3
    shra_r.ph         t5, t4, 8
    andi              t5, t5, 0x00ff
    addq.ph           t4, t4, t5
    shra_r.ph         t4, t4, 8
    andi              t4, t4, 0x00ff

    addu_s.qb         t2, t2, t4
    sb                t2, 0(a0)
    addiu             a3, a3, -1
    bnez              a3, 2b
     addiu            a0, a0, 1

3:
    RESTORE_REGS_FROM_STACK 0, v0
    j                 ra
     nop

END(pixman_composite_over_n_8_8_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_over_n_8_8888_asm_mips)
/*
 * a0 - dst  (a8r8g8b8)
 * a1 - src  (32bit constant)
 * a2 - mask (a8)
 * a3 - w
 */

    SAVE_REGS_ON_STACK 4, s0, s1, s2, s3, s4
    beqz      a3, 4f
     nop
    li        t4, 0x00ff00ff
    li        t5, 0xff
    addiu     t0, a3, -1
    beqz      t0, 3f         /* last pixel */
     srl      t6, a1, 24     /* t6 = srca */
    not       s4, a1
    beq       t5, t6, 2f     /* if (srca == 0xff) */
     srl      s4, s4, 24
1:
                             /* a1 = src */
    lbu       t0, 0(a2)      /* t0 = mask */
    lbu       t1, 1(a2)      /* t1 = mask */
    or        t2, t0, t1
    beqz      t2, 111f       /* if (t0 == 0) && (t1 == 0) */
     addiu    a2, a2, 2
    and       t3, t0, t1

    lw        t2, 0(a0)      /* t2 = dst */
    beq       t3, t5, 11f    /* if (t0 == 0xff) && (t1 == 0xff) */
     lw       t3, 4(a0)      /* t3 = dst */

    MIPS_2xUN8x4_MUL_2xUN8 a1, a1, t0, t1, s0, s1, t4, t6, t7, t8, t9, s2, s3
    not       s2, s0
    not       s3, s1
    srl       s2, s2, 24
    srl       s3, s3, 24
    MIPS_2xUN8x4_MUL_2xUN8 t2, t3, s2, s3, t2, t3, t4, t0, t1, t6, t7, t8, t9
    addu_s.qb s2, t2, s0
    addu_s.qb s3, t3, s1
    sw        s2, 0(a0)
    b         111f
     sw       s3, 4(a0)
11:
    MIPS_2xUN8x4_MUL_2xUN8 t2, t3, s4, s4, t2, t3, t4, t0, t1, t6, t7, t8, t9
    addu_s.qb s2, t2, a1
    addu_s.qb s3, t3, a1
    sw        s2, 0(a0)
    sw        s3, 4(a0)

111:
    addiu     a3, a3, -2
    addiu     t0, a3, -1
    bgtz      t0, 1b
     addiu    a0, a0, 8
    b         3f
     nop
2:
                             /* a1 = src */
    lbu       t0, 0(a2)      /* t0 = mask */
    lbu       t1, 1(a2)      /* t1 = mask */
    or        t2, t0, t1
    beqz      t2, 222f       /* if (t0 == 0) && (t1 == 0) */
     addiu    a2, a2, 2
    and       t3, t0, t1
    beq       t3, t5, 22f    /* if (t0 == 0xff) && (t1 == 0xff) */
     nop
    lw        t2, 0(a0)      /* t2 = dst */
    lw        t3, 4(a0)      /* t3 = dst */

    OVER_2x8888_2x8_2x8888 a1, a1, t0, t1, t2, t3, \
                           t6, t7, t4, t8, t9, s0, s1, s2, s3
    sw        t6, 0(a0)
    b         222f
     sw        t7, 4(a0)
22:
    sw        a1, 0(a0)
    sw        a1, 4(a0)
222:
    addiu     a3, a3, -2
    addiu     t0, a3, -1
    bgtz      t0, 2b
     addiu    a0, a0, 8
3:
    blez      a3, 4f
     nop
                             /* a1 = src */
    lbu       t0, 0(a2)      /* t0 = mask */
    beqz      t0, 4f         /* if (t0 == 0) */
     addiu    a2, a2, 1
    move      t3, a1
    beq       t0, t5, 31f    /* if (t0 == 0xff) */
     lw       t1, 0(a0)      /* t1 = dst */

    MIPS_UN8x4_MUL_UN8 a1, t0, t3, t4, t6, t7, t8
31:
    not       t2, t3
    srl       t2, t2, 24
    MIPS_UN8x4_MUL_UN8 t1, t2, t1, t4, t6, t7, t8
    addu_s.qb t2, t1, t3
    sw        t2, 0(a0)
4:
    RESTORE_REGS_FROM_STACK 4, s0, s1, s2, s3, s4
    j         ra
     nop

END(pixman_composite_over_n_8_8888_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_over_n_8_0565_asm_mips)
/*
 * a0 - dst  (r5g6b5)
 * a1 - src  (32bit constant)
 * a2 - mask (a8)
 * a3 - w
 */
    SAVE_REGS_ON_STACK 24, v0, s0, s1, s2, s3, s4, s5, s6, s7, s8
    beqz     a3, 4f
     nop
    li       t4, 0x00ff00ff
    li       t5, 0xff
    li       t6, 0xf800f800
    li       t7, 0x07e007e0
    li       t8, 0x001F001F
    addiu    t1, a3, -1
    beqz     t1, 3f         /* last pixel */
     srl     t0, a1, 24     /* t0 = srca */
    not      v0, a1
    beq      t0, t5, 2f     /* if (srca == 0xff) */
     srl     v0, v0, 24
1:
                            /* a1 = src */
    lbu      t0, 0(a2)      /* t0 = mask */
    lbu      t1, 1(a2)      /* t1 = mask */
    or       t2, t0, t1
    beqz     t2, 111f       /* if (t0 == 0) && (t1 == 0) */
     addiu   a2, a2, 2
    lhu      t2, 0(a0)      /* t2 = dst */
    lhu      t3, 2(a0)      /* t3 = dst */
    CONVERT_2x0565_TO_2x8888 t2, t3, s0, s1, t7, t8, t9, s2, s3, s4
    and      t9, t0, t1
    beq      t9, t5, 11f    /* if (t0 == 0xff) && (t1 == 0xff) */
     nop

    MIPS_2xUN8x4_MUL_2xUN8   a1, a1, t0, t1, s2, s3, t4, t9, s4, s5, s6, s7, s8
    not      s4, s2
    not      s5, s3
    srl      s4, s4, 24
    srl      s5, s5, 24
    MIPS_2xUN8x4_MUL_2xUN8   s0, s1, s4, s5, s0, s1, t4, t9, t0, t1, s6, s7, s8
    addu_s.qb                s4, s2, s0
    addu_s.qb                s5, s3, s1
    CONVERT_2x8888_TO_2x0565 s4, s5, t2, t3, t6, t7, t8, s0, s1
    sh       t2, 0(a0)
    b        111f
     sh      t3, 2(a0)
11:
    MIPS_2xUN8x4_MUL_2xUN8   s0, s1, v0, v0, s0, s1, t4, t9, t0, t1, s6, s7, s8
    addu_s.qb                s4, a1, s0
    addu_s.qb                s5, a1, s1
    CONVERT_2x8888_TO_2x0565 s4, s5, t2, t3, t6, t7, t8, s0, s1
    sh       t2, 0(a0)
    sh       t3, 2(a0)
111:
    addiu    a3, a3, -2
    addiu    t0, a3, -1
    bgtz     t0, 1b
     addiu   a0, a0, 4
    b        3f
     nop
2:
    CONVERT_1x8888_TO_1x0565 a1, s0, s1, s2
21:
                            /* a1 = src */
    lbu      t0, 0(a2)      /* t0 = mask */
    lbu      t1, 1(a2)      /* t1 = mask */
    or       t2, t0, t1
    beqz     t2, 222f       /* if (t0 == 0) && (t1 == 0) */
     addiu   a2, a2, 2
    and      t9, t0, t1
    move     s2, s0
    beq      t9, t5, 22f    /* if (t0 == 0xff) && (t2 == 0xff) */
     move    s3, s0
    lhu      t2, 0(a0)      /* t2 = dst */
    lhu      t3, 2(a0)      /* t3 = dst */

    CONVERT_2x0565_TO_2x8888 t2, t3, s2, s3, t7, t8, s4, s5, s6, s7
    OVER_2x8888_2x8_2x8888   a1, a1, t0, t1, s2, s3, \
                             t2, t3, t4, t9, s4, s5, s6, s7, s8
    CONVERT_2x8888_TO_2x0565 t2, t3, s2, s3, t6, t7, t8, s4, s5
22:
    sh       s2, 0(a0)
    sh       s3, 2(a0)
222:
    addiu    a3, a3, -2
    addiu    t0, a3, -1
    bgtz     t0, 21b
     addiu   a0, a0, 4
3:
    blez      a3, 4f
     nop
                            /* a1 = src */
    lbu      t0, 0(a2)      /* t0 = mask */
    beqz     t0, 4f         /* if (t0 == 0) */
     nop
    lhu      t1, 0(a0)      /* t1 = dst */
    CONVERT_1x0565_TO_1x8888 t1, t2, t3, t7
    beq      t0, t5, 31f    /* if (t0 == 0xff) */
     move    t3, a1

    MIPS_UN8x4_MUL_UN8       a1, t0, t3, t4, t7, t8, t9
31:
    not      t6, t3
    srl      t6, t6, 24
    MIPS_UN8x4_MUL_UN8       t2, t6, t2, t4, t7, t8, t9
    addu_s.qb                t1, t2, t3
    CONVERT_1x8888_TO_1x0565 t1, t2, t3, t7
    sh       t2, 0(a0)
4:
    RESTORE_REGS_FROM_STACK  24, v0, s0, s1, s2, s3, s4, s5, s6, s7, s8
    j        ra
     nop

END(pixman_composite_over_n_8_0565_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_over_8888_n_8888_asm_mips)
/*
 * a0 - dst  (a8r8g8b8)
 * a1 - src  (a8r8g8b8)
 * a2 - mask (32bit constant)
 * a3 - w
 */

    SAVE_REGS_ON_STACK 0, s0
    li       t4, 0x00ff00ff
    beqz     a3, 3f
     nop
    addiu    t1, a3, -1
    srl      a2, a2, 24
    beqz     t1, 2f
     nop

1:
    lw       t0, 0(a1) /* t0 = source      (a8r8g8b8) */
    lw       t1, 4(a1) /* t1 = source      (a8r8g8b8) */
                       /* a2 = mask        (32bit constant) */
    lw       t2, 0(a0) /* t2 = destination (a8r8g8b8) */
    lw       t3, 4(a0) /* t3 = destination (a8r8g8b8) */
    addiu    a1, a1, 8

    OVER_2x8888_2x8_2x8888 t0, t1, a2, a2, t2, t3, \
                           t5, t6, t4, t7, t8, t9, t0, t1, s0

    sw       t5, 0(a0)
    sw       t6, 4(a0)
    addiu    a3, a3, -2
    addiu    t1, a3, -1
    bgtz     t1, 1b
     addiu   a0, a0, 8
2:
    beqz     a3, 3f
     nop
    lw       t0, 0(a1) /* t0 = source      (a8r8g8b8) */
                       /* a2 = mask        (32bit constant) */
    lw       t1, 0(a0) /* t1 = destination (a8r8g8b8) */

    OVER_8888_8_8888 t0, a2, t1, t3, t4, t5, t6, t7, t8

    sw       t3, 0(a0)
3:
    RESTORE_REGS_FROM_STACK 0, s0
    j        ra
     nop

END(pixman_composite_over_8888_n_8888_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_over_8888_n_0565_asm_mips)
/*
 * a0 - dst  (r5g6b5)
 * a1 - src  (a8r8g8b8)
 * a2 - mask (32bit constant)
 * a3 - w
 */

    SAVE_REGS_ON_STACK 0, s0, s1, s2, s3
    li       t6, 0x00ff00ff
    li       t7, 0xf800f800
    li       t8, 0x07e007e0
    li       t9, 0x001F001F
    beqz     a3, 3f
     nop
    srl      a2, a2, 24
    addiu    t1, a3, -1
    beqz     t1, 2f
     nop
1:
    lw       t0, 0(a1) /* t0 = source      (a8r8g8b8) */
    lw       t1, 4(a1) /* t1 = source      (a8r8g8b8) */
                       /* a2 = mask        (32bit constant) */
    lhu      t2, 0(a0) /* t2 = destination (r5g6b5) */
    lhu      t3, 2(a0) /* t2 = destination (r5g6b5) */
    addiu    a1, a1, 8

    CONVERT_2x0565_TO_2x8888 t2, t3, t4, t5, t8, t9, s0, s1, t2, t3
    OVER_2x8888_2x8_2x8888   t0, t1, a2, a2, t4, t5, \
                             t2, t3, t6, t0, t1, s0, s1, s2, s3
    CONVERT_2x8888_TO_2x0565 t2, t3, t4, t5, t7, t8, t9, s0, s1

    sh       t4, 0(a0)
    sh       t5, 2(a0)
    addiu    a3, a3, -2
    addiu    t1, a3, -1
    bgtz     t1, 1b
     addiu   a0, a0, 4
2:
    beqz     a3, 3f
     nop
    lw       t0, 0(a1) /* t0 = source      (a8r8g8b8) */
                       /* a2 = mask        (32bit constant) */
    lhu      t1, 0(a0) /* t1 = destination (r5g6b5) */

    CONVERT_1x0565_TO_1x8888 t1, t2, t4, t5
    OVER_8888_8_8888         t0, a2, t2, t1, t6, t3, t4, t5, t7
    CONVERT_1x8888_TO_1x0565 t1, t3, t4, t5

    sh       t3, 0(a0)
3:
    RESTORE_REGS_FROM_STACK 0, s0, s1, s2, s3
    j                 ra
     nop

END(pixman_composite_over_8888_n_0565_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_over_0565_n_0565_asm_mips)
/*
 * a0 - dst  (r5g6b5)
 * a1 - src  (r5g6b5)
 * a2 - mask (32bit constant)
 * a3 - w
 */

    SAVE_REGS_ON_STACK 20, s0, s1, s2, s3, s4, s5
    li       t6, 0x00ff00ff
    li       t7, 0xf800f800
    li       t8, 0x07e007e0
    li       t9, 0x001F001F
    beqz     a3, 3f
     nop
    srl      a2, a2, 24
    addiu    t1, a3, -1
    beqz     t1, 2f
     nop
1:
    lhu      t0, 0(a1) /* t0 = source      (r5g6b5) */
    lhu      t1, 2(a1) /* t1 = source      (r5g6b5) */
                       /* a2 = mask        (32bit constant) */
    lhu      t2, 0(a0) /* t2 = destination (r5g6b5) */
    lhu      t3, 2(a0) /* t3 = destination (r5g6b5) */
    addiu    a1, a1, 4

    CONVERT_2x0565_TO_2x8888 t0, t1, t4, t5, t8, t9, s0, s1, s2, s3
    CONVERT_2x0565_TO_2x8888 t2, t3, s0, s1, t8, t9, s2, s3, s4, s5
    OVER_2x8888_2x8_2x8888   t4, t5, a2, a2, s0, s1, \
                             t0, t1, t6, s2, s3, s4, s5, t4, t5
    CONVERT_2x8888_TO_2x0565 t0, t1, s0, s1, t7, t8, t9, s2, s3

    sh       s0, 0(a0)
    sh       s1, 2(a0)
    addiu    a3, a3, -2
    addiu    t1, a3, -1
    bgtz     t1, 1b
     addiu   a0, a0, 4
2:
    beqz     a3, 3f
     nop
    lhu      t0, 0(a1) /* t0 = source      (r5g6b5) */
                       /* a2 = mask        (32bit constant) */
    lhu      t1, 0(a0) /* t1 = destination (r5g6b5) */

    CONVERT_1x0565_TO_1x8888 t0, t2, t4, t5
    CONVERT_1x0565_TO_1x8888 t1, t3, t4, t5
    OVER_8888_8_8888         t2, a2, t3, t0, t6, t1, t4, t5, t7
    CONVERT_1x8888_TO_1x0565 t0, t3, t4, t5

    sh       t3, 0(a0)
3:
    RESTORE_REGS_FROM_STACK 20, s0, s1, s2, s3, s4, s5
    j        ra
     nop

END(pixman_composite_over_0565_n_0565_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_over_8888_8_8888_asm_mips)
/*
 * a0 - dst  (a8r8g8b8)
 * a1 - src  (a8r8g8b8)
 * a2 - mask (a8)
 * a3 - w
 */

    SAVE_REGS_ON_STACK 0, s0, s1
    li       t4, 0x00ff00ff
    beqz     a3, 3f
     nop
    addiu    t1, a3, -1
    beqz     t1, 2f
     nop
1:
    lw       t0, 0(a1) /* t0 = source      (a8r8g8b8) */
    lw       t1, 4(a1) /* t1 = source      (a8r8g8b8) */
    lbu      t2, 0(a2) /* t2 = mask        (a8) */
    lbu      t3, 1(a2) /* t3 = mask        (a8) */
    lw       t5, 0(a0) /* t5 = destination (a8r8g8b8) */
    lw       t6, 4(a0) /* t6 = destination (a8r8g8b8) */
    addiu    a1, a1, 8
    addiu    a2, a2, 2

    OVER_2x8888_2x8_2x8888 t0, t1, t2, t3, t5, t6, \
                           t7, t8, t4, t9, s0, s1, t0, t1, t2

    sw       t7, 0(a0)
    sw       t8, 4(a0)
    addiu    a3, a3, -2
    addiu    t1, a3, -1
    bgtz     t1, 1b
     addiu   a0, a0, 8
2:
    beqz     a3, 3f
     nop
    lw       t0, 0(a1) /* t0 = source      (a8r8g8b8) */
    lbu      t1, 0(a2) /* t1 = mask        (a8) */
    lw       t2, 0(a0) /* t2 = destination (a8r8g8b8) */

    OVER_8888_8_8888 t0, t1, t2, t3, t4, t5, t6, t7, t8

    sw       t3, 0(a0)
3:
    RESTORE_REGS_FROM_STACK 0, s0, s1
    j        ra
     nop

END(pixman_composite_over_8888_8_8888_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_over_8888_8_0565_asm_mips)
/*
 * a0 - dst  (r5g6b5)
 * a1 - src  (a8r8g8b8)
 * a2 - mask (a8)
 * a3 - w
 */

    SAVE_REGS_ON_STACK 20, s0, s1, s2, s3, s4, s5
    li       t6, 0x00ff00ff
    li       t7, 0xf800f800
    li       t8, 0x07e007e0
    li       t9, 0x001F001F
    beqz     a3, 3f
     nop
    addiu    t1, a3, -1
    beqz     t1, 2f
     nop
1:
    lw       t0, 0(a1) /* t0 = source      (a8r8g8b8) */
    lw       t1, 4(a1) /* t1 = source      (a8r8g8b8) */
    lbu      t2, 0(a2) /* t2 = mask        (a8) */
    lbu      t3, 1(a2) /* t3 = mask        (a8) */
    lhu      t4, 0(a0) /* t4 = destination (r5g6b5) */
    lhu      t5, 2(a0) /* t5 = destination (r5g6b5) */
    addiu    a1, a1, 8
    addiu    a2, a2, 2

    CONVERT_2x0565_TO_2x8888 t4, t5, s0, s1, t8, t9, s2, s3, s4, s5
    OVER_2x8888_2x8_2x8888   t0, t1, t2, t3, s0, s1, \
                             t4, t5, t6, s2, s3, s4, s5, t0, t1
    CONVERT_2x8888_TO_2x0565 t4, t5, s0, s1, t7, t8, t9, s2, s3

    sh       s0, 0(a0)
    sh       s1, 2(a0)
    addiu    a3, a3, -2
    addiu    t1, a3, -1
    bgtz     t1, 1b
     addiu   a0, a0, 4
2:
    beqz     a3, 3f
     nop
    lw       t0, 0(a1) /* t0 = source      (a8r8g8b8) */
    lbu      t1, 0(a2) /* t1 = mask        (a8) */
    lhu      t2, 0(a0) /* t2 = destination (r5g6b5) */

    CONVERT_1x0565_TO_1x8888 t2, t3, t4, t5
    OVER_8888_8_8888         t0, t1, t3, t2, t6, t4, t5, t7, t8
    CONVERT_1x8888_TO_1x0565 t2, t3, t4, t5

    sh       t3, 0(a0)
3:
    RESTORE_REGS_FROM_STACK 20, s0, s1, s2, s3, s4, s5
    j        ra
     nop

END(pixman_composite_over_8888_8_0565_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_over_0565_8_0565_asm_mips)
/*
 * a0 - dst  (r5g6b5)
 * a1 - src  (r5g6b5)
 * a2 - mask (a8)
 * a3 - w
 */

    SAVE_REGS_ON_STACK 20, s0, s1, s2, s3, s4, s5
    li       t4, 0xf800f800
    li       t5, 0x07e007e0
    li       t6, 0x001F001F
    li       t7, 0x00ff00ff
    beqz     a3, 3f
     nop
    addiu    t1, a3, -1
    beqz     t1, 2f
     nop
1:
    lhu      t0, 0(a1) /* t0 = source      (r5g6b5) */
    lhu      t1, 2(a1) /* t1 = source      (r5g6b5) */
    lbu      t2, 0(a2) /* t2 = mask        (a8) */
    lbu      t3, 1(a2) /* t3 = mask        (a8) */
    lhu      t8, 0(a0) /* t8 = destination (r5g6b5) */
    lhu      t9, 2(a0) /* t9 = destination (r5g6b5) */
    addiu    a1, a1, 4
    addiu    a2, a2, 2

    CONVERT_2x0565_TO_2x8888 t0, t1, s0, s1, t5, t6, s2, s3, s4, s5
    CONVERT_2x0565_TO_2x8888 t8, t9, s2, s3, t5, t6, s4, s5, t0, t1
    OVER_2x8888_2x8_2x8888   s0, s1, t2, t3, s2, s3, \
                             t0, t1, t7, s4, s5, t8, t9, s0, s1
    CONVERT_2x8888_TO_2x0565 t0, t1, s0, s1, t4, t5, t6, s2, s3

    sh       s0, 0(a0)
    sh       s1, 2(a0)
    addiu    a3, a3, -2
    addiu    t1, a3, -1
    bgtz     t1, 1b
     addiu   a0, a0, 4
2:
    beqz     a3, 3f
     nop
    lhu      t0, 0(a1) /* t0 = source      (r5g6b5) */
    lbu      t1, 0(a2) /* t1 = mask        (a8) */
    lhu      t2, 0(a0) /* t2 = destination (r5g6b5) */

    CONVERT_1x0565_TO_1x8888 t0, t3, t4, t5
    CONVERT_1x0565_TO_1x8888 t2, t4, t5, t6
    OVER_8888_8_8888         t3, t1, t4, t0, t7, t2, t5, t6, t8
    CONVERT_1x8888_TO_1x0565 t0, t3, t4, t5

    sh       t3, 0(a0)
3:
    RESTORE_REGS_FROM_STACK 20, s0, s1, s2, s3, s4, s5
    j        ra
     nop

END(pixman_composite_over_0565_8_0565_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_over_8888_8888_8888_asm_mips)
/*
 * a0 - dst  (a8r8g8b8)
 * a1 - src  (a8r8g8b8)
 * a2 - mask (a8r8g8b8)
 * a3 - w
 */

    SAVE_REGS_ON_STACK 0, s0, s1, s2
    li       t4, 0x00ff00ff
    beqz     a3, 3f
     nop
    addiu    t1, a3, -1
    beqz     t1, 2f
     nop
1:
    lw       t0, 0(a1) /* t0 = source      (a8r8g8b8) */
    lw       t1, 4(a1) /* t1 = source      (a8r8g8b8) */
    lw       t2, 0(a2) /* t2 = mask        (a8r8g8b8) */
    lw       t3, 4(a2) /* t3 = mask        (a8r8g8b8) */
    lw       t5, 0(a0) /* t5 = destination (a8r8g8b8) */
    lw       t6, 4(a0) /* t6 = destination (a8r8g8b8) */
    addiu    a1, a1, 8
    addiu    a2, a2, 8
    srl      t2, t2, 24
    srl      t3, t3, 24

    OVER_2x8888_2x8_2x8888 t0, t1, t2, t3, t5, t6, t7, t8, t4, t9, s0, s1, s2, t0, t1

    sw       t7, 0(a0)
    sw       t8, 4(a0)
    addiu    a3, a3, -2
    addiu    t1, a3, -1
    bgtz     t1, 1b
     addiu   a0, a0, 8
2:
    beqz     a3, 3f
     nop
    lw       t0, 0(a1) /* t0 = source      (a8r8g8b8) */
    lw       t1, 0(a2) /* t1 = mask        (a8r8g8b8) */
    lw       t2, 0(a0) /* t2 = destination (a8r8g8b8) */
    srl      t1, t1, 24

    OVER_8888_8_8888 t0, t1, t2, t3, t4, t5, t6, t7, t8

    sw       t3, 0(a0)
3:
    RESTORE_REGS_FROM_STACK 0, s0, s1, s2
    j        ra
     nop

END(pixman_composite_over_8888_8888_8888_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_over_8888_8888_asm_mips)
/*
 * a0 - dst  (a8r8g8b8)
 * a1 - src  (a8r8g8b8)
 * a2 - w
 */

    SAVE_REGS_ON_STACK 0, s0, s1, s2
    li           t4, 0x00ff00ff
    beqz         a2, 3f
     nop
    addiu        t1, a2, -1
    beqz         t1, 2f
     nop
1:
    lw           t0, 0(a1) /* t0 = source      (a8r8g8b8) */
    lw           t1, 4(a1) /* t1 = source      (a8r8g8b8) */
    lw           t2, 0(a0) /* t2 = destination (a8r8g8b8) */
    lw           t3, 4(a0) /* t3 = destination (a8r8g8b8) */
    addiu        a1, a1, 8

    not          t5, t0
    srl          t5, t5, 24
    not          t6, t1
    srl          t6, t6, 24

    or           t7, t5, t6
    beqz         t7, 11f
     or          t8, t0, t1
    beqz         t8, 12f

    MIPS_2xUN8x4_MUL_2xUN8 t2, t3, t5, t6, t7, t8, t4, t9, s0, s1, s2, t2, t3

    addu_s.qb    t0, t7, t0
    addu_s.qb    t1, t8, t1
11:
    sw           t0, 0(a0)
    sw           t1, 4(a0)
12:
    addiu        a2, a2, -2
    addiu        t1, a2, -1
    bgtz         t1, 1b
     addiu       a0, a0, 8
2:
    beqz         a2, 3f
     nop

    lw           t0, 0(a1) /* t0 = source      (a8r8g8b8) */
    lw           t1, 0(a0) /* t1 = destination (a8r8g8b8) */
    addiu        a1, a1, 4

    not          t2, t0
    srl          t2, t2, 24

    beqz         t2, 21f
     nop
    beqz         t0, 3f

    MIPS_UN8x4_MUL_UN8 t1, t2, t3, t4, t5, t6, t7

    addu_s.qb    t0, t3, t0
21:
    sw           t0, 0(a0)

3:
    RESTORE_REGS_FROM_STACK 0, s0, s1, s2
    j            ra
     nop

END(pixman_composite_over_8888_8888_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_over_8888_0565_asm_mips)
/*
 * a0 - dst  (r5g6b5)
 * a1 - src  (a8r8g8b8)
 * a2 - w
 */

    SAVE_REGS_ON_STACK 8, s0, s1, s2, s3, s4, s5
    li           t4, 0x00ff00ff
    li           s3, 0xf800f800
    li           s4, 0x07e007e0
    li           s5, 0x001F001F
    beqz         a2, 3f
     nop
    addiu        t1, a2, -1
    beqz         t1, 2f
     nop
1:
    lw           t0, 0(a1) /* t0 = source      (a8r8g8b8) */
    lw           t1, 4(a1) /* t1 = source      (a8r8g8b8) */
    lhu          t2, 0(a0) /* t2 = destination (r5g6b5) */
    lhu          t3, 2(a0) /* t3 = destination (r5g6b5) */
    addiu        a1, a1, 8

    not          t5, t0
    srl          t5, t5, 24
    not          t6, t1
    srl          t6, t6, 24

    or           t7, t5, t6
    beqz         t7, 11f
     or          t8, t0, t1
    beqz         t8, 12f

    CONVERT_2x0565_TO_2x8888 t2, t3, s0, s1, s4, s5, t7, t8, t9, s2
    MIPS_2xUN8x4_MUL_2xUN8   s0, s1, t5, t6, t7, t8, t4, t9, t2, t3, s2, s0, s1

    addu_s.qb    t0, t7, t0
    addu_s.qb    t1, t8, t1
11:
    CONVERT_2x8888_TO_2x0565 t0, t1, t7, t8, s3, s4, s5, t2, t3
    sh           t7, 0(a0)
    sh           t8, 2(a0)
12:
    addiu        a2, a2, -2
    addiu        t1, a2, -1
    bgtz         t1, 1b
     addiu       a0, a0, 4
2:
    beqz         a2, 3f
     nop

    lw           t0, 0(a1) /* t0 = source      (a8r8g8b8) */
    lhu          t1, 0(a0) /* t1 = destination (r5g6b5) */
    addiu        a1, a1, 4

    not          t2, t0
    srl          t2, t2, 24

    beqz         t2, 21f
     nop
    beqz         t0, 3f

    CONVERT_1x0565_TO_1x8888 t1, s0, t8, t9
    MIPS_UN8x4_MUL_UN8       s0, t2, t3, t4, t5, t6, t7

    addu_s.qb    t0, t3, t0
21:
    CONVERT_1x8888_TO_1x0565 t0, s0, t8, t9
    sh           s0, 0(a0)

3:
    RESTORE_REGS_FROM_STACK 8, s0, s1, s2, s3, s4, s5
    j            ra
     nop

END(pixman_composite_over_8888_0565_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_over_n_0565_asm_mips)
/*
 * a0 - dst  (r5g6b5)
 * a1 - src  (32bit constant)
 * a2 - w
 */

    beqz         a2, 5f
     nop

    not          t0, a1
    srl          t0, t0, 24
    bgtz         t0, 1f
     nop
    CONVERT_1x8888_TO_1x0565 a1, t1, t2, t3
0:
    sh           t1, 0(a0)
    addiu        a2, a2, -1
    bgtz         a2, 0b
     addiu       a0, a0, 2
    j            ra
     nop

1:
    SAVE_REGS_ON_STACK 0, s0, s1, s2
    li           t4, 0x00ff00ff
    li           t5, 0xf800f800
    li           t6, 0x07e007e0
    li           t7, 0x001F001F
    addiu        t1, a2, -1
    beqz         t1, 3f
     nop
2:
    lhu          t1, 0(a0) /* t1 = destination (r5g6b5) */
    lhu          t2, 2(a0) /* t2 = destination (r5g6b5) */

    CONVERT_2x0565_TO_2x8888 t1, t2, t3, t8, t6, t7, t9, s0, s1, s2
    MIPS_2xUN8x4_MUL_2xUN8   t3, t8, t0, t0, t1, t2, t4, t9, s0, s1, s2, t3, t8
    addu_s.qb                t1, t1, a1
    addu_s.qb                t2, t2, a1
    CONVERT_2x8888_TO_2x0565 t1, t2, t3, t8, t5, t6, t7, s0, s1

    sh           t3, 0(a0)
    sh           t8, 2(a0)

    addiu        a2, a2, -2
    addiu        t1, a2, -1
    bgtz         t1, 2b
     addiu       a0, a0, 4
3:
    beqz         a2, 4f
     nop

    lhu          t1, 0(a0) /* t1 = destination (r5g6b5) */

    CONVERT_1x0565_TO_1x8888 t1, t2, s0, s1
    MIPS_UN8x4_MUL_UN8       t2, t0, t1, t4, s0, s1, s2
    addu_s.qb                t1, t1, a1
    CONVERT_1x8888_TO_1x0565 t1, t2, s0, s1

    sh           t2, 0(a0)

4:
    RESTORE_REGS_FROM_STACK 0, s0, s1, s2
5:
    j            ra
     nop

END(pixman_composite_over_n_0565_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_over_n_8888_asm_mips)
/*
 * a0 - dst  (a8r8g8b8)
 * a1 - src  (32bit constant)
 * a2 - w
 */

    beqz         a2, 5f
     nop

    not          t0, a1
    srl          t0, t0, 24
    bgtz         t0, 1f
     nop
0:
    sw           a1, 0(a0)
    addiu        a2, a2, -1
    bgtz         a2, 0b
     addiu       a0, a0, 4
    j            ra
     nop

1:
    SAVE_REGS_ON_STACK 0, s0, s1, s2
    li           t4, 0x00ff00ff
    addiu        t1, a2, -1
    beqz         t1, 3f
     nop
2:
    lw           t2, 0(a0) /* t2 = destination (a8r8g8b8) */
    lw           t3, 4(a0) /* t3 = destination (a8r8g8b8) */

    MIPS_2xUN8x4_MUL_2xUN8 t2, t3, t0, t0, t7, t8, t4, t9, s0, s1, s2, t2, t3

    addu_s.qb    t7, t7, a1
    addu_s.qb    t8, t8, a1

    sw           t7, 0(a0)
    sw           t8, 4(a0)

    addiu        a2, a2, -2
    addiu        t1, a2, -1
    bgtz         t1, 2b
     addiu       a0, a0, 8
3:
    beqz         a2, 4f
     nop

    lw           t1, 0(a0) /* t1 = destination (a8r8g8b8) */

    MIPS_UN8x4_MUL_UN8 t1, t0, t3, t4, t5, t6, t7

    addu_s.qb    t3, t3, a1

    sw           t3, 0(a0)

4:
    RESTORE_REGS_FROM_STACK 0, s0, s1, s2
5:
    j            ra
     nop

END(pixman_composite_over_n_8888_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_add_8_8_8_asm_mips)
/*
 * a0 - dst  (a8)
 * a1 - src  (a8)
 * a2 - mask (a8)
 * a3 - w
 */

    SAVE_REGS_ON_STACK 0, v0, v1
    li                t9, 0x00ff00ff
    beqz              a3, 3f
     nop

    srl               v0, a3, 2   /* v0 = how many multiples of 4 dst pixels */
    beqz              v0, 1f      /* branch if less than 4 src pixels */
     nop

0:
    beqz              v0, 1f
     addiu            v0, v0, -1
    lbu               t0, 0(a2)
    lbu               t1, 1(a2)
    lbu               t2, 2(a2)
    lbu               t3, 3(a2)
    lbu               t4, 0(a0)
    lbu               t5, 1(a0)
    lbu               t6, 2(a0)
    lbu               t7, 3(a0)

    addiu             a2, a2, 4

    precr_sra.ph.w    t1, t0, 0
    precr_sra.ph.w    t3, t2, 0
    precr_sra.ph.w    t5, t4, 0
    precr_sra.ph.w    t7, t6, 0

    precr.qb.ph       t0, t3, t1
    precr.qb.ph       t1, t7, t5

    lbu               t4, 0(a1)
    lbu               v1, 1(a1)
    lbu               t7, 2(a1)
    lbu               t8, 3(a1)

    addiu             a1, a1, 4

    precr_sra.ph.w    v1, t4, 0
    precr_sra.ph.w    t8, t7, 0

    muleu_s.ph.qbl    t2, t0, t8
    muleu_s.ph.qbr    t3, t0, v1
    shra_r.ph         t4, t2, 8
    shra_r.ph         t5, t3, 8
    and               t4, t4, t9
    and               t5, t5, t9
    addq.ph           t2, t2, t4
    addq.ph           t3, t3, t5
    shra_r.ph         t2, t2, 8
    shra_r.ph         t3, t3, 8
    precr.qb.ph       t0, t2, t3

    addu_s.qb         t2, t0, t1

    sb                t2, 0(a0)
    srl               t2, t2, 8
    sb                t2, 1(a0)
    srl               t2, t2, 8
    sb                t2, 2(a0)
    srl               t2, t2, 8
    sb                t2, 3(a0)
    addiu             a3, a3, -4
    b                 0b
     addiu            a0, a0, 4

1:
    beqz              a3, 3f
     nop
2:
    lbu               t8, 0(a1)
    lbu               t0, 0(a2)
    lbu               t1, 0(a0)
    addiu             a1, a1, 1
    addiu             a2, a2, 1

    mul               t2, t0, t8
    shra_r.ph         t3, t2, 8
    andi              t3, t3, 0xff
    addq.ph           t2, t2, t3
    shra_r.ph         t2, t2, 8
    andi              t2, t2, 0xff

    addu_s.qb         t2, t2, t1
    sb                t2, 0(a0)
    addiu             a3, a3, -1
    bnez              a3, 2b
     addiu            a0, a0, 1

3:
    RESTORE_REGS_FROM_STACK 0, v0, v1
    j                 ra
     nop

END(pixman_composite_add_8_8_8_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_add_n_8_8_asm_mips)
/*
 * a0 - dst  (a8)
 * a1 - src  (32bit constant)
 * a2 - mask (a8)
 * a3 - w
 */

    SAVE_REGS_ON_STACK 0, v0
    li                t9, 0x00ff00ff
    beqz              a3, 3f
     nop

    srl               v0, a3, 2   /* v0 = how many multiples of 4 dst pixels */
    beqz              v0, 1f      /* branch if less than 4 src pixels */
     nop

    srl               t8, a1, 24
    replv.ph          t8, t8

0:
    beqz              v0, 1f
     addiu            v0, v0, -1
    lbu               t0, 0(a2)
    lbu               t1, 1(a2)
    lbu               t2, 2(a2)
    lbu               t3, 3(a2)
    lbu               t4, 0(a0)
    lbu               t5, 1(a0)
    lbu               t6, 2(a0)
    lbu               t7, 3(a0)

    addiu             a2, a2, 4

    precr_sra.ph.w    t1, t0, 0
    precr_sra.ph.w    t3, t2, 0
    precr_sra.ph.w    t5, t4, 0
    precr_sra.ph.w    t7, t6, 0

    precr.qb.ph       t0, t3, t1
    precr.qb.ph       t1, t7, t5

    muleu_s.ph.qbl    t2, t0, t8
    muleu_s.ph.qbr    t3, t0, t8
    shra_r.ph         t4, t2, 8
    shra_r.ph         t5, t3, 8
    and               t4, t4, t9
    and               t5, t5, t9
    addq.ph           t2, t2, t4
    addq.ph           t3, t3, t5
    shra_r.ph         t2, t2, 8
    shra_r.ph         t3, t3, 8
    precr.qb.ph       t0, t2, t3

    addu_s.qb         t2, t0, t1

    sb                t2, 0(a0)
    srl               t2, t2, 8
    sb                t2, 1(a0)
    srl               t2, t2, 8
    sb                t2, 2(a0)
    srl               t2, t2, 8
    sb                t2, 3(a0)
    addiu             a3, a3, -4
    b                 0b
     addiu            a0, a0, 4

1:
    beqz              a3, 3f
     nop
    srl               t8, a1, 24
2:
    lbu               t0, 0(a2)
    lbu               t1, 0(a0)
    addiu             a2, a2, 1

    mul               t2, t0, t8
    shra_r.ph         t3, t2, 8
    andi              t3, t3, 0xff
    addq.ph           t2, t2, t3
    shra_r.ph         t2, t2, 8
    andi              t2, t2, 0xff

    addu_s.qb         t2, t2, t1
    sb                t2, 0(a0)
    addiu             a3, a3, -1
    bnez              a3, 2b
     addiu            a0, a0, 1

3:
    RESTORE_REGS_FROM_STACK 0, v0
    j                 ra
     nop

END(pixman_composite_add_n_8_8_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_add_n_8_8888_asm_mips)
/*
 * a0 - dst  (a8r8g8b8)
 * a1 - src  (32bit constant)
 * a2 - mask (a8)
 * a3 - w
 */

    SAVE_REGS_ON_STACK 0, s0, s1, s2
    li       t4, 0x00ff00ff
    beqz     a3, 3f
     nop
    addiu    t1, a3, -1
    beqz     t1, 2f
     nop
1:
                       /* a1 = source      (32bit constant) */
    lbu      t0, 0(a2) /* t0 = mask        (a8) */
    lbu      t1, 1(a2) /* t1 = mask        (a8) */
    lw       t2, 0(a0) /* t2 = destination (a8r8g8b8) */
    lw       t3, 4(a0) /* t3 = destination (a8r8g8b8) */
    addiu    a2, a2, 2

    MIPS_2xUN8x4_MUL_2xUN8_ADD_2xUN8x4 a1, a1, \
                                       t0, t1, \
                                       t2, t3, \
                                       t5, t6, \
                                       t4, t7, t8, t9, s0, s1, s2

    sw       t5, 0(a0)
    sw       t6, 4(a0)
    addiu    a3, a3, -2
    addiu    t1, a3, -1
    bgtz     t1, 1b
     addiu   a0, a0, 8
2:
    beqz     a3, 3f
     nop
                       /* a1 = source      (32bit constant) */
    lbu      t0, 0(a2) /* t0 = mask        (a8) */
    lw       t1, 0(a0) /* t1 = destination (a8r8g8b8) */

    MIPS_UN8x4_MUL_UN8_ADD_UN8x4 a1, t0, t1, t2, t4, t3, t5, t6

    sw       t2, 0(a0)
3:
    RESTORE_REGS_FROM_STACK 0, s0, s1, s2
    j        ra
     nop

END(pixman_composite_add_n_8_8888_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_add_0565_8_0565_asm_mips)
/*
 * a0 - dst  (r5g6b5)
 * a1 - src  (r5g6b5)
 * a2 - mask (a8)
 * a3 - w
 */

    SAVE_REGS_ON_STACK 20, s0, s1, s2, s3, s4, s5, s6, s7
    li       t4, 0xf800f800
    li       t5, 0x07e007e0
    li       t6, 0x001F001F
    li       t7, 0x00ff00ff
    beqz     a3, 3f
     nop
    addiu    t1, a3, -1
    beqz     t1, 2f
     nop
1:
    lhu      t0, 0(a1) /* t0 = source      (r5g6b5) */
    lhu      t1, 2(a1) /* t1 = source      (r5g6b5) */
    lbu      t2, 0(a2) /* t2 = mask        (a8) */
    lbu      t3, 1(a2) /* t3 = mask        (a8) */
    lhu      t8, 0(a0) /* t8 = destination (r5g6b5) */
    lhu      t9, 2(a0) /* t9 = destination (r5g6b5) */
    addiu    a1, a1, 4
    addiu    a2, a2, 2

    CONVERT_2x0565_TO_2x8888  t0, t1, s0, s1, t5, t6, s2, s3, s4, s5
    CONVERT_2x0565_TO_2x8888  t8, t9, s2, s3, t5, t6, s4, s5, s6, s7
    MIPS_2xUN8x4_MUL_2xUN8_ADD_2xUN8x4  s0, s1, \
                                        t2, t3, \
                                        s2, s3, \
                                        t0, t1, \
                                        t7, s4, s5, s6, s7, t8, t9
    CONVERT_2x8888_TO_2x0565  t0, t1, s0, s1, t4, t5, t6, s2, s3

    sh       s0, 0(a0)
    sh       s1, 2(a0)
    addiu    a3, a3, -2
    addiu    t1, a3, -1
    bgtz     t1, 1b
     addiu   a0, a0, 4
2:
    beqz     a3, 3f
     nop
    lhu      t0, 0(a1) /* t0 = source      (r5g6b5) */
    lbu      t1, 0(a2) /* t1 = mask        (a8) */
    lhu      t2, 0(a0) /* t2 = destination (r5g6b5) */

    CONVERT_1x0565_TO_1x8888  t0, t3, t4, t5
    CONVERT_1x0565_TO_1x8888  t2, t4, t5, t6
    MIPS_UN8x4_MUL_UN8_ADD_UN8x4  t3, t1, t4, t0, t7, t2, t5, t6
    CONVERT_1x8888_TO_1x0565  t0, t3, t4, t5

    sh       t3, 0(a0)
3:
    RESTORE_REGS_FROM_STACK 20, s0, s1, s2, s3, s4, s5, s6, s7
    j        ra
     nop

END(pixman_composite_add_0565_8_0565_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_add_8888_8_8888_asm_mips)
/*
 * a0 - dst  (a8r8g8b8)
 * a1 - src  (a8r8g8b8)
 * a2 - mask (a8)
 * a3 - w
 */

    SAVE_REGS_ON_STACK 0, s0, s1, s2
    li       t4, 0x00ff00ff
    beqz     a3, 3f
     nop
    addiu    t1, a3, -1
    beqz     t1, 2f
     nop
1:
    lw       t0, 0(a1) /* t0 = source      (a8r8g8b8) */
    lw       t1, 4(a1) /* t1 = source      (a8r8g8b8) */
    lbu      t2, 0(a2) /* t2 = mask        (a8) */
    lbu      t3, 1(a2) /* t3 = mask        (a8) */
    lw       t5, 0(a0) /* t5 = destination (a8r8g8b8) */
    lw       t6, 4(a0) /* t6 = destination (a8r8g8b8) */
    addiu    a1, a1, 8
    addiu    a2, a2, 2

    MIPS_2xUN8x4_MUL_2xUN8_ADD_2xUN8x4 t0, t1, \
                                       t2, t3, \
                                       t5, t6, \
                                       t7, t8, \
                                       t4, t9, s0, s1, s2, t0, t1

    sw       t7, 0(a0)
    sw       t8, 4(a0)
    addiu    a3, a3, -2
    addiu    t1, a3, -1
    bgtz     t1, 1b
     addiu   a0, a0, 8
2:
    beqz     a3, 3f
     nop
    lw       t0, 0(a1) /* t0 = source      (a8r8g8b8) */
    lbu      t1, 0(a2) /* t1 = mask        (a8) */
    lw       t2, 0(a0) /* t2 = destination (a8r8g8b8) */

    MIPS_UN8x4_MUL_UN8_ADD_UN8x4 t0, t1, t2, t3, t4, t5, t6, t7

    sw       t3, 0(a0)
3:
    RESTORE_REGS_FROM_STACK 0, s0, s1, s2
    j        ra
     nop

END(pixman_composite_add_8888_8_8888_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_add_8888_n_8888_asm_mips)
/*
 * a0 - dst  (a8r8g8b8)
 * a1 - src  (a8r8g8b8)
 * a2 - mask (32bit constant)
 * a3 - w
 */

    SAVE_REGS_ON_STACK 0, s0, s1, s2
    li       t4, 0x00ff00ff
    beqz     a3, 3f
     nop
    srl      a2, a2, 24
    addiu    t1, a3, -1
    beqz     t1, 2f
     nop
1:
    lw       t0, 0(a1) /* t0 = source      (a8r8g8b8) */
    lw       t1, 4(a1) /* t1 = source      (a8r8g8b8) */
                       /* a2 = mask        (32bit constant) */
    lw       t2, 0(a0) /* t2 = destination (a8r8g8b8) */
    lw       t3, 4(a0) /* t3 = destination (a8r8g8b8) */
    addiu    a1, a1, 8

    MIPS_2xUN8x4_MUL_2xUN8_ADD_2xUN8x4 t0, t1, \
                                       a2, a2, \
                                       t2, t3, \
                                       t5, t6, \
                                       t4, t7, t8, t9, s0, s1, s2

    sw       t5, 0(a0)
    sw       t6, 4(a0)
    addiu    a3, a3, -2
    addiu    t1, a3, -1
    bgtz     t1, 1b
     addiu   a0, a0, 8
2:
    beqz     a3, 3f
     nop
    lw       t0, 0(a1) /* t0 = source      (a8r8g8b8) */
                       /* a2 = mask        (32bit constant) */
    lw       t1, 0(a0) /* t1 = destination (a8r8g8b8) */

    MIPS_UN8x4_MUL_UN8_ADD_UN8x4 t0, a2, t1, t3, t4, t5, t6, t7

    sw       t3, 0(a0)
3:
    RESTORE_REGS_FROM_STACK 0, s0, s1, s2
    j        ra
     nop

END(pixman_composite_add_8888_n_8888_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_add_8888_8888_8888_asm_mips)
/*
 * a0 - dst  (a8r8g8b8)
 * a1 - src  (a8r8g8b8)
 * a2 - mask (a8r8g8b8)
 * a3 - w
 */

    SAVE_REGS_ON_STACK 0, s0, s1, s2
    li       t4, 0x00ff00ff
    beqz     a3, 3f
     nop
    addiu    t1, a3, -1
    beqz     t1, 2f
     nop
1:
    lw       t0, 0(a1) /* t0 = source      (a8r8g8b8) */
    lw       t1, 4(a1) /* t1 = source      (a8r8g8b8) */
    lw       t2, 0(a2) /* t2 = mask        (a8r8g8b8) */
    lw       t3, 4(a2) /* t3 = mask        (a8r8g8b8) */
    lw       t5, 0(a0) /* t5 = destination (a8r8g8b8) */
    lw       t6, 4(a0) /* t6 = destination (a8r8g8b8) */
    addiu    a1, a1, 8
    addiu    a2, a2, 8
    srl      t2, t2, 24
    srl      t3, t3, 24

    MIPS_2xUN8x4_MUL_2xUN8_ADD_2xUN8x4 t0, t1, \
                                       t2, t3, \
                                       t5, t6, \
                                       t7, t8, \
                                       t4, t9, s0, s1, s2, t0, t1

    sw       t7, 0(a0)
    sw       t8, 4(a0)
    addiu    a3, a3, -2
    addiu    t1, a3, -1
    bgtz     t1, 1b
     addiu   a0, a0, 8
2:
    beqz     a3, 3f
     nop
    lw       t0, 0(a1) /* t0 = source      (a8r8g8b8) */
    lw       t1, 0(a2) /* t1 = mask        (a8r8g8b8) */
    lw       t2, 0(a0) /* t2 = destination (a8r8g8b8) */
    srl      t1, t1, 24

    MIPS_UN8x4_MUL_UN8_ADD_UN8x4 t0, t1, t2, t3, t4, t5, t6, t7

    sw       t3, 0(a0)
3:
    RESTORE_REGS_FROM_STACK 0, s0, s1, s2
    j        ra
     nop

END(pixman_composite_add_8888_8888_8888_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_add_8_8_asm_mips)
/*
 * a0 - dst  (a8)
 * a1 - src  (a8)
 * a2 - w
 */

    beqz              a2, 3f
     nop
    srl               t9, a2, 2   /* t9 = how many multiples of 4 dst pixels */
    beqz              t9, 1f      /* branch if less than 4 src pixels */
     nop

0:
    beqz              t9, 1f
     addiu            t9, t9, -1
    lbu               t0, 0(a1)
    lbu               t1, 1(a1)
    lbu               t2, 2(a1)
    lbu               t3, 3(a1)
    lbu               t4, 0(a0)
    lbu               t5, 1(a0)
    lbu               t6, 2(a0)
    lbu               t7, 3(a0)

    addiu             a1, a1, 4

    precr_sra.ph.w    t1, t0, 0
    precr_sra.ph.w    t3, t2, 0
    precr_sra.ph.w    t5, t4, 0
    precr_sra.ph.w    t7, t6, 0

    precr.qb.ph       t0, t3, t1
    precr.qb.ph       t1, t7, t5

    addu_s.qb         t2, t0, t1

    sb                t2, 0(a0)
    srl               t2, t2, 8
    sb                t2, 1(a0)
    srl               t2, t2, 8
    sb                t2, 2(a0)
    srl               t2, t2, 8
    sb                t2, 3(a0)
    addiu             a2, a2, -4
    b                 0b
     addiu            a0, a0, 4

1:
    beqz              a2, 3f
     nop
2:
    lbu               t0, 0(a1)
    lbu               t1, 0(a0)
    addiu             a1, a1, 1

    addu_s.qb         t2, t0, t1
    sb                t2, 0(a0)
    addiu             a2, a2, -1
    bnez              a2, 2b
     addiu            a0, a0, 1

3:
    j                 ra
     nop

END(pixman_composite_add_8_8_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_add_8888_8888_asm_mips)
/*
 * a0 - dst (a8r8g8b8)
 * a1 - src (a8r8g8b8)
 * a2 - w
 */

    beqz         a2, 4f
     nop

    srl          t9, a2, 2      /* t1 = how many multiples of 4 src pixels */
    beqz         t9, 3f         /* branch if less than 4 src pixels */
     nop
1:
    addiu        t9, t9, -1
    beqz         t9, 2f
     addiu       a2, a2, -4

    lw           t0, 0(a1)
    lw           t1, 4(a1)
    lw           t2, 8(a1)
    lw           t3, 12(a1)
    lw           t4, 0(a0)
    lw           t5, 4(a0)
    lw           t6, 8(a0)
    lw           t7, 12(a0)
    addiu        a1, a1, 16

    addu_s.qb    t4, t4, t0
    addu_s.qb    t5, t5, t1
    addu_s.qb    t6, t6, t2
    addu_s.qb    t7, t7, t3

    sw           t4, 0(a0)
    sw           t5, 4(a0)
    sw           t6, 8(a0)
    sw           t7, 12(a0)
    b            1b
     addiu       a0, a0, 16
2:
    lw           t0, 0(a1)
    lw           t1, 4(a1)
    lw           t2, 8(a1)
    lw           t3, 12(a1)
    lw           t4, 0(a0)
    lw           t5, 4(a0)
    lw           t6, 8(a0)
    lw           t7, 12(a0)
    addiu        a1, a1, 16

    addu_s.qb    t4, t4, t0
    addu_s.qb    t5, t5, t1
    addu_s.qb    t6, t6, t2
    addu_s.qb    t7, t7, t3

    sw           t4, 0(a0)
    sw           t5, 4(a0)
    sw           t6, 8(a0)
    sw           t7, 12(a0)

    beqz         a2, 4f
     addiu       a0, a0, 16
3:
    lw           t0, 0(a1)
    lw           t1, 0(a0)
    addiu        a1, a1, 4
    addiu        a2, a2, -1
    addu_s.qb    t1, t1, t0
    sw           t1, 0(a0)
    bnez         a2, 3b
     addiu       a0, a0, 4
4:
    jr           ra
     nop

END(pixman_composite_add_8888_8888_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_out_reverse_8_0565_asm_mips)
/*
 * a0 - dst  (r5g6b5)
 * a1 - src  (a8)
 * a2 - w
 */

    beqz     a2, 4f
     nop

    SAVE_REGS_ON_STACK 0, s0, s1, s2, s3
    li       t2, 0xf800f800
    li       t3, 0x07e007e0
    li       t4, 0x001F001F
    li       t5, 0x00ff00ff

    addiu    t1, a2, -1
    beqz     t1, 2f
     nop
1:
    lbu      t0, 0(a1) /* t0 = source      (a8) */
    lbu      t1, 1(a1) /* t1 = source      (a8) */
    lhu      t6, 0(a0) /* t6 = destination (r5g6b5) */
    lhu      t7, 2(a0) /* t7 = destination (r5g6b5) */
    addiu    a1, a1, 2

    not      t0, t0
    not      t1, t1
    andi     t0, 0xff  /* t0 = neg source1 */
    andi     t1, 0xff  /* t1 = neg source2 */
    CONVERT_2x0565_TO_2x8888 t6, t7, t8, t9, t3, t4, s0, s1, s2, s3
    MIPS_2xUN8x4_MUL_2xUN8   t8, t9, t0, t1, t6, t7, t5, s0, s1, s2, s3, t8, t9
    CONVERT_2x8888_TO_2x0565 t6, t7, t8, t9, t2, t3, t4, s0, s1

    sh       t8, 0(a0)
    sh       t9, 2(a0)
    addiu    a2, a2, -2
    addiu    t1, a2, -1
    bgtz     t1, 1b
     addiu   a0, a0, 4
2:
    beqz     a2, 3f
     nop
    lbu      t0, 0(a1) /* t0 = source      (a8) */
    lhu      t1, 0(a0) /* t1 = destination (r5g6b5) */

    not      t0, t0
    andi     t0, 0xff  /* t0 = neg source */
    CONVERT_1x0565_TO_1x8888 t1, t2, t3, t4
    MIPS_UN8x4_MUL_UN8        t2, t0, t1, t5, t3, t4, t6
    CONVERT_1x8888_TO_1x0565 t1, t2, t3, t4

    sh       t2, 0(a0)
3:
    RESTORE_REGS_FROM_STACK 0, s0, s1, s2, s3
4:
    j        ra
     nop

END(pixman_composite_out_reverse_8_0565_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_out_reverse_8_8888_asm_mips)
/*
 * a0 - dst  (a8r8g8b8)
 * a1 - src  (a8)
 * a2 - w
 */

    beqz     a2, 3f
     nop
    li       t4, 0x00ff00ff
    addiu    t1, a2, -1
    beqz     t1, 2f
     nop
1:
    lbu      t0, 0(a1) /* t0 = source      (a8) */
    lbu      t1, 1(a1) /* t1 = source      (a8) */
    lw       t2, 0(a0) /* t2 = destination (a8r8g8b8) */
    lw       t3, 4(a0) /* t3 = destination (a8r8g8b8) */
    addiu    a1, a1, 2
    not      t0, t0
    not      t1, t1
    andi     t0, 0xff  /* t0 = neg source */
    andi     t1, 0xff  /* t1 = neg source */

    MIPS_2xUN8x4_MUL_2xUN8 t2, t3, t0, t1, t5, t6, t4, t7, t8, t9, t2, t3, t0

    sw       t5, 0(a0)
    sw       t6, 4(a0)
    addiu    a2, a2, -2
    addiu    t1, a2, -1
    bgtz     t1, 1b
     addiu   a0, a0, 8
2:
    beqz     a2, 3f
     nop
    lbu      t0, 0(a1) /* t0 = source      (a8) */
    lw       t1, 0(a0) /* t1 = destination (a8r8g8b8) */
    not      t0, t0
    andi     t0, 0xff  /* t0 = neg source */

    MIPS_UN8x4_MUL_UN8 t1, t0, t2, t4, t3, t5, t6

    sw       t2, 0(a0)
3:
    j        ra
     nop

END(pixman_composite_out_reverse_8_8888_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_over_reverse_n_8888_asm_mips)
/*
 * a0 - dst  (a8r8g8b8)
 * a1 - src  (32bit constant)
 * a2 - w
 */

    beqz              a2, 5f
     nop

    SAVE_REGS_ON_STACK 20, s0, s1, s2, s3, s4, s5, s6, s7
    li                t0, 0x00ff00ff
    srl               t9, a2, 2   /* t9 = how many multiples of 4 src pixels */
    beqz              t9, 2f      /* branch if less than 4 src pixels */
     nop
1:
    beqz              t9, 2f
     addiu            t9, t9, -1

    lw                t1, 0(a0)
    lw                t2, 4(a0)
    lw                t3, 8(a0)
    lw                t4, 12(a0)

    addiu             a2, a2, -4

    not               t5, t1
    not               t6, t2
    not               t7, t3
    not               t8, t4
    srl               t5, t5, 24
    srl               t6, t6, 24
    srl               t7, t7, 24
    srl               t8, t8, 24
    replv.ph          t5, t5
    replv.ph          t6, t6
    replv.ph          t7, t7
    replv.ph          t8, t8
    muleu_s.ph.qbl    s0, a1, t5
    muleu_s.ph.qbr    s1, a1, t5
    muleu_s.ph.qbl    s2, a1, t6
    muleu_s.ph.qbr    s3, a1, t6
    muleu_s.ph.qbl    s4, a1, t7
    muleu_s.ph.qbr    s5, a1, t7
    muleu_s.ph.qbl    s6, a1, t8
    muleu_s.ph.qbr    s7, a1, t8

    shra_r.ph         t5, s0, 8
    shra_r.ph         t6, s1, 8
    shra_r.ph         t7, s2, 8
    shra_r.ph         t8, s3, 8
    and               t5, t5, t0
    and               t6, t6, t0
    and               t7, t7, t0
    and               t8, t8, t0
    addq.ph           s0, s0, t5
    addq.ph           s1, s1, t6
    addq.ph           s2, s2, t7
    addq.ph           s3, s3, t8
    shra_r.ph         s0, s0, 8
    shra_r.ph         s1, s1, 8
    shra_r.ph         s2, s2, 8
    shra_r.ph         s3, s3, 8
    shra_r.ph         t5, s4, 8
    shra_r.ph         t6, s5, 8
    shra_r.ph         t7, s6, 8
    shra_r.ph         t8, s7, 8
    and               t5, t5, t0
    and               t6, t6, t0
    and               t7, t7, t0
    and               t8, t8, t0
    addq.ph           s4, s4, t5
    addq.ph           s5, s5, t6
    addq.ph           s6, s6, t7
    addq.ph           s7, s7, t8
    shra_r.ph         s4, s4, 8
    shra_r.ph         s5, s5, 8
    shra_r.ph         s6, s6, 8
    shra_r.ph         s7, s7, 8

    precr.qb.ph       t5, s0, s1
    precr.qb.ph       t6, s2, s3
    precr.qb.ph       t7, s4, s5
    precr.qb.ph       t8, s6, s7
    addu_s.qb         t5, t1, t5
    addu_s.qb         t6, t2, t6
    addu_s.qb         t7, t3, t7
    addu_s.qb         t8, t4, t8

    sw                t5, 0(a0)
    sw                t6, 4(a0)
    sw                t7, 8(a0)
    sw                t8, 12(a0)
    b                 1b
     addiu            a0, a0, 16

2:
    beqz              a2, 4f
     nop
3:
    lw                t1, 0(a0)

    not               t2, t1
    srl               t2, t2, 24
    replv.ph          t2, t2

    muleu_s.ph.qbl    t4, a1, t2
    muleu_s.ph.qbr    t5, a1, t2
    shra_r.ph         t6, t4, 8
    shra_r.ph         t7, t5, 8

    and               t6,t6,t0
    and               t7,t7,t0

    addq.ph           t8, t4, t6
    addq.ph           t9, t5, t7

    shra_r.ph         t8, t8, 8
    shra_r.ph         t9, t9, 8

    precr.qb.ph       t9, t8, t9

    addu_s.qb         t9, t1, t9
    sw                t9, 0(a0)

    addiu             a2, a2, -1
    bnez              a2, 3b
     addiu            a0, a0, 4
4:
    RESTORE_REGS_FROM_STACK 20, s0, s1, s2, s3, s4, s5, s6, s7
5:
    j                 ra
     nop

END(pixman_composite_over_reverse_n_8888_asm_mips)

LEAF_MIPS_DSPR2(pixman_composite_in_n_8_asm_mips)
/*
 * a0 - dst  (a8)
 * a1 - src  (32bit constant)
 * a2 - w
 */

    li                t9, 0x00ff00ff
    beqz              a2, 3f
     nop
    srl               t7, a2, 2   /* t7 = how many multiples of 4 dst pixels */
    beqz              t7, 1f      /* branch if less than 4 src pixels */
     nop

    srl               t8, a1, 24
    replv.ph          t8, t8

0:
    beqz              t7, 1f
     addiu            t7, t7, -1
    lbu               t0, 0(a0)
    lbu               t1, 1(a0)
    lbu               t2, 2(a0)
    lbu               t3, 3(a0)

    precr_sra.ph.w    t1, t0, 0
    precr_sra.ph.w    t3, t2, 0
    precr.qb.ph       t0, t3, t1

    muleu_s.ph.qbl    t2, t0, t8
    muleu_s.ph.qbr    t3, t0, t8
    shra_r.ph         t4, t2, 8
    shra_r.ph         t5, t3, 8
    and               t4, t4, t9
    and               t5, t5, t9
    addq.ph           t2, t2, t4
    addq.ph           t3, t3, t5
    shra_r.ph         t2, t2, 8
    shra_r.ph         t3, t3, 8
    precr.qb.ph       t2, t2, t3

    sb                t2, 0(a0)
    srl               t2, t2, 8
    sb                t2, 1(a0)
    srl               t2, t2, 8
    sb                t2, 2(a0)
    srl               t2, t2, 8
    sb                t2, 3(a0)
    addiu             a2, a2, -4
    b                 0b
     addiu            a0, a0, 4

1:
    beqz              a2, 3f
     nop
    srl               t8, a1, 24
2:
    lbu               t0, 0(a0)

    mul               t2, t0, t8
    shra_r.ph         t3, t2, 8
    andi              t3, t3, 0x00ff
    addq.ph           t2, t2, t3
    shra_r.ph         t2, t2, 8

    sb                t2, 0(a0)
    addiu             a2, a2, -1
    bnez              a2, 2b
     addiu            a0, a0, 1

3:
    j                 ra
     nop

END(pixman_composite_in_n_8_asm_mips)

LEAF_MIPS_DSPR2(pixman_scaled_nearest_scanline_8888_8888_OVER_asm_mips)
/*
 * a0     - dst  (a8r8g8b8)
 * a1     - src  (a8r8g8b8)
 * a2     - w
 * a3     - vx
 * 16(sp) - unit_x
 */

    SAVE_REGS_ON_STACK 0, s0, s1, s2, s3
    lw       t8, 16(sp) /* t8 = unit_x */
    li       t6, 0x00ff00ff
    beqz     a2, 3f
     nop
    addiu    t1, a2, -1
    beqz     t1, 2f
     nop
1:
    sra      t0, a3, 16 /* t0 = vx >> 16 */
    sll      t0, t0, 2  /* t0 = t0 * 4 (a8r8g8b8) */
    addu     t0, a1, t0
    lw       t0, 0(t0)  /* t0 = source      (a8r8g8b8) */
    addu     a3, a3, t8 /* a3 = vx + unit_x */

    sra      t1, a3, 16 /* t0 = vx >> 16 */
    sll      t1, t1, 2  /* t0 = t0 * 4 (a8r8g8b8) */
    addu     t1, a1, t1
    lw       t1, 0(t1)  /* t1 = source      (a8r8g8b8) */
    addu     a3, a3, t8 /* a3 = vx + unit_x */

    lw       t2, 0(a0)  /* t2 = destination (a8r8g8b8) */
    lw       t3, 4(a0)  /* t3 = destination (a8r8g8b8) */

    OVER_2x8888_2x8888 t0, t1, t2, t3, t4, t5, t6, t7, t9, s0, s1, s2, s3

    sw       t4, 0(a0)
    sw       t5, 4(a0)
    addiu    a2, a2, -2
    addiu    t1, a2, -1
    bgtz     t1, 1b
     addiu   a0, a0, 8
2:
    beqz     a2, 3f
     nop
    sra      t0, a3, 16 /* t0 = vx >> 16 */
    sll      t0, t0, 2  /* t0 = t0 * 4 (a8r8g8b8) */
    addu     t0, a1, t0
    lw       t0, 0(t0)  /* t0 = source      (a8r8g8b8) */
    lw       t1, 0(a0)  /* t1 = destination (a8r8g8b8) */
    addu     a3, a3, t8 /* a3 = vx + unit_x */

    OVER_8888_8888 t0, t1, t2, t6, t4, t5, t3, t7

    sw       t2, 0(a0)
3:
    RESTORE_REGS_FROM_STACK 0, s0, s1, s2, s3
    j        ra
     nop

END(pixman_scaled_nearest_scanline_8888_8888_OVER_asm_mips)

LEAF_MIPS_DSPR2(pixman_scaled_nearest_scanline_8888_0565_OVER_asm_mips)
/*
 * a0     - dst  (r5g6b5)
 * a1     - src  (a8r8g8b8)
 * a2     - w
 * a3     - vx
 * 16(sp) - unit_x
 */

    SAVE_REGS_ON_STACK 24, s0, s1, s2, s3, s4, v0, v1
    lw       t8, 40(sp) /* t8 = unit_x */
    li       t4, 0x00ff00ff
    li       t5, 0xf800f800
    li       t6, 0x07e007e0
    li       t7, 0x001F001F
    beqz     a2, 3f
     nop
    addiu    t1, a2, -1
    beqz     t1, 2f
     nop
1:
    sra      t0, a3, 16 /* t0 = vx >> 16 */
    sll      t0, t0, 2  /* t0 = t0 * 4 (a8r8g8b8) */
    addu     t0, a1, t0
    lw       t0, 0(t0)  /* t0 = source      (a8r8g8b8) */
    addu     a3, a3, t8 /* a3 = vx + unit_x */
    sra      t1, a3, 16 /* t0 = vx >> 16 */
    sll      t1, t1, 2  /* t0 = t0 * 4 (a8r8g8b8) */
    addu     t1, a1, t1
    lw       t1, 0(t1)  /* t1 = source      (a8r8g8b8) */
    addu     a3, a3, t8 /* a3 = vx + unit_x */
    lhu      t2, 0(a0)  /* t2 = destination (r5g6b5) */
    lhu      t3, 2(a0)  /* t3 = destination (r5g6b5) */

    CONVERT_2x0565_TO_2x8888 t2, t3, v0, v1, t6, t7, s0, s1, s2, s3
    OVER_2x8888_2x8888       t0, t1, v0, v1, t2, t3, t4, t9, s0, s1, s2, s3, s4
    CONVERT_2x8888_TO_2x0565 t2, t3, v0, v1, t5, t6, t7, t9, s2

    sh       v0, 0(a0)
    sh       v1, 2(a0)
    addiu    a2, a2, -2
    addiu    t1, a2, -1
    bgtz     t1, 1b
     addiu   a0, a0, 4
2:
    beqz     a2, 3f
     nop
    sra      t0, a3, 16 /* t0 = vx >> 16 */
    sll      t0, t0, 2  /* t0 = t0 * 4 (a8r8g8b8) */
    addu     t0, a1, t0
    lw       t0, 0(t0)  /* t0 = source      (a8r8g8b8) */
    lhu      t1, 0(a0)  /* t1 = destination (r5g6b5) */
    addu     a3, a3, t8 /* a3 = vx + unit_x */

    CONVERT_1x0565_TO_1x8888 t1, t2, t5, t6
    OVER_8888_8888           t0, t2, t1, t4, t3, t5, t6, t7
    CONVERT_1x8888_TO_1x0565 t1, t2, t5, t6

    sh       t2, 0(a0)
3:
    RESTORE_REGS_FROM_STACK 24, s0, s1, s2, s3, s4, v0, v1
    j        ra
     nop

END(pixman_scaled_nearest_scanline_8888_0565_OVER_asm_mips)

LEAF_MIPS_DSPR2(pixman_scaled_nearest_scanline_0565_8888_SRC_asm_mips)
/*
 * a0     - dst (a8r8g8b8)
 * a1     - src (r5g6b5)
 * a2     - w
 * a3     - vx
 * 16(sp) - unit_x
 */

    SAVE_REGS_ON_STACK 0, v0
    beqz     a2, 3f
     nop

    lw       v0, 16(sp) /* v0 = unit_x */
    addiu    t1, a2, -1
    beqz     t1, 2f
     nop

    li       t4, 0x07e007e0
    li       t5, 0x001F001F
1:
    sra      t0, a3, 16 /* t0 = vx >> 16 */
    sll      t0, t0, 1  /* t0 = t0 * 2 ((r5g6b5)) */
    addu     t0, a1, t0
    lhu      t0, 0(t0)  /* t0 = source ((r5g6b5)) */
    addu     a3, a3, v0 /* a3 = vx + unit_x */
    sra      t1, a3, 16 /* t1 = vx >> 16 */
    sll      t1, t1, 1  /* t1 = t1 * 2 ((r5g6b5)) */
    addu     t1, a1, t1
    lhu      t1, 0(t1)  /* t1 = source ((r5g6b5)) */
    addu     a3, a3, v0 /* a3 = vx + unit_x */
    addiu    a2, a2, -2

    CONVERT_2x0565_TO_2x8888 t0, t1, t2, t3, t4, t5, t6, t7, t8, t9

    sw       t2, 0(a0)
    sw       t3, 4(a0)

    addiu    t2, a2, -1
    bgtz     t2, 1b
     addiu   a0, a0, 8
2:
    beqz     a2, 3f
     nop
    sra      t0, a3, 16 /* t0 = vx >> 16 */
    sll      t0, t0, 1  /* t0 = t0 * 2 ((r5g6b5)) */
    addu     t0, a1, t0
    lhu      t0, 0(t0)  /* t0 = source ((r5g6b5)) */

    CONVERT_1x0565_TO_1x8888 t0, t1, t2, t3

    sw       t1, 0(a0)
3:
    RESTORE_REGS_FROM_STACK 0, v0
    j        ra
     nop

END(pixman_scaled_nearest_scanline_0565_8888_SRC_asm_mips)

LEAF_MIPS_DSPR2(pixman_scaled_nearest_scanline_8888_8_0565_OVER_asm_mips)
/*
 * a0     - dst  (r5g6b5)
 * a1     - src  (a8r8g8b8)
 * a2     - mask (a8)
 * a3     - w
 * 16(sp) - vx
 * 20(sp) - unit_x
 */
    beqz     a3, 4f
     nop

    SAVE_REGS_ON_STACK 20, v0, v1, s0, s1, s2, s3, s4, s5
    lw       v0, 36(sp) /* v0 = vx */
    lw       v1, 40(sp) /* v1 = unit_x */
    li       t6, 0x00ff00ff
    li       t7, 0xf800f800
    li       t8, 0x07e007e0
    li       t9, 0x001F001F

    addiu    t1, a3, -1
    beqz     t1, 2f
     nop
1:
    sra      t0, v0, 16 /* t0 = vx >> 16 */
    sll      t0, t0, 2  /* t0 = t0 * 4      (a8r8g8b8) */
    addu     t0, a1, t0
    lw       t0, 0(t0)  /* t0 = source      (a8r8g8b8) */
    addu     v0, v0, v1 /* v0 = vx + unit_x */
    sra      t1, v0, 16 /* t1 = vx >> 16 */
    sll      t1, t1, 2  /* t1 = t1 * 4      (a8r8g8b8) */
    addu     t1, a1, t1
    lw       t1, 0(t1)  /* t1 = source      (a8r8g8b8) */
    addu     v0, v0, v1 /* v0 = vx + unit_x */
    lbu      t2, 0(a2)  /* t2 = mask        (a8) */
    lbu      t3, 1(a2)  /* t3 = mask        (a8) */
    lhu      t4, 0(a0)  /* t4 = destination (r5g6b5) */
    lhu      t5, 2(a0)  /* t5 = destination (r5g6b5) */
    addiu    a2, a2, 2

    CONVERT_2x0565_TO_2x8888 t4, t5, s0, s1, t8, t9, s2, s3, s4, s5
    OVER_2x8888_2x8_2x8888   t0, t1, \
                             t2, t3, \
                             s0, s1, \
                             t4, t5, \
                             t6, s2, s3, s4, s5, t2, t3
    CONVERT_2x8888_TO_2x0565 t4, t5, s0, s1, t7, t8, t9, s2, s3

    sh       s0, 0(a0)
    sh       s1, 2(a0)
    addiu    a3, a3, -2
    addiu    t1, a3, -1
    bgtz     t1, 1b
     addiu   a0, a0, 4
2:
    beqz     a3, 3f
     nop
    sra      t0, v0, 16 /* t0 = vx >> 16 */
    sll      t0, t0, 2  /* t0 = t0 * 4      (a8r8g8b8) */
    addu     t0, a1, t0
    lw       t0, 0(t0)  /* t0 = source      (a8r8g8b8) */
    lbu      t1, 0(a2)  /* t1 = mask        (a8) */
    lhu      t2, 0(a0)  /* t2 = destination (r5g6b5) */

    CONVERT_1x0565_TO_1x8888 t2, t3, t4, t5
    OVER_8888_8_8888         t0, t1, t3, t2, t6, t4, t5, t7, t8
    CONVERT_1x8888_TO_1x0565 t2, t3, t4, t5

    sh       t3, 0(a0)
3:
    RESTORE_REGS_FROM_STACK 20, v0, v1, s0, s1, s2, s3, s4, s5
4:
    j        ra
     nop

END(pixman_scaled_nearest_scanline_8888_8_0565_OVER_asm_mips)

LEAF_MIPS_DSPR2(pixman_scaled_nearest_scanline_0565_8_0565_OVER_asm_mips)
/*
 * a0     - dst  (r5g6b5)
 * a1     - src  (r5g6b5)
 * a2     - mask (a8)
 * a3     - w
 * 16(sp) - vx
 * 20(sp) - unit_x
 */

    beqz     a3, 4f
     nop
    SAVE_REGS_ON_STACK 20, v0, v1, s0, s1, s2, s3, s4, s5
    lw       v0, 36(sp) /* v0 = vx */
    lw       v1, 40(sp) /* v1 = unit_x */
    li       t4, 0xf800f800
    li       t5, 0x07e007e0
    li       t6, 0x001F001F
    li       t7, 0x00ff00ff

    addiu    t1, a3, -1
    beqz     t1, 2f
     nop
1:
    sra      t0, v0, 16 /* t0 = vx >> 16 */
    sll      t0, t0, 1  /* t0 = t0 * 2      (r5g6b5) */
    addu     t0, a1, t0
    lhu      t0, 0(t0)  /* t0 = source      (r5g6b5) */
    addu     v0, v0, v1 /* v0 = vx + unit_x */
    sra      t1, v0, 16 /* t1 = vx >> 16 */
    sll      t1, t1, 1  /* t1 = t1 * 2      (r5g6b5) */
    addu     t1, a1, t1
    lhu      t1, 0(t1)  /* t1 = source      (r5g6b5) */
    addu     v0, v0, v1 /* v0 = vx + unit_x */
    lbu      t2, 0(a2)  /* t2 = mask        (a8) */
    lbu      t3, 1(a2)  /* t3 = mask        (a8) */
    lhu      t8, 0(a0)  /* t8 = destination (r5g6b5) */
    lhu      t9, 2(a0)  /* t9 = destination (r5g6b5) */
    addiu    a2, a2, 2

    CONVERT_2x0565_TO_2x8888 t0, t1, s0, s1, t5, t6, s2, s3, s4, s5
    CONVERT_2x0565_TO_2x8888 t8, t9, s2, s3, t5, t6, s4, s5, t0, t1
    OVER_2x8888_2x8_2x8888   s0, s1, \
                             t2, t3, \
                             s2, s3, \
                             t0, t1, \
                             t7, t8, t9, s4, s5, s0, s1
    CONVERT_2x8888_TO_2x0565 t0, t1, s0, s1, t4, t5, t6, s2, s3

    sh       s0, 0(a0)
    sh       s1, 2(a0)
    addiu    a3, a3, -2
    addiu    t1, a3, -1
    bgtz     t1, 1b
     addiu   a0, a0, 4
2:
    beqz     a3, 3f
     nop
    sra      t0, v0, 16 /* t0 = vx >> 16 */
    sll      t0, t0, 1  /* t0 = t0 * 2      (r5g6b5) */
    addu     t0, a1, t0

    lhu      t0, 0(t0)  /* t0 = source      (r5g6b5) */
    lbu      t1, 0(a2)  /* t1 = mask        (a8) */
    lhu      t2, 0(a0)  /* t2 = destination (r5g6b5) */

    CONVERT_1x0565_TO_1x8888 t0, t3, t4, t5
    CONVERT_1x0565_TO_1x8888 t2, t4, t5, t6
    OVER_8888_8_8888         t3, t1, t4, t0, t7, t2, t5, t6, t8
    CONVERT_1x8888_TO_1x0565 t0, t3, t4, t5

    sh       t3, 0(a0)
3:
    RESTORE_REGS_FROM_STACK 20, v0, v1, s0, s1, s2, s3, s4, s5
4:
    j        ra
     nop

END(pixman_scaled_nearest_scanline_0565_8_0565_OVER_asm_mips)

LEAF_MIPS_DSPR2(pixman_scaled_bilinear_scanline_8888_8888_SRC_asm_mips)
/*
 * a0     - *dst
 * a1     - *src_top
 * a2     - *src_bottom
 * a3     - w
 * 16(sp) - wt
 * 20(sp) - wb
 * 24(sp) - vx
 * 28(sp) - unit_x
 */

    beqz     a3, 1f
     nop

    SAVE_REGS_ON_STACK 20, v0, s0, s1, s2, s3, s4, s5, s6, s7

    lw       s0, 36(sp)     /* s0 = wt */
    lw       s1, 40(sp)     /* s1 = wb */
    lw       s2, 44(sp)     /* s2 = vx */
    lw       s3, 48(sp)     /* s3 = unit_x */
    li       v0, BILINEAR_INTERPOLATION_RANGE

    sll      s0, s0, (2 * (8 - BILINEAR_INTERPOLATION_BITS))
    sll      s1, s1, (2 * (8 - BILINEAR_INTERPOLATION_BITS))
0:
    andi     t4, s2, 0xffff /* t4 = (short)vx */
    srl      t4, t4, (16 - BILINEAR_INTERPOLATION_BITS) /* t4 = vx >> 8 */
    subu     t5, v0, t4     /* t5 = ( 256 - (vx>>8)) */

    mul      s4, s0, t5     /* s4 = wt*(256-(vx>>8)) */
    mul      s5, s0, t4     /* s5 = wt*(vx>>8) */
    mul      s6, s1, t5     /* s6 = wb*(256-(vx>>8)) */
    mul      s7, s1, t4     /* s7 = wb*(vx>>8) */

    sra      t9, s2, 16
    sll      t9, t9, 2
    addiu    t8, t9, 4
    lwx      t0, t9(a1)     /* t0 = tl */
    lwx      t1, t8(a1)     /* t1 = tr */
    addiu    a3, a3, -1
    lwx      t2, t9(a2)     /* t2 = bl */
    lwx      t3, t8(a2)     /* t3 = br */

    BILINEAR_INTERPOLATE_SINGLE_PIXEL t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, s4, s5, s6, s7

    addu     s2, s2, s3     /* vx += unit_x; */
    sw       t0, 0(a0)
    bnez     a3, 0b
     addiu   a0, a0, 4

    RESTORE_REGS_FROM_STACK 20, v0, s0, s1, s2, s3, s4, s5, s6, s7
1:
    j        ra
     nop

END(pixman_scaled_bilinear_scanline_8888_8888_SRC_asm_mips)

LEAF_MIPS_DSPR2(pixman_scaled_bilinear_scanline_8888_0565_SRC_asm_mips)
/*
 * a0     - *dst
 * a1     - *src_top
 * a2     - *src_bottom
 * a3     - w
 * 16(sp) - wt
 * 20(sp) - wb
 * 24(sp) - vx
 * 28(sp) - unit_x
 */

    beqz     a3, 1f
     nop

    SAVE_REGS_ON_STACK 20, v0, s0, s1, s2, s3, s4, s5, s6, s7

    lw       s0, 36(sp)     /* s0 = wt */
    lw       s1, 40(sp)     /* s1 = wb */
    lw       s2, 44(sp)     /* s2 = vx */
    lw       s3, 48(sp)     /* s3 = unit_x */
    li       v0, BILINEAR_INTERPOLATION_RANGE

    sll      s0, s0, (2 * (8 - BILINEAR_INTERPOLATION_BITS))
    sll      s1, s1, (2 * (8 - BILINEAR_INTERPOLATION_BITS))
0:
    andi     t4, s2, 0xffff /* t4 = (short)vx */
    srl      t4, t4, (16 - BILINEAR_INTERPOLATION_BITS) /* t4 = vx >> 8 */
    subu     t5, v0, t4     /* t5 = ( 256 - (vx>>8)) */

    mul      s4, s0, t5     /* s4 = wt*(256-(vx>>8)) */
    mul      s5, s0, t4     /* s5 = wt*(vx>>8) */
    mul      s6, s1, t5     /* s6 = wb*(256-(vx>>8)) */
    mul      s7, s1, t4     /* s7 = wb*(vx>>8) */

    sra      t9, s2, 16
    sll      t9, t9, 2
    addiu    t8, t9, 4
    lwx      t0, t9(a1)     /* t0 = tl */
    lwx      t1, t8(a1)     /* t1 = tr */
    addiu    a3, a3, -1
    lwx      t2, t9(a2)     /* t2 = bl */
    lwx      t3, t8(a2)     /* t3 = br */

    BILINEAR_INTERPOLATE_SINGLE_PIXEL t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, s4, s5, s6, s7
    CONVERT_1x8888_TO_1x0565 t0, t1, t2, t3

    addu     s2, s2, s3     /* vx += unit_x; */
    sh       t1, 0(a0)
    bnez     a3, 0b
     addiu   a0, a0, 2

    RESTORE_REGS_FROM_STACK 20, v0, s0, s1, s2, s3, s4, s5, s6, s7
1:
    j        ra
     nop

END(pixman_scaled_bilinear_scanline_8888_0565_SRC_asm_mips)

LEAF_MIPS_DSPR2(pixman_scaled_bilinear_scanline_0565_8888_SRC_asm_mips)
/*
 * a0     - *dst
 * a1     - *src_top
 * a2     - *src_bottom
 * a3     - w
 * 16(sp) - wt
 * 20(sp) - wb
 * 24(sp) - vx
 * 28(sp) - unit_x
 */

    beqz     a3, 1f
     nop

    SAVE_REGS_ON_STACK 28, v0, v1, s0, s1, s2, s3, s4, s5, s6, s7, s8

    lw       s0, 44(sp)     /* s0 = wt */
    lw       s1, 48(sp)     /* s1 = wb */
    lw       s2, 52(sp)     /* s2 = vx */
    lw       s3, 56(sp)     /* s3 = unit_x */
    li       v0, BILINEAR_INTERPOLATION_RANGE
    li       v1, 0x07e007e0
    li       s8, 0x001f001f

    sll      s0, s0, (2 * (8 - BILINEAR_INTERPOLATION_BITS))
    sll      s1, s1, (2 * (8 - BILINEAR_INTERPOLATION_BITS))
0:
    andi     t4, s2, 0xffff /* t4 = (short)vx */
    srl      t4, t4, (16 - BILINEAR_INTERPOLATION_BITS) /* t4 = vx >> 8 */
    subu     t5, v0, t4     /* t5 = ( 256 - (vx>>8)) */

    mul      s4, s0, t5     /* s4 = wt*(256-(vx>>8)) */
    mul      s5, s0, t4     /* s5 = wt*(vx>>8) */
    mul      s6, s1, t5     /* s6 = wb*(256-(vx>>8)) */
    mul      s7, s1, t4     /* s7 = wb*(vx>>8) */

    sra      t9, s2, 16
    sll      t9, t9, 1
    addiu    t8, t9, 2
    lhx      t0, t9(a1)     /* t0 = tl */
    lhx      t1, t8(a1)     /* t1 = tr */
    andi     t1, t1, 0xffff
    addiu    a3, a3, -1
    lhx      t2, t9(a2)     /* t2 = bl */
    lhx      t3, t8(a2)     /* t3 = br */
    andi     t3, t3, 0xffff

    CONVERT_2x0565_TO_2x8888 t0, t1, t0, t1, v1, s8, t4, t5, t6, t7
    CONVERT_2x0565_TO_2x8888 t2, t3, t2, t3, v1, s8, t4, t5, t6, t7
    BILINEAR_INTERPOLATE_SINGLE_PIXEL t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, s4, s5, s6, s7

    addu     s2, s2, s3     /* vx += unit_x; */
    sw       t0, 0(a0)
    bnez     a3, 0b
     addiu   a0, a0, 4

    RESTORE_REGS_FROM_STACK 28, v0, v1, s0, s1, s2, s3, s4, s5, s6, s7, s8
1:
    j        ra
     nop

END(pixman_scaled_bilinear_scanline_0565_8888_SRC_asm_mips)

LEAF_MIPS_DSPR2(pixman_scaled_bilinear_scanline_0565_0565_SRC_asm_mips)
/*
 * a0     - *dst
 * a1     - *src_top
 * a2     - *src_bottom
 * a3     - w
 * 16(sp) - wt
 * 20(sp) - wb
 * 24(sp) - vx
 * 28(sp) - unit_x
 */

    beqz     a3, 1f
     nop

    SAVE_REGS_ON_STACK 28, v0, v1, s0, s1, s2, s3, s4, s5, s6, s7, s8

    lw       s0, 44(sp)     /* s0 = wt */
    lw       s1, 48(sp)     /* s1 = wb */
    lw       s2, 52(sp)     /* s2 = vx */
    lw       s3, 56(sp)     /* s3 = unit_x */
    li       v0, BILINEAR_INTERPOLATION_RANGE
    li       v1, 0x07e007e0
    li       s8, 0x001f001f

    sll      s0, s0, (2 * (8 - BILINEAR_INTERPOLATION_BITS))
    sll      s1, s1, (2 * (8 - BILINEAR_INTERPOLATION_BITS))
0:
    andi     t4, s2, 0xffff /* t4 = (short)vx */
    srl      t4, t4, (16 - BILINEAR_INTERPOLATION_BITS) /* t4 = vx >> 8 */
    subu     t5, v0, t4     /* t5 = ( 256 - (vx>>8)) */

    mul      s4, s0, t5     /* s4 = wt*(256-(vx>>8)) */
    mul      s5, s0, t4     /* s5 = wt*(vx>>8) */
    mul      s6, s1, t5     /* s6 = wb*(256-(vx>>8)) */
    mul      s7, s1, t4     /* s7 = wb*(vx>>8) */

    sra      t9, s2, 16
    sll      t9, t9, 1
    addiu    t8, t9, 2
    lhx      t0, t9(a1)     /* t0 = tl */
    lhx      t1, t8(a1)     /* t1 = tr */
    andi     t1, t1, 0xffff
    addiu    a3, a3, -1
    lhx      t2, t9(a2)     /* t2 = bl */
    lhx      t3, t8(a2)     /* t3 = br */
    andi     t3, t3, 0xffff

    CONVERT_2x0565_TO_2x8888 t0, t1, t0, t1, v1, s8, t4, t5, t6, t7
    CONVERT_2x0565_TO_2x8888 t2, t3, t2, t3, v1, s8, t4, t5, t6, t7
    BILINEAR_INTERPOLATE_SINGLE_PIXEL t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, s4, s5, s6, s7
    CONVERT_1x8888_TO_1x0565 t0, t1, t2, t3

    addu     s2, s2, s3     /* vx += unit_x; */
    sh       t1, 0(a0)
    bnez     a3, 0b
     addiu   a0, a0, 2

    RESTORE_REGS_FROM_STACK 28, v0, v1, s0, s1, s2, s3, s4, s5, s6, s7, s8
1:
    j        ra
     nop

END(pixman_scaled_bilinear_scanline_0565_0565_SRC_asm_mips)

LEAF_MIPS_DSPR2(pixman_scaled_bilinear_scanline_8888_8888_OVER_asm_mips)
/*
 * a0     - *dst
 * a1     - *src_top
 * a2     - *src_bottom
 * a3     - w
 * 16(sp) - wt
 * 20(sp) - wb
 * 24(sp) - vx
 * 28(sp) - unit_x
 */

    beqz     a3, 1f
     nop

    SAVE_REGS_ON_STACK 24, v0, s0, s1, s2, s3, s4, s5, s6, s7, s8

    lw       s0, 40(sp)     /* s0 = wt */
    lw       s1, 44(sp)     /* s1 = wb */
    lw       s2, 48(sp)     /* s2 = vx */
    lw       s3, 52(sp)     /* s3 = unit_x */
    li       v0, BILINEAR_INTERPOLATION_RANGE
    li       s8, 0x00ff00ff

    sll      s0, s0, (2 * (8 - BILINEAR_INTERPOLATION_BITS))
    sll      s1, s1, (2 * (8 - BILINEAR_INTERPOLATION_BITS))
0:
    andi     t4, s2, 0xffff /* t4 = (short)vx */
    srl      t4, t4, (16 - BILINEAR_INTERPOLATION_BITS) /* t4 = vx >> 8 */
    subu     t5, v0, t4     /* t5 = ( 256 - (vx>>8)) */

    mul      s4, s0, t5     /* s4 = wt*(256-(vx>>8)) */
    mul      s5, s0, t4     /* s5 = wt*(vx>>8) */
    mul      s6, s1, t5     /* s6 = wb*(256-(vx>>8)) */
    mul      s7, s1, t4     /* s7 = wb*(vx>>8) */

    sra      t9, s2, 16
    sll      t9, t9, 2
    addiu    t8, t9, 4
    lwx      t0, t9(a1)     /* t0 = tl */
    lwx      t1, t8(a1)     /* t1 = tr */
    addiu    a3, a3, -1
    lwx      t2, t9(a2)     /* t2 = bl */
    lwx      t3, t8(a2)     /* t3 = br */

    BILINEAR_INTERPOLATE_SINGLE_PIXEL t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, s4, s5, s6, s7
    lw       t1, 0(a0)      /* t1 = dest */
    OVER_8888_8888 t0, t1, t2, s8, t3, t4, t5, t6

    addu     s2, s2, s3     /* vx += unit_x; */
    sw       t2, 0(a0)
    bnez     a3, 0b
     addiu   a0, a0, 4

    RESTORE_REGS_FROM_STACK 24, v0, s0, s1, s2, s3, s4, s5, s6, s7, s8
1:
    j        ra
     nop

END(pixman_scaled_bilinear_scanline_8888_8888_OVER_asm_mips)

LEAF_MIPS_DSPR2(pixman_scaled_bilinear_scanline_8888_8888_ADD_asm_mips)
/*
 * a0     - *dst
 * a1     - *src_top
 * a2     - *src_bottom
 * a3     - w
 * 16(sp) - wt
 * 20(sp) - wb
 * 24(sp) - vx
 * 28(sp) - unit_x
 */

    beqz         a3, 1f
     nop

    SAVE_REGS_ON_STACK 20, v0, s0, s1, s2, s3, s4, s5, s6, s7

    lw           s0, 36(sp)     /* s0 = wt */
    lw           s1, 40(sp)     /* s1 = wb */
    lw           s2, 44(sp)     /* s2 = vx */
    lw           s3, 48(sp)     /* s3 = unit_x */
    li           v0, BILINEAR_INTERPOLATION_RANGE

    sll          s0, s0, (2 * (8 - BILINEAR_INTERPOLATION_BITS))
    sll          s1, s1, (2 * (8 - BILINEAR_INTERPOLATION_BITS))
0:
    andi         t4, s2, 0xffff /* t4 = (short)vx */
    srl          t4, t4, (16 - BILINEAR_INTERPOLATION_BITS) /* t4 = vx >> 8 */
    subu         t5, v0, t4     /* t5 = ( 256 - (vx>>8)) */

    mul          s4, s0, t5     /* s4 = wt*(256-(vx>>8)) */
    mul          s5, s0, t4     /* s5 = wt*(vx>>8) */
    mul          s6, s1, t5     /* s6 = wb*(256-(vx>>8)) */
    mul          s7, s1, t4     /* s7 = wb*(vx>>8) */

    sra          t9, s2, 16
    sll          t9, t9, 2
    addiu        t8, t9, 4
    lwx          t0, t9(a1)     /* t0 = tl */
    lwx          t1, t8(a1)     /* t1 = tr */
    addiu        a3, a3, -1
    lwx          t2, t9(a2)     /* t2 = bl */
    lwx          t3, t8(a2)     /* t3 = br */

    BILINEAR_INTERPOLATE_SINGLE_PIXEL t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, s4, s5, s6, s7
    lw           t1, 0(a0)
    addu_s.qb    t2, t0, t1

    addu         s2, s2, s3     /* vx += unit_x; */
    sw           t2, 0(a0)
    bnez         a3, 0b
     addiu       a0, a0, 4

    RESTORE_REGS_FROM_STACK 20, v0, s0, s1, s2, s3, s4, s5, s6, s7
1:
    j            ra
     nop

END(pixman_scaled_bilinear_scanline_8888_8888_ADD_asm_mips)

LEAF_MIPS_DSPR2(pixman_scaled_bilinear_scanline_8888_8_8888_SRC_asm_mips)
/*
 * a0     - *dst
 * a1     - *mask
 * a2     - *src_top
 * a3     - *src_bottom
 * 16(sp) - wt
 * 20(sp) - wb
 * 24(sp) - vx
 * 28(sp) - unit_x
 * 32(sp) - w
 */

    lw       v1, 32(sp)
    beqz     v1, 1f
     nop

    SAVE_REGS_ON_STACK 28, v0, v1, s0, s1, s2, s3, s4, s5, s6, s7, s8

    lw       s0, 44(sp)        /* s0 = wt */
    lw       s1, 48(sp)        /* s1 = wb */
    lw       s2, 52(sp)        /* s2 = vx */
    lw       s3, 56(sp)        /* s3 = unit_x */
    li       v0, BILINEAR_INTERPOLATION_RANGE
    li       s8, 0x00ff00ff

    sll      s0, s0, (2 * (8 - BILINEAR_INTERPOLATION_BITS))
    sll      s1, s1, (2 * (8 - BILINEAR_INTERPOLATION_BITS))
0:
    andi     t4, s2, 0xffff    /* t4 = (short)vx */
    srl      t4, t4, (16 - BILINEAR_INTERPOLATION_BITS) /* t4 = vx >> 8 */
    subu     t5, v0, t4        /* t5 = ( 256 - (vx>>8)) */

    mul      s4, s0, t5        /* s4 = wt*(256-(vx>>8)) */
    mul      s5, s0, t4        /* s5 = wt*(vx>>8) */
    mul      s6, s1, t5        /* s6 = wb*(256-(vx>>8)) */
    mul      s7, s1, t4        /* s7 = wb*(vx>>8) */

    sra      t9, s2, 16
    sll      t9, t9, 2
    addiu    t8, t9, 4
    lwx      t0, t9(a2)        /* t0 = tl */
    lwx      t1, t8(a2)        /* t1 = tr */
    addiu    v1, v1, -1
    lwx      t2, t9(a3)        /* t2 = bl */
    lwx      t3, t8(a3)        /* t3 = br */

    BILINEAR_INTERPOLATE_SINGLE_PIXEL t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, s4, s5, s6, s7
    lbu      t1, 0(a1)         /* t1 = mask */
    addiu    a1, a1, 1
    MIPS_UN8x4_MUL_UN8 t0, t1, t0, s8, t2, t3, t4

    addu     s2, s2, s3        /* vx += unit_x; */
    sw       t0, 0(a0)
    bnez     v1, 0b
     addiu   a0, a0, 4

    RESTORE_REGS_FROM_STACK 28, v0, v1, s0, s1, s2, s3, s4, s5, s6, s7, s8
1:
    j        ra
     nop

END(pixman_scaled_bilinear_scanline_8888_8_8888_SRC_asm_mips)

LEAF_MIPS_DSPR2(pixman_scaled_bilinear_scanline_8888_8_0565_SRC_asm_mips)
/*
 * a0     - *dst
 * a1     - *mask
 * a2     - *src_top
 * a3     - *src_bottom
 * 16(sp) - wt
 * 20(sp) - wb
 * 24(sp) - vx
 * 28(sp) - unit_x
 * 32(sp) - w
 */

    lw       v1, 32(sp)
    beqz     v1, 1f
     nop

    SAVE_REGS_ON_STACK 28, v0, v1, s0, s1, s2, s3, s4, s5, s6, s7, s8

    lw       s0, 44(sp)        /* s0 = wt */
    lw       s1, 48(sp)        /* s1 = wb */
    lw       s2, 52(sp)        /* s2 = vx */
    lw       s3, 56(sp)        /* s3 = unit_x */
    li       v0, BILINEAR_INTERPOLATION_RANGE
    li       s8, 0x00ff00ff

    sll      s0, s0, (2 * (8 - BILINEAR_INTERPOLATION_BITS))
    sll      s1, s1, (2 * (8 - BILINEAR_INTERPOLATION_BITS))
0:
    andi     t4, s2, 0xffff    /* t4 = (short)vx */
    srl      t4, t4, (16 - BILINEAR_INTERPOLATION_BITS) /* t4 = vx >> 8 */
    subu     t5, v0, t4        /* t5 = ( 256 - (vx>>8)) */

    mul      s4, s0, t5        /* s4 = wt*(256-(vx>>8)) */
    mul      s5, s0, t4        /* s5 = wt*(vx>>8) */
    mul      s6, s1, t5        /* s6 = wb*(256-(vx>>8)) */
    mul      s7, s1, t4        /* s7 = wb*(vx>>8) */

    sra      t9, s2, 16
    sll      t9, t9, 2
    addiu    t8, t9, 4
    lwx      t0, t9(a2)        /* t0 = tl */
    lwx      t1, t8(a2)        /* t1 = tr */
    addiu    v1, v1, -1
    lwx      t2, t9(a3)        /* t2 = bl */
    lwx      t3, t8(a3)        /* t3 = br */

    BILINEAR_INTERPOLATE_SINGLE_PIXEL t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, s4, s5, s6, s7
    lbu      t1, 0(a1)         /* t1 = mask */
    addiu    a1, a1, 1
    MIPS_UN8x4_MUL_UN8 t0, t1, t0, s8, t2, t3, t4
    CONVERT_1x8888_TO_1x0565 t0, t1, t2, t3

    addu     s2, s2, s3        /* vx += unit_x; */
    sh       t1, 0(a0)
    bnez     v1, 0b
     addiu   a0, a0, 2

    RESTORE_REGS_FROM_STACK 28, v0, v1, s0, s1, s2, s3, s4, s5, s6, s7, s8
1:
    j        ra
     nop

END(pixman_scaled_bilinear_scanline_8888_8_0565_SRC_asm_mips)

LEAF_MIPS_DSPR2(pixman_scaled_bilinear_scanline_0565_8_x888_SRC_asm_mips)
/*
 * a0     - *dst
 * a1     - *mask
 * a2     - *src_top
 * a3     - *src_bottom
 * 16(sp) - wt
 * 20(sp) - wb
 * 24(sp) - vx
 * 28(sp) - unit_x
 * 32(sp) - w
 */

    lw       t0, 32(sp)
    beqz     t0, 1f
     nop

    SAVE_REGS_ON_STACK 32, v0, v1, s0, s1, s2, s3, s4, s5, s6, s7, s8, ra

    lw       s0, 48(sp)        /* s0 = wt */
    lw       s1, 52(sp)        /* s1 = wb */
    lw       s2, 56(sp)        /* s2 = vx */
    lw       s3, 60(sp)        /* s3 = unit_x */
    lw       ra, 64(sp)        /* ra = w */
    li       v0, 0x00ff00ff
    li       v1, 0x07e007e0
    li       s8, 0x001f001f

    sll      s0, s0, (2 * (8 - BILINEAR_INTERPOLATION_BITS))
    sll      s1, s1, (2 * (8 - BILINEAR_INTERPOLATION_BITS))
0:
    andi     t4, s2, 0xffff    /* t4 = (short)vx */
    srl      t4, t4, (16 - BILINEAR_INTERPOLATION_BITS) /* t4 = vx >> 8 */
    li       t5, BILINEAR_INTERPOLATION_RANGE
    subu     t5, t5, t4        /* t5 = ( 256 - (vx>>8)) */

    mul      s4, s0, t5        /* s4 = wt*(256-(vx>>8)) */
    mul      s5, s0, t4        /* s5 = wt*(vx>>8) */
    mul      s6, s1, t5        /* s6 = wb*(256-(vx>>8)) */
    mul      s7, s1, t4        /* s7 = wb*(vx>>8) */

    sra      t9, s2, 16
    sll      t9, t9, 1
    addiu    t8, t9, 2
    lhx      t0, t9(a2)        /* t0 = tl */
    lhx      t1, t8(a2)        /* t1 = tr */
    andi     t1, t1, 0xffff
    addiu    ra, ra, -1
    lhx      t2, t9(a3)        /* t2 = bl */
    lhx      t3, t8(a3)        /* t3 = br */
    andi     t3, t3, 0xffff

    CONVERT_2x0565_TO_2x8888 t0, t1, t0, t1, v1, s8, t4, t5, t6, t7
    CONVERT_2x0565_TO_2x8888 t2, t3, t2, t3, v1, s8, t4, t5, t6, t7
    BILINEAR_INTERPOLATE_SINGLE_PIXEL t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, s4, s5, s6, s7
    lbu      t1, 0(a1)         /* t1 = mask */
    addiu    a1, a1, 1
    MIPS_UN8x4_MUL_UN8 t0, t1, t0, v0, t2, t3, t4

    addu     s2, s2, s3        /* vx += unit_x; */
    sw       t0, 0(a0)
    bnez     ra, 0b
     addiu   a0, a0, 4

    RESTORE_REGS_FROM_STACK 32, v0, v1, s0, s1, s2, s3, s4, s5, s6, s7, s8, ra
1:
    j        ra
     nop

END(pixman_scaled_bilinear_scanline_0565_8_x888_SRC_asm_mips)

LEAF_MIPS_DSPR2(pixman_scaled_bilinear_scanline_0565_8_0565_SRC_asm_mips)
/*
 * a0     - *dst
 * a1     - *mask
 * a2     - *src_top
 * a3     - *src_bottom
 * 16(sp) - wt
 * 20(sp) - wb
 * 24(sp) - vx
 * 28(sp) - unit_x
 * 32(sp) - w
 */

    lw       t0, 32(sp)
    beqz     t0, 1f
     nop

    SAVE_REGS_ON_STACK 32, v0, v1, s0, s1, s2, s3, s4, s5, s6, s7, s8, ra

    lw       s0, 48(sp)        /* s0 = wt */
    lw       s1, 52(sp)        /* s1 = wb */
    lw       s2, 56(sp)        /* s2 = vx */
    lw       s3, 60(sp)        /* s3 = unit_x */
    lw       ra, 64(sp)        /* ra = w */
    li       v0, 0x00ff00ff
    li       v1, 0x07e007e0
    li       s8, 0x001f001f

    sll      s0, s0, (2 * (8 - BILINEAR_INTERPOLATION_BITS))
    sll      s1, s1, (2 * (8 - BILINEAR_INTERPOLATION_BITS))
0:
    andi     t4, s2, 0xffff    /* t4 = (short)vx */
    srl      t4, t4, (16 - BILINEAR_INTERPOLATION_BITS) /* t4 = vx >> 8 */
    li       t5, BILINEAR_INTERPOLATION_RANGE
    subu     t5, t5, t4        /* t5 = ( 256 - (vx>>8)) */

    mul      s4, s0, t5        /* s4 = wt*(256-(vx>>8)) */
    mul      s5, s0, t4        /* s5 = wt*(vx>>8) */
    mul      s6, s1, t5        /* s6 = wb*(256-(vx>>8)) */
    mul      s7, s1, t4        /* s7 = wb*(vx>>8) */

    sra      t9, s2, 16
    sll      t9, t9, 1
    addiu    t8, t9, 2
    lhx      t0, t9(a2)        /* t0 = tl */
    lhx      t1, t8(a2)        /* t1 = tr */
    andi     t1, t1, 0xffff
    addiu    ra, ra, -1
    lhx      t2, t9(a3)        /* t2 = bl */
    lhx      t3, t8(a3)        /* t3 = br */
    andi     t3, t3, 0xffff

    CONVERT_2x0565_TO_2x8888 t0, t1, t0, t1, v1, s8, t4, t5, t6, t7
    CONVERT_2x0565_TO_2x8888 t2, t3, t2, t3, v1, s8, t4, t5, t6, t7
    BILINEAR_INTERPOLATE_SINGLE_PIXEL t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, s4, s5, s6, s7
    lbu      t1, 0(a1)         /* t1 = mask */
    addiu    a1, a1, 1
    MIPS_UN8x4_MUL_UN8 t0, t1, t0, v0, t2, t3, t4
    CONVERT_1x8888_TO_1x0565 t0, t1, t2, t3

    addu     s2, s2, s3        /* vx += unit_x; */
    sh       t1, 0(a0)
    bnez     ra, 0b
     addiu   a0, a0, 2

    RESTORE_REGS_FROM_STACK 32, v0, v1, s0, s1, s2, s3, s4, s5, s6, s7, s8, ra
1:
    j        ra
     nop

END(pixman_scaled_bilinear_scanline_0565_8_0565_SRC_asm_mips)

LEAF_MIPS_DSPR2(pixman_scaled_bilinear_scanline_8888_8_8888_OVER_asm_mips)
/*
 * a0     - dst        (a8r8g8b8)
 * a1     - mask       (a8)
 * a2     - src_top    (a8r8g8b8)
 * a3     - src_bottom (a8r8g8b8)
 * 16(sp) - wt
 * 20(sp) - wb
 * 24(sp) - vx
 * 28(sp) - unit_x
 * 32(sp) - w
 */

    SAVE_REGS_ON_STACK 28, v0, v1, s0, s1, s2, s3, s4, s5, s6, s7, s8

    lw       v1, 60(sp)        /* v1 = w(sp + 32 + 28 save regs stack offset)*/
    beqz     v1, 1f
     nop

    lw       s0, 44(sp)        /* s0 = wt */
    lw       s1, 48(sp)        /* s1 = wb */
    lw       s2, 52(sp)        /* s2 = vx */
    lw       s3, 56(sp)        /* s3 = unit_x */
    li       v0, BILINEAR_INTERPOLATION_RANGE
    li       s8, 0x00ff00ff

    sll      s0, s0, (2 * (8 - BILINEAR_INTERPOLATION_BITS))
    sll      s1, s1, (2 * (8 - BILINEAR_INTERPOLATION_BITS))

0:
    andi     t4, s2, 0xffff    /* t4 = (short)vx */
    srl      t4, t4, (16 - BILINEAR_INTERPOLATION_BITS) /* t4 = vx >> 8 */
    subu     t5, v0, t4        /* t5 = ( 256 - (vx>>8)) */

    mul      s4, s0, t5        /* s4 = wt*(256-(vx>>8)) */
    mul      s5, s0, t4        /* s5 = wt*(vx>>8) */
    mul      s6, s1, t5        /* s6 = wb*(256-(vx>>8)) */
    mul      s7, s1, t4        /* s7 = wb*(vx>>8) */

    sra      t9, s2, 16
    sll      t9, t9, 2
    addiu    t8, t9, 4
    lwx      t0, t9(a2)        /* t0 = tl */
    lwx      t1, t8(a2)        /* t1 = tr */
    addiu    v1, v1, -1
    lwx      t2, t9(a3)        /* t2 = bl */
    lwx      t3, t8(a3)        /* t3 = br */

    BILINEAR_INTERPOLATE_SINGLE_PIXEL t0, t1, t2, t3, \
                                      t4, t5, t6, t7, t8, t9, s4, s5, s6, s7
    lbu      t1, 0(a1)         /* t1 = mask */
    lw       t2, 0(a0)         /* t2 = dst */
    addiu    a1, a1, 1
    OVER_8888_8_8888 t0, t1, t2, t0, s8, t3, t4, t5, t6

    addu     s2, s2, s3        /* vx += unit_x; */
    sw       t0, 0(a0)
    bnez     v1, 0b
     addiu   a0, a0, 4

1:
    RESTORE_REGS_FROM_STACK 28, v0, v1, s0, s1, s2, s3, s4, s5, s6, s7, s8
    j        ra
     nop

END(pixman_scaled_bilinear_scanline_8888_8_8888_OVER_asm_mips)

LEAF_MIPS_DSPR2(pixman_scaled_bilinear_scanline_8888_8_8888_ADD_asm_mips)
/*
 * a0     - *dst
 * a1     - *mask
 * a2     - *src_top
 * a3     - *src_bottom
 * 16(sp) - wt
 * 20(sp) - wb
 * 24(sp) - vx
 * 28(sp) - unit_x
 * 32(sp) - w
 */

    lw       v1, 32(sp)
    beqz     v1, 1f
     nop

    SAVE_REGS_ON_STACK 28, v0, v1, s0, s1, s2, s3, s4, s5, s6, s7, s8

    lw       s0, 44(sp)        /* s0 = wt */
    lw       s1, 48(sp)        /* s1 = wb */
    lw       s2, 52(sp)        /* s2 = vx */
    lw       s3, 56(sp)        /* s3 = unit_x */
    li       v0, BILINEAR_INTERPOLATION_RANGE
    li       s8, 0x00ff00ff

    sll      s0, s0, (2 * (8 - BILINEAR_INTERPOLATION_BITS))
    sll      s1, s1, (2 * (8 - BILINEAR_INTERPOLATION_BITS))
0:
    andi     t4, s2, 0xffff    /* t4 = (short)vx */
    srl      t4, t4, (16 - BILINEAR_INTERPOLATION_BITS) /* t4 = vx >> 8 */
    subu     t5, v0, t4        /* t5 = ( 256 - (vx>>8)) */

    mul      s4, s0, t5        /* s4 = wt*(256-(vx>>8)) */
    mul      s5, s0, t4        /* s5 = wt*(vx>>8) */
    mul      s6, s1, t5        /* s6 = wb*(256-(vx>>8)) */
    mul      s7, s1, t4        /* s7 = wb*(vx>>8) */

    sra      t9, s2, 16
    sll      t9, t9, 2
    addiu    t8, t9, 4
    lwx      t0, t9(a2)        /* t0 = tl */
    lwx      t1, t8(a2)        /* t1 = tr */
    addiu    v1, v1, -1
    lwx      t2, t9(a3)        /* t2 = bl */
    lwx      t3, t8(a3)        /* t3 = br */

    BILINEAR_INTERPOLATE_SINGLE_PIXEL t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, s4, s5, s6, s7
    lbu      t1, 0(a1)         /* t1 = mask */
    lw       t2, 0(a0)         /* t2 = dst */
    addiu    a1, a1, 1
    MIPS_UN8x4_MUL_UN8_ADD_UN8x4 t0, t1, t2, t0, s8, t3, t4, t5

    addu     s2, s2, s3        /* vx += unit_x; */
    sw       t0, 0(a0)
    bnez     v1, 0b
     addiu   a0, a0, 4

    RESTORE_REGS_FROM_STACK 28, v0, v1, s0, s1, s2, s3, s4, s5, s6, s7, s8
1:
    j        ra
     nop

END(pixman_scaled_bilinear_scanline_8888_8_8888_ADD_asm_mips)