aboutsummaryrefslogtreecommitdiffstats
path: root/distrib/libpng-1.2.19/pnggccrd.c
blob: f63867cd225cc18cad8e74d0e3e519a80d0f8755 (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
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041

/* pnggccrd.c - mixed C/assembler version of utilities to read a PNG file
 *
 * For Intel/AMD x86 or x86-64 CPU (Pentium-MMX or later) and GNU C compiler.
 *
 * Last changed in libpng 1.2.19 August 18, 2007
 * For conditions of distribution and use, see copyright notice in png.h
 * Copyright (c) 1998 Intel Corporation
 * Copyright (c) 1999-2002,2007 Greg Roelofs
 * Copyright (c) 1998-2007 Glenn Randers-Pehrson
 *
 * Based on MSVC code contributed by Nirav Chhatrapati, Intel Corp., 1998.
 * Interface to libpng contributed by Gilles Vollant, 1999.
 * GNU C port by Greg Roelofs, 1999-2001.
 *
 * References:
 *
 *     http://www.intel.com/drg/pentiumII/appnotes/916/916.htm
 *     http://www.intel.com/drg/pentiumII/appnotes/923/923.htm
 *       [Intel's performance analysis of the MMX vs. non-MMX code;
 *        moved/deleted as of 2006, but text and some graphs still
 *        available via WayBack Machine at archive.org]
 *
 *     http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html
 *     http://sam.zoy.org/blog/2007-04-13-shlib-with-non-pic-code-have-inline-assembly-and-pic-mix-well
 *     http://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
 *     http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html
 *     http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
 *     AMD64 Architecture Programmer's Manual, volumes 1 and 5
 *       [http://www.amd.com/us-en/Processors/TechnicalResources/0,,30_182_739_7044,00.html]
 *     Intel 64 and IA-32 Software Developer's Manuals
 *       [http://developer.intel.com/products/processor/manuals/]
 *
 * png_read_filter_row_mmx_*() were converted in place with intel2gas 1.3.1:
 *
 *     intel2gas -mdI pnggccrd.c.partially-msvc -o pnggccrd.c
 *
 * and then cleaned up by hand.  See http://hermes.terminal.at/intel2gas/ .
 *
 * NOTE:  A sufficiently recent version of GNU as (or as.exe under DOS/Windows)
 * is required to assemble the newer asm instructions such as movq.  (Version
 * 2.5.2l.15 is definitely too old.)  See ftp://ftp.gnu.org/pub/gnu/binutils/ .
 */

/*
 * PORTING NOTES AND CHANGELOG (mostly by Greg Roelofs)
 * ===========================
 *
 * 19991006:
 *  - fixed sign error in post-MMX cleanup code (16- & 32-bit cases)
 *
 * 19991007:
 *  - additional optimizations (possible or definite):
 *     x [DONE] write MMX code for 64-bit case (pixel_bytes == 8) [not tested]
 *     - write MMX code for 48-bit case (pixel_bytes == 6)
 *     - figure out what's up with 24-bit case (pixel_bytes == 3):
 *        why subtract 8 from width_mmx in the pass 4/5 case?
 *        (only width_mmx case) (near line 2335)
 *     x [DONE] replace pixel_bytes within each block with the true
 *        constant value (or are compilers smart enough to do that?)
 *     - rewrite all MMX interlacing code so it's aligned with
 *        the *beginning* of the row buffer, not the end.  This
 *        would not only allow one to eliminate half of the memory
 *        writes for odd passes (that is, pass == odd), it may also
 *        eliminate some unaligned-data-access exceptions (assuming
 *        there's a penalty for not aligning 64-bit accesses on
 *        64-bit boundaries).  The only catch is that the "leftover"
 *        pixel(s) at the end of the row would have to be saved,
 *        but there are enough unused MMX registers in every case,
 *        so this is not a problem.  A further benefit is that the
 *        post-MMX cleanup code (C code) in at least some of the
 *        cases could be done within the assembler block.
 *  x [DONE] the "v3 v2 v1 v0 v7 v6 v5 v4" comments are confusing,
 *     inconsistent, and don't match the MMX Programmer's Reference
 *     Manual conventions anyway.  They should be changed to
 *     "b7 b6 b5 b4 b3 b2 b1 b0," where b0 indicates the byte that
 *     was lowest in memory (i.e., corresponding to a left pixel)
 *     and b7 is the byte that was highest (i.e., a right pixel).
 *
 * 19991016:
 *  - Brennan's Guide notwithstanding, gcc under Linux does *not*
 *     want globals prefixed by underscores when referencing them--
 *     i.e., if the variable is const4, then refer to it as const4,
 *     not _const4.  This seems to be a djgpp-specific requirement.
 *     Also, such variables apparently *must* be declared outside
 *     of functions; neither static nor automatic variables work if
 *     defined within the scope of a single function, but both
 *     static and truly global (multi-module) variables work fine.
 *
 * 19991017:
 *  - replaced pixel_bytes in each png_memcpy() call with constant value for
 *     inlining (png_do_read_interlace() "non-MMX/modified C code" block)
 *
 * 19991023:
 *  - fixed png_combine_row() non-MMX replication bug (odd passes only?)
 *  - switched from string-concatenation-with-macros to cleaner method of
 *     renaming global variables for djgpp--i.e., always use prefixes in
 *     inlined assembler code (== strings) and conditionally rename the
 *     variables, not the other way around.  Hence _const4, _mask8_0, etc.
 *
 * 19991024:
 *  - fixed mmxsupport()/png_do_read_interlace() first-row bug
 *     This one was severely weird:  even though mmxsupport() doesn't touch
 *     ebx (where "row" pointer was stored), it nevertheless managed to zero
 *     the register (even in static/non-fPIC code--see below), which in turn
 *     caused png_do_read_interlace() to return prematurely on the first row of
 *     interlaced images (i.e., without expanding the interlaced pixels).
 *     Inspection of the generated assembly code didn't turn up any clues,
 *     although it did point at a minor optimization (i.e., get rid of
 *     mmx_supported_local variable and just use eax).  Possibly the CPUID
 *     instruction is more destructive than it looks?  (Not yet checked.)
 *  - "info gcc" was next to useless, so compared fPIC and non-fPIC assembly
 *     listings...  Apparently register spillage has to do with ebx, since
 *     it's used to index the global offset table.  Commenting it out of the
 *     input-reg lists in png_combine_row() eliminated compiler barfage, so
 *     ifdef'd with __PIC__ macro:  if defined, use a global for unmask
 *
 * 19991107:
 *  - verified CPUID clobberage:  12-char string constant ("GenuineIntel",
 *     "AuthenticAMD", etc.) placed in ebx:ecx:edx.  Still need to polish.
 *
 * 19991120:
 *  - made "diff" variable (now "_dif") global to simplify conversion of
 *     filtering routines (running out of regs, sigh).  "diff" is still used
 *     in interlacing routines, however.
 *  - fixed up both versions of mmxsupport() (ORIG_THAT_USED_TO_CLOBBER_EBX
 *     macro determines which is used); original not yet tested.
 *
 * 20000213:
 *  - when compiling with gcc, be sure to use  -fomit-frame-pointer
 *
 * 20000319:
 *  - fixed a register-name typo in png_do_read_interlace(), default (MMX) case,
 *     pass == 4 or 5, that caused visible corruption of interlaced images
 *
 * 20000623:
 *  - Various problems were reported with gcc 2.95.2 in the Cygwin environment,
 *     many of the form "forbidden register 0 (ax) was spilled for class AREG."
 *     This is explained at http://gcc.gnu.org/fom_serv/cache/23.html, and
 *     Chuck Wilson supplied a patch involving dummy output registers.  See
 *     http://sourceforge.net/bugs/?func=detailbug&bug_id=108741&group_id=5624
 *     for the original (anonymous) SourceForge bug report.
 *
 * 20000706:
 *  - Chuck Wilson passed along these remaining gcc 2.95.2 errors:
 *       pnggccrd.c: In function `png_combine_row':
 *       pnggccrd.c:525: more than 10 operands in `asm'
 *       pnggccrd.c:669: more than 10 operands in `asm'
 *       pnggccrd.c:828: more than 10 operands in `asm'
 *       pnggccrd.c:994: more than 10 operands in `asm'
 *       pnggccrd.c:1177: more than 10 operands in `asm'
 *     They are all the same problem and can be worked around by using the
 *     global _unmask variable unconditionally, not just in the -fPIC case.
 *     Reportedly earlier versions of gcc also have the problem with more than
 *     10 operands; they just don't report it.  Much strangeness ensues, etc.
 *
 * 20000729:
 *  - enabled png_read_filter_row_mmx_up() (shortest remaining unconverted
 *     MMX routine); began converting png_read_filter_row_mmx_sub()
 *  - to finish remaining sections:
 *     - clean up indentation and comments
 *     - preload local variables
 *     - add output and input regs (order of former determines numerical
 *        mapping of latter)
 *     - avoid all usage of ebx (including bx, bh, bl) register [20000823]
 *     - remove "$" from addressing of Shift and Mask variables [20000823]
 *
 * 20000731:
 *  - global union vars causing segfaults in png_read_filter_row_mmx_sub()?
 *
 * 20000822:
 *  - ARGH, stupid png_read_filter_row_mmx_sub() segfault only happens with
 *     shared-library (-fPIC) version!  Code works just fine as part of static
 *     library.  Should have tested that sooner.
 *     ebx is getting clobbered again (explicitly this time); need to save it
 *     on stack or rewrite asm code to avoid using it altogether.  Blargh!
 *
 * 20000823:
 *  - first section was trickiest; all remaining sections have ebx -> edx now.
 *     (-fPIC works again.)  Also added missing underscores to various Shift*
 *     and *Mask* globals and got rid of leading "$" signs.
 *
 * 20000826:
 *  - added visual separators to help navigate microscopic printed copies
 *     (http://pobox.com/~newt/code/gpr-latest.zip, mode 10); started working
 *     on png_read_filter_row_mmx_avg()
 *
 * 20000828:
 *  - finished png_read_filter_row_mmx_avg():  only Paeth left! (930 lines...)
 *     What the hell, did png_read_filter_row_mmx_paeth(), too.  Comments not
 *     cleaned up/shortened in either routine, but functionality is complete
 *     and seems to be working fine.
 *
 * 20000829:
 *  - ahhh, figured out last(?) bit of gcc/gas asm-fu:  if register is listed
 *     as an input reg (with dummy output variables, etc.), then it *cannot*
 *     also appear in the clobber list or gcc 2.95.2 will barf.  The solution
 *     is simple enough...
 *
 * 20000914:
 *  - bug in png_read_filter_row_mmx_avg():  16-bit grayscale not handled
 *     correctly (but 48-bit RGB just fine)
 *
 * 20000916:
 *  - fixed bug in png_read_filter_row_mmx_avg(), bpp == 2 case; three errors:
 *     - "_ShiftBpp.use = 24;"      should have been   "_ShiftBpp.use = 16;"
 *     - "_ShiftRem.use = 40;"      should have been   "_ShiftRem.use = 48;"
 *     - "psllq _ShiftRem, %%mm2"   should have been   "psrlq _ShiftRem, %%mm2"
 *
 * 20010101:
 *  - added new png_init_mmx_flags() function (here only because it needs to
 *     call mmxsupport(), which should probably become global png_mmxsupport());
 *     modified other MMX routines to run conditionally (png_ptr->asm_flags)
 *
 * 20010103:
 *  - renamed mmxsupport() to png_mmx_support(), with auto-set of mmx_supported,
 *     and made it public; moved png_init_mmx_flags() to png.c as internal func
 *
 * 20010104:
 *  - removed dependency on png_read_filter_row_c() (C code already duplicated
 *     within MMX version of png_read_filter_row()) so no longer necessary to
 *     compile it into pngrutil.o
 *
 * 20010310:
 *  - fixed buffer-overrun bug in png_combine_row() C code (non-MMX)
 *
 * 20010808:
 *  - added PNG_THREAD_UNSAFE_OK around code using global variables [GR-P]
 *
 * 20011124:
 *  - fixed missing save of Eflag in png_mmx_support() [Maxim Sobolev]
 *
 * 20020304:
 *  - eliminated incorrect use of width_mmx in pixel_bytes == 8 case
 *
 * 20020407:
 *  - fixed insufficient preservation of ebx register [Sami Farin]
 *
 * 20040724:
 *  - more tinkering with clobber list at lines 4529 and 5033 to get it to
 *     compile with gcc 3.4 [GR-P]
 *
 * 20040809:
 *  - added "rim" definitions for CONST4 and CONST6 [GR-P]
 *
 * 20060303:
 *  - added "OS2" to list of systems that don't need leading underscores [GR-P]
 *
 * 20060320:
 *  - made PIC-compliant [Christian Aichinger]
 *
 * 20070313:
 *  - finally applied Giuseppe Ghibò's 64-bit patch of 20060803 (completely
 *     overlooked Dylan Alex Simon's similar patch of 20060414, oops...)
 *
 * 20070524:
 *  - fixed link failure caused by asm-only variables being optimized out
 *     (identified by Dimitri of Trolltech) with __attribute__((used)), which
 *     also gets rid of warnings => nuked ugly png_squelch_warnings() hack
 *  - dropped redundant ifdef
 *  - moved png_mmx_support() back up where originally intended (as in
 *     pngvcrd.c), using __attribute__((noinline)) in extra prototype
 *
 * 20070527:
 *  - revised png_combine_row() to reuse mask in lieu of external _unmask
 *  - moved 32-bit (RGBA) case to top of png_combine_row():  most common
 *  - just about ready to give up on x86-64 -fPIC mode; can't even access 16
 *     _mask*_* constants without triggering link error on shared library:
 *       /usr/bin/ld: pnggccrd.pic.o: relocation R_X86_64_32S against `a local
 *         symbol' can not be used when making a shared object; recompile with
 *         -fPIC
 *       pnggccrd.pic.o: could not read symbols: Bad value
 *       ("objdump -x pnggccrd.pic.o | grep rodata" to verify)
 *     [might be able to work around by doing within assembly code whatever
 *     -fPIC does, but given problems to date, seems like long shot...]
 *     [relevant ifdefs:  __x86_64__ && __PIC__ => C code only]
 *  - changed #if 0 to #ifdef PNG_CLOBBER_MMX_REGS_SUPPORTED in case gcc ever
 *     supports MMX regs (%mm0, etc.) in clobber list (not supported by gcc
 *     2.7.2.3, 2.91.66 (egcs 1.1.2), 3.x, or 4.1.2)
 *
 * 20070603:
 *  - revised png_combine_row() to use @GOTPCREL(%%rip) addressing on _c64
 *     struct of _mask*_* constants for x86-64 -fPIC; see sam.zoy.org link
 *     above for details
 *  - moved _const4 and _const6 into _c64 struct, renamed to _amask5_3_0 and
 *     _amask7_1_0, respectively
 *  - can't figure out how to use _c64._mask*_* vars within asm code, so still
 *     need single variables for non-x86-64/-fPIC half :-(
 *  - replaced various __PIC__ ifdefs with *_GOT_ebx macros
 *  - moved _LBCarryMask and _HBClearMask into _c64 struct
 *  - conditionally replaced _p*temp variables with %r11d-%r13d (via p*_TEMP
 *     and CLOBBER_r1*d macros)
 *
 * 20070604:
 *  - replaced all _ActiveMask and _ActiveMaskEnd with new _amask*_*_* consts
 *     (_amask naming convention:  numbers of 00-bytes, ff-bytes, 00-bytes)
 *    - _ActiveMask     // (10) // avg/paeth/sub; read-only; consts; movq/pand
 *       0x0000000000ffffffLL (bpp 3, avg)      _amask5_3_0
 *       0xffffffffffffffffLL (bpp 4, 6, avg)   _amask0_8_0
 *       0x000000000000ffffLL (bpp 2, avg)      _amask6_2_0
 *       0x0000000000ffffffLL (bpp 3, paeth)    _amask5_3_0
 *       0x00000000ffffffffLL (bpp 6, paeth)    _amask4_4_0
 *       0x00000000ffffffffLL (bpp 4, paeth)    _amask4_4_0
 *       0x00000000ffffffffLL (bpp 8, paeth)    _amask4_4_0
 *       0x0000ffffff000000LL (bpp 3, sub)      _amask2_3_3
 *       0x00000000ffff0000LL (bpp 2, sub)      _amask4_2_2
 *    - _ActiveMaskEnd  // (1)  // paeth only; read-only; const; pand
 *       0xffff000000000000LL (bpp 3, paeth)    _amask0_2_6
 *  - changed all "#if defined(__x86_64__) // later // && defined(__PIC__)"
 *     lines to "#ifdef PNG_x86_64_USE_GOTPCREL" for easier/safer testing
 *
 * 20070605:
 *  - merged PNG_x86_64_USE_GOTPCREL, non-PNG_x86_64_USE_GOTPCREL code via
 *     *MASK* and LOAD/RESTORE macros
 *
 * 20070607:
 *  - replaced all constant instances of _ShiftBpp, _ShiftRem with immediates
 *     (still have two shared cases in avg, sub routines)
 *
 * 20070609:
 *  - replaced remaining instances of _ShiftBpp, _ShiftRem with immediates
 *     (split sub and avg 4/6-bpp cases into separate blocks)
 *  - fixed paeth bug due to clobbered r11/r12/r13 regs
 *
 * 20070610:
 *  - made global "_dif" variable (avg/paeth/sub routines) local again (now
 *     "diff"--see 19991120 entry above), using register constraints
 *  - note that %ebp in clobber list doesn't actually work, at least for 32-bit
 *     version and gcc 4.1.2; must save and restore manually.  (Seems to work
 *     OK for 64-bit version and gcc 3.4.3, but gcc may not be using ebp/rbp
 *     in that case.)
 *  - started replacing direct _MMXLength accesses with register constraints
 *
 * 20070612:
 *  - continued replacing direct _MMXLength accesses with register constraints
 *
 * 20070613:
 *  - finished replacing direct _MMXLength accesses with register constraints;
 *     switched to local variable (and renamed back to MMXLength)
 *
 * 20070614:
 *  - fixed sub bpp = 1 bug
 *  - started replacing direct _FullLength accesses with register constraints
 *
 * 20070615:
 *  - fixed 64-bit paeth bpp 3 crash bug (misplaced LOAD_GOT_rbp)
 *  - fixed 64-bit paeth bpp 1/2 and cleanup-block crash bugs (misplaced
 *     RESTORE_r11_r12_r13)
 *  - slightly optimized avg/paeth cleanup blocks and paeth bpp 1/2 block
 *     (save/restore ebx only if needed)
 *  - continued replacing direct _FullLength accesses with register constraints
 *
 * 20070616:
 *  - finished replacing direct _FullLength accesses with register constraints
 *     (*ugly* conditional clobber-separator macros for avg and paeth, sigh)
 *
 * 20070618:
 *  - fixed misplaced PNG_THREAD_UNSAFE_OK endif (was missing LOAD_GOT_rbp/
 *     RESTORE_rbp in 32-bit thread-safe case)
 *  - changed all "ifdef *" to "if defined(*)" [GR-P]
 *
 * 20070619:
 *  - rearranged most bitdepth-related case statements to put most frequent
 *     cases at top (24-bit, 32-bit, 8-bit, rest)
 *
 * 20070623:
 *  - cleaned up png_debug() warnings/formatting
 *  - removed PNG_MMX_CODE_SUPPORTED ifdefs and added outer __GNUC__ ifdef
 *     (module no longer used by non-x86/non-GCC builds as of libpng 1.2.19)
 *  - removed single libpng-1.2.x PNG_DEBUG dependency on 1.0.x png_struct
 *     member (row_buf_size)
 *  - rearranged pass-related if-blocks in png_do_read_interlace() to put most
 *     frequent cases (4, 5) at top [GR-P suggestion]
 *
 * 20070624-29:
 *  - fixed 64-bit crash bug:  pointers -> rsi/rdi, not esi/edi (switched to
 *     %0/%1/%2/%3/%4 notation; eliminated size suffixes from relevant add/
 *     inc/sub/mov instructions; changed dummy vars to pointers)
 *     - png_combine_row()
 *     - png_do_read_interlace()
 *     - png_read_filter_row_mmx_avg()
 *     - png_read_filter_row_mmx_paeth()
 *     - png_read_filter_row_mmx_sub()
 *     - png_read_filter_row_mmx_up()
 *  - NOTE:  this fix makes use of the fact that modifying a 32-bit reg (e.g.,
 *     %%ebx) clears the top half of its corresponding 64-bit reg (%%rbx), so
 *     it's safe to mix 32-bit operations with 64-bit base/index addressing
 *     (see new PSI/PAX/PBX/PDX/PBP/etc. "pointer-register" macros); applies
 *     also to clobber lists
 *
 * 20070630:
 *  - cleaned up formatting, macros, minor png_read_filter_row_mmx_sub() 8-bpp
 *     register-usage inefficiency
 *  - fixed 32-bit png_do_read_interlace() bug (was using pointer size for
 *     64-bit dummy values)
 *
 * 20070703:
 *  - added check for (manual) PIC macro to fix OpenBSD crash bug
 *
 * 20070717:
 *  - fixed 48-bit png_combine_row() bug (was acting like 32-bit):  copy 6
 *     bytes per pixel, not 4, and use stride of 6, not 4, in the second loop
 *     of interlace processing of 48-bit pixels [GR-P]
 *
 * 20070722:
 *  - fixed 64-bit png_uint_32 bug with MMXLength/FullLength temp vars
 *
 * [still broken:  tops of all row-filter blocks (input/output constraints);
 *  shows up on 64-bit dynamic (-fPIC) version with -O2, especially if debug-
 *  printfs enabled, but at right edge of odd-width images even if disabled]
 *
 *
 * STILL TO DO:
 *  - fix final thread-unsafe code using stack vars and pointer? (paeth top,
 *     default, bottom only:  default, bottom already 5 reg constraints; could
 *     replace bpp with pointer and group bpp/patemp/pbtemp/pctemp in array)
 *  - fix ebp/no-reg-constraint inefficiency (avg/paeth/sub top)
 *  - test png_do_read_interlace() 64-bit case (pixel_bytes == 8)
 *  - write MMX code for 48-bit case (pixel_bytes == 6)
 *  - figure out what's up with 24-bit case (pixel_bytes == 3):
 *     why subtract 8 from width_mmx in the pass 4/5 case?  due to
 *     odd number of bytes? (only width_mmx case) (near line 2335)
 *  - rewrite all MMX interlacing code so it's aligned with beginning
 *     of the row buffer, not the end (see 19991007 for details)
 *  - add error messages to any remaining bogus default cases
 *  - enable pixel_depth == 8 cases in png_read_filter_row()? (test speed)
 *  - try =r, etc., as reg constraints?  (would gcc use 64-bit ones on x86-64?)
 *  - need full, non-graphical, CRC-based test suite...  maybe autogenerate
 *     random data of various height/width/depth, compute CRCs, write (C
 *     funcs), read (asm/MMX), recompute CRCs, and compare?
 *  - write true x86-64 version using 128-bit "media instructions", %xmm0-15,
 *     and extra general-purpose registers
 */

#if defined(__GNUC__)

#define PNG_INTERNAL
#include "png.h"


/* for some inexplicable reason, gcc 3.3.5 on OpenBSD (and elsewhere?) does
 * *not* define __PIC__ when the -fPIC option is used, so we have to rely on
 * makefiles and whatnot to define the PIC macro explicitly */
#if defined(PIC) && !defined(__PIC__)   // (this can/should move to pngconf.h)
#  define __PIC__
#endif

#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_USE_PNGGCCRD)

/* if you want/need full thread-safety on x86-64 even when linking statically,
 * comment out the "&& defined(__PIC__)" part here: */
#if defined(__x86_64__) && defined(__PIC__)
#  define PNG_x86_64_USE_GOTPCREL            // GOTPCREL => full thread-safety
#  define PNG_CLOBBER_x86_64_REGS_SUPPORTED  // works as of gcc 3.4.3 ...
#endif

int PNGAPI png_mmx_support(void);

#if defined(PNG_USE_LOCAL_ARRAYS)
static PNG_CONST int FARDATA png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
static PNG_CONST int FARDATA png_pass_inc[7]   = {8, 8, 4, 4, 2, 2, 1};
static PNG_CONST int FARDATA png_pass_width[7] = {8, 4, 4, 2, 2, 1, 1};
#endif

/* djgpp, Win32, Cygwin, and OS2 add their own underscores to global variables,
 * so define them without: */
#if defined(__DJGPP__) || defined(WIN32) || defined(__CYGWIN__) || \
    defined(__OS2__)
#  define _mmx_supported  mmx_supported
#  define _mask8_0        mask8_0
#  define _mask16_1       mask16_1
#  define _mask16_0       mask16_0
#  define _mask24_2       mask24_2
#  define _mask24_1       mask24_1
#  define _mask24_0       mask24_0
#  define _mask32_3       mask32_3
#  define _mask32_2       mask32_2
#  define _mask32_1       mask32_1
#  define _mask32_0       mask32_0
#  define _mask48_5       mask48_5
#  define _mask48_4       mask48_4
#  define _mask48_3       mask48_3
#  define _mask48_2       mask48_2
#  define _mask48_1       mask48_1
#  define _mask48_0       mask48_0
#  define _amask5_3_0     amask5_3_0
#  define _amask7_1_0     amask7_1_0
#  define _LBCarryMask    LBCarryMask
#  define _HBClearMask    HBClearMask
#  define _amask0_8_0     amask0_8_0
#  define _amask6_2_0     amask6_2_0
#  define _amask4_4_0     amask4_4_0
#  define _amask0_2_6     amask0_2_6
#  define _amask2_3_3     amask2_3_3
#  define _amask4_2_2     amask4_2_2
#  if defined(PNG_THREAD_UNSAFE_OK)
#    define _patemp       patemp
#    define _pbtemp       pbtemp
#    define _pctemp       pctemp
#  endif
#endif // djgpp, Win32, Cygwin, OS2


/* These constants are used in the inlined MMX assembly code. */

typedef unsigned long long  ull;

#if defined(PNG_x86_64_USE_GOTPCREL)
static PNG_CONST struct {
    //ull _mask_array[26];

    // png_combine_row() constants:
    ull _mask8_0;
    ull _mask16_0, _mask16_1;
    ull _mask24_0, _mask24_1, _mask24_2;
    ull _mask32_0, _mask32_1, _mask32_2, _mask32_3;
    ull _mask48_0, _mask48_1, _mask48_2, _mask48_3, _mask48_4, _mask48_5;

    // png_do_read_interlace() constants:
    ull _amask5_3_0, _amask7_1_0;  // was _const4 and _const6, respectively

    // png_read_filter_row_mmx_avg() constants (also uses _amask5_3_0):
    ull _LBCarryMask, _HBClearMask;
    ull _amask0_8_0, _amask6_2_0;  // was ActiveMask for bpp 4/6 and 2 cases

    // png_read_filter_row_mmx_paeth() constants (also uses _amask5_3_0):
    ull _amask4_4_0, _amask0_2_6;  // was ActiveMask{,End} for bpp 6/4/8 and 3

    // png_read_filter_row_mmx_sub() constants:
    ull _amask2_3_3, _amask4_2_2;  // was ActiveMask for bpp 3 and 2 cases

} _c64 __attribute__((used, aligned(8))) = {

    // png_combine_row() constants:
    0x0102040810204080LL, // _mask8_0      offset 0

    0x1010202040408080LL, // _mask16_0     offset 8
    0x0101020204040808LL, // _mask16_1     offset 16

    0x2020404040808080LL, // _mask24_0     offset 24
    0x0408080810101020LL, // _mask24_1     offset 32
    0x0101010202020404LL, // _mask24_2     offset 40

    0x4040404080808080LL, // _mask32_0     offset 48
    0x1010101020202020LL, // _mask32_1     offset 56
    0x0404040408080808LL, // _mask32_2     offset 64
    0x0101010102020202LL, // _mask32_3     offset 72

    0x4040808080808080LL, // _mask48_0     offset 80
    0x2020202040404040LL, // _mask48_1     offset 88
    0x1010101010102020LL, // _mask48_2     offset 96
    0x0404080808080808LL, // _mask48_3     offset 104
    0x0202020204040404LL, // _mask48_4     offset 112
    0x0101010101010202LL, // _mask48_5     offset 120

    // png_do_read_interlace() constants:
    0x0000000000FFFFFFLL, // _amask5_3_0   offset 128  (bpp 3, avg/paeth) const4
    0x00000000000000FFLL, // _amask7_1_0   offset 136                     const6

    // png_read_filter_row_mmx_avg() constants:
    0x0101010101010101LL, // _LBCarryMask  offset 144
    0x7F7F7F7F7F7F7F7FLL, // _HBClearMask  offset 152
    0xFFFFFFFFFFFFFFFFLL, // _amask0_8_0   offset 160  (bpp 4/6, avg)
    0x000000000000FFFFLL, // _amask6_2_0   offset 168  (bpp 2,   avg)

    // png_read_filter_row_mmx_paeth() constants:
    0x00000000FFFFFFFFLL, // _amask4_4_0   offset 176  (bpp 6/4/8, paeth)
    0xFFFF000000000000LL, // _amask0_2_6   offset 184  (bpp 3, paeth)   A.M.End

    // png_read_filter_row_mmx_sub() constants:
    0x0000FFFFFF000000LL, // _amask2_3_3   offset 192  (bpp 3, sub)
    0x00000000FFFF0000LL, // _amask4_2_2   offset 200  (bpp 2, sub)

};

#define MASK8_0        "(%%rbp)"
#define MASK16_0       "8(%%rbp)"
#define MASK16_1       "16(%%rbp)"
#define MASK24_0       "24(%%rbp)"
#define MASK24_1       "32(%%rbp)"
#define MASK24_2       "40(%%rbp)"
#define MASK32_0       "48(%%rbp)"
#define MASK32_1       "56(%%rbp)"
#define MASK32_2       "64(%%rbp)"
#define MASK32_3       "72(%%rbp)"
#define MASK48_0       "80(%%rbp)"
#define MASK48_1       "88(%%rbp)"
#define MASK48_2       "96(%%rbp)"
#define MASK48_3       "104(%%rbp)"
#define MASK48_4       "112(%%rbp)"
#define MASK48_5       "120(%%rbp)"
#define AMASK5_3_0     "128(%%rbp)"
#define AMASK7_1_0     "136(%%rbp)"
#define LB_CARRY_MASK  "144(%%rbp)"
#define HB_CLEAR_MASK  "152(%%rbp)"
#define AMASK0_8_0     "160(%%rbp)"
#define AMASK6_2_0     "168(%%rbp)"
#define AMASK4_4_0     "176(%%rbp)"
#define AMASK0_2_6     "184(%%rbp)"
#define AMASK2_3_3     "192(%%rbp)"
#define AMASK4_2_2     "200(%%rbp)"

#else // !PNG_x86_64_USE_GOTPCREL

static PNG_CONST ull _mask8_0  __attribute__((used, aligned(8))) = 0x0102040810204080LL;

static PNG_CONST ull _mask16_1 __attribute__((used, aligned(8))) = 0x0101020204040808LL;
static PNG_CONST ull _mask16_0 __attribute__((used, aligned(8))) = 0x1010202040408080LL;

static PNG_CONST ull _mask24_2 __attribute__((used, aligned(8))) = 0x0101010202020404LL;
static PNG_CONST ull _mask24_1 __attribute__((used, aligned(8))) = 0x0408080810101020LL;
static PNG_CONST ull _mask24_0 __attribute__((used, aligned(8))) = 0x2020404040808080LL;

static PNG_CONST ull _mask32_3 __attribute__((used, aligned(8))) = 0x0101010102020202LL;
static PNG_CONST ull _mask32_2 __attribute__((used, aligned(8))) = 0x0404040408080808LL;
static PNG_CONST ull _mask32_1 __attribute__((used, aligned(8))) = 0x1010101020202020LL;
static PNG_CONST ull _mask32_0 __attribute__((used, aligned(8))) = 0x4040404080808080LL;

static PNG_CONST ull _mask48_5 __attribute__((used, aligned(8))) = 0x0101010101010202LL;
static PNG_CONST ull _mask48_4 __attribute__((used, aligned(8))) = 0x0202020204040404LL;
static PNG_CONST ull _mask48_3 __attribute__((used, aligned(8))) = 0x0404080808080808LL;
static PNG_CONST ull _mask48_2 __attribute__((used, aligned(8))) = 0x1010101010102020LL;
static PNG_CONST ull _mask48_1 __attribute__((used, aligned(8))) = 0x2020202040404040LL;
static PNG_CONST ull _mask48_0 __attribute__((used, aligned(8))) = 0x4040808080808080LL;

// png_do_read_interlace() constants:
static PNG_CONST ull _amask5_3_0  __attribute__((aligned(8))) = 0x0000000000FFFFFFLL;  // was _const4
static PNG_CONST ull _amask7_1_0  __attribute__((aligned(8))) = 0x00000000000000FFLL;  // was _const6

// png_read_filter_row_mmx_avg() constants:
static PNG_CONST ull _LBCarryMask __attribute__((used, aligned(8))) = 0x0101010101010101LL;
static PNG_CONST ull _HBClearMask __attribute__((used, aligned(8))) = 0x7f7f7f7f7f7f7f7fLL;
static PNG_CONST ull _amask0_8_0  __attribute__((used, aligned(8))) = 0xFFFFFFFFFFFFFFFFLL;
static PNG_CONST ull _amask6_2_0  __attribute__((used, aligned(8))) = 0x000000000000FFFFLL;

// png_read_filter_row_mmx_paeth() constants:
static PNG_CONST ull _amask4_4_0  __attribute__((used, aligned(8))) = 0x00000000FFFFFFFFLL;
static PNG_CONST ull _amask0_2_6  __attribute__((used, aligned(8))) = 0xFFFF000000000000LL;

// png_read_filter_row_mmx_sub() constants:
static PNG_CONST ull _amask2_3_3  __attribute__((used, aligned(8))) = 0x0000FFFFFF000000LL;
static PNG_CONST ull _amask4_2_2  __attribute__((used, aligned(8))) = 0x00000000FFFF0000LL;

#define MASK8_0        "_mask8_0"
#define MASK16_0       "_mask16_0"
#define MASK16_1       "_mask16_1"
#define MASK24_0       "_mask24_0"
#define MASK24_1       "_mask24_1"
#define MASK24_2       "_mask24_2"
#define MASK32_0       "_mask32_0"
#define MASK32_1       "_mask32_1"
#define MASK32_2       "_mask32_2"
#define MASK32_3       "_mask32_3"
#define MASK48_0       "_mask48_0"
#define MASK48_1       "_mask48_1"
#define MASK48_2       "_mask48_2"
#define MASK48_3       "_mask48_3"
#define MASK48_4       "_mask48_4"
#define MASK48_5       "_mask48_5"
#define AMASK5_3_0     "_amask5_3_0"
#define AMASK7_1_0     "_amask7_1_0"
#define LB_CARRY_MASK  "_LBCarryMask"
#define HB_CLEAR_MASK  "_HBClearMask"
#define AMASK0_8_0     "_amask0_8_0"
#define AMASK6_2_0     "_amask6_2_0"
#define AMASK4_4_0     "_amask4_4_0"
#define AMASK0_2_6     "_amask0_2_6"
#define AMASK2_3_3     "_amask2_3_3"
#define AMASK4_2_2     "_amask4_2_2"

#endif // ?PNG_x86_64_USE_GOTPCREL


#if defined(PNG_HAVE_MMX_READ_FILTER_ROW) || defined(PNG_HAVE_MMX_COMBINE_ROW)

// this block is specific to png_read_filter_row_mmx_paeth() except for
// LOAD_GOT_rbp and RESTORE_rbp, which are also used in png_combine_row()
#if defined(PNG_x86_64_USE_GOTPCREL)
#  define pa_TEMP                "%%r11d"
#  define pb_TEMP                "%%r12d"
#  define pc_TEMP                "%%r13d"
#  if defined(PNG_CLOBBER_x86_64_REGS_SUPPORTED)  // works as of gcc 3.4.3 ...
#    define SAVE_r11_r12_r13
#    define RESTORE_r11_r12_r13
#    define _CLOBBER_r11_r12_r13 ,"%r11", "%r12", "%r13"
#    define CLOBBER_r11_r12_r13  "%r11", "%r12", "%r13"
#  else // !PNG_CLOBBER_x86_64_REGS_SUPPORTED
#    define SAVE_r11_r12_r13     "pushq %%r11  \n\t" \
                                 "pushq %%r12  \n\t" \
                                 "pushq %%r13  \n\t"  // "normally 0-extended"
#    define RESTORE_r11_r12_r13  "popq  %%r13  \n\t" \
                                 "popq  %%r12  \n\t" \
                                 "popq  %%r11  \n\t"
#    define _CLOBBER_r11_r12_r13
#    define CLOBBER_r11_r12_r13
#  endif
#  define LOAD_GOT_rbp           "pushq %%rbp                        \n\t" \
                                 "movq  _c64@GOTPCREL(%%rip), %%rbp  \n\t"
#  define RESTORE_rbp            "popq  %%rbp                        \n\t"
#else // 32-bit and/or non-PIC
#  if defined(PNG_THREAD_UNSAFE_OK)
     // These variables are used in png_read_filter_row_mmx_paeth() and would be
     //   local variables if not for gcc-inline-assembly addressing limitations
     //   (some apparently related to ELF format, others to CPU type).
     //
     // WARNING: Their presence defeats the thread-safety of libpng.
     static int                     _patemp  __attribute__((used));
     static int                     _pbtemp  __attribute__((used));
     static int                     _pctemp  __attribute__((used));
#    define pa_TEMP                "_patemp"
#    define pb_TEMP                "_pbtemp"  // temp variables for
#    define pc_TEMP                "_pctemp"  //  Paeth routine
#    define SAVE_r11_r12_r13
#    define RESTORE_r11_r12_r13
#    define _CLOBBER_r11_r12_r13   // not using regs => not clobbering
#    define CLOBBER_r11_r12_r13
#  endif // PNG_THREAD_UNSAFE_OK
#  define LOAD_GOT_rbp
#  define RESTORE_rbp
#endif

#if defined(__x86_64__)
#  define SAVE_ebp
#  define RESTORE_ebp
#  define _CLOBBER_ebp         ,"%ebp"
#  define CLOBBER_ebp          "%ebp"
#  define SAVE_FullLength      "movl %%eax, %%r15d  \n\t"
#  define RESTORE_FullLength   "movl %%r15d, "     // may go into eax or ecx
#  if defined(PNG_CLOBBER_x86_64_REGS_SUPPORTED)   // works as of gcc 3.4.3 ...
#    define SAVE_r15
#    define RESTORE_r15
#    define _CLOBBER_r15       ,"%r15"
#  else
#    define SAVE_r15           "pushq %%r15  \n\t"
#    define RESTORE_r15        "popq  %%r15  \n\t"
#    define _CLOBBER_r15
#  endif
#  define PBP                  "%%rbp"             // regs used for 64-bit
#  define PAX                  "%%rax"             //  pointers or in
#  define PBX                  "%%rbx"             //  combination with
#  define PCX                  "%%rcx"             //  64-bit pointer-regs
#  define PDX                  "%%rdx"             //  (base/index pairs,
#  define PSI                  "%%rsi"             //  add/sub/mov pairs)
#  define CLEAR_BOTTOM_3_BITS  "and  $0xfffffffffffffff8, "
#else
#  define SAVE_ebp             "pushl %%ebp \n\t"  // clobber list doesn't work
#  define RESTORE_ebp          "popl  %%ebp \n\t"  //  for %ebp on 32-bit; not
#  define _CLOBBER_ebp                             //  clear why not
#  define CLOBBER_ebp
#  define SAVE_FullLength      "pushl %%eax \n\t"
#  define RESTORE_FullLength   "popl "             // eax (avg) or ecx (paeth)
#  define SAVE_r15
#  define RESTORE_r15
#  define _CLOBBER_r15
#  define PBP                  "%%ebp"             // regs used for or in
#  define PAX                  "%%eax"             //  combination with
#  define PBX                  "%%ebx"             //  "normal," 32-bit
#  define PCX                  "%%ecx"             //  pointers
#  define PDX                  "%%edx"
#  define PSI                  "%%esi"
#  define CLEAR_BOTTOM_3_BITS  "and  $0xfffffff8, "
#endif

// CLOB_COMMA_ebx_ebp:  need comma ONLY if both CLOBBER_ebp and CLOBBER_GOT_ebx
//                      have values, i.e., only if __x86_64__ AND !__PIC__
#if defined(__x86_64__) && !defined(__PIC__)
#  define CLOB_COMMA_ebx_ebp    , // clobbering both ebp and ebx => need comma
#else
#  define CLOB_COMMA_ebx_ebp
#endif

// CLOB_COMMA_ebX_r1X:  need comma UNLESS both CLOBBER_ebp and CLOBBER_GOT_ebx
//                   are empty OR CLOBBER_r11_r12_r13 is empty--i.e., NO comma
//                   if (!__x86_64__ AND __PIC__) OR !(PNG_x86_64_USE_GOTPCREL
//                   AND PNG_CLOBBER_x86_64_REGS_SUPPORTED)   (double sigh...)
#if (!defined(__x86_64__) && defined(__PIC__)) || \
    !defined(PNG_x86_64_USE_GOTPCREL) || \
    !defined(PNG_CLOBBER_x86_64_REGS_SUPPORTED)
#  define CLOB_COMMA_ebX_r1X
#else
#  define CLOB_COMMA_ebX_r1X    , // clobbering (ebp OR ebx) AND r11_r12_r13
#endif

// CLOB_COLON_ebx_ebp:  need colon unless CLOBBER_ebp and CLOBBER_GOT_ebx are
//                      BOTH empty--i.e., NO colon if (!__x86_64__ AND __PIC__)
// CLOB_COLON_ebx_ebp_r1X:  if, in addition, CLOBBER_r11_r12_r13 is empty, then
//                          no colon for Paeth blocks, either--i.e., NO colon
//                          if !(PNG_x86_64_USE_GOTPCREL AND
//                               PNG_CLOBBER_x86_64_REGS_SUPPORTED)
#if (!defined(__x86_64__) && defined(__PIC__))
#  define CLOB_COLON_ebx_ebp
#  if !(defined(PNG_x86_64_USE_GOTPCREL) && \
        defined(PNG_CLOBBER_x86_64_REGS_SUPPORTED))
#    define CLOB_COLON_ebx_ebp_r1X
#  else
#    define CLOB_COLON_ebx_ebp_r1X  : // clobbering ebp OR ebx OR r11_r12_r13
#  endif
#else
#  define CLOB_COLON_ebx_ebp        : // clobbering ebp OR ebx
#  define CLOB_COLON_ebx_ebp_r1X    : // clobbering ebp OR ebx OR r11_r12_r13
#endif

#endif // PNG_HAVE_MMX_READ_FILTER_ROW

#if defined(__PIC__)  // macros to save, restore index to Global Offset Table
#  if defined(__x86_64__)
#    define SAVE_GOT_ebx     "pushq %%rbx \n\t"
#    define RESTORE_GOT_ebx  "popq  %%rbx \n\t"
#  else
#    define SAVE_GOT_ebx     "pushl %%ebx \n\t"
#    define RESTORE_GOT_ebx  "popl  %%ebx \n\t"
#  endif
#  define _CLOBBER_GOT_ebx   // explicitly saved, restored => not clobbered
#  define CLOBBER_GOT_ebx
#else
#  define SAVE_GOT_ebx
#  define RESTORE_GOT_ebx
#  define _CLOBBER_GOT_ebx   ,"%ebx"
#  define CLOBBER_GOT_ebx    "%ebx"
#endif

#if defined(PNG_HAVE_MMX_COMBINE_ROW) || defined(PNG_HAVE_MMX_READ_INTERLACE)
#  define BPP2  2
#  define BPP3  3  // bytes per pixel (a.k.a. pixel_bytes)
#  define BPP4  4  // (defined only to help avoid cut-and-paste errors)
#  define BPP6  6
#  define BPP8  8
#endif



static int _mmx_supported = 2; // 0: no MMX; 1: MMX supported; 2: not tested

/*===========================================================================*/
/*                                                                           */
/*                      P N G _ M M X _ S U P P O R T                        */
/*                                                                           */
/*===========================================================================*/

// GRR NOTES:  (1) the following code assumes 386 or better (pushfl/popfl)
//             (2) all instructions compile with gcc 2.7.2.3 and later
//           x (3) the function is moved down here to prevent gcc from
//           x      inlining it in multiple places and then barfing be-
//           x      cause the ".NOT_SUPPORTED" label is multiply defined
//                  [need to retest with gcc 2.7.2.3]

// GRR 20070524:  This declaration apparently is compatible with but supersedes
//   the one in png.h; in any case, the generated object file is slightly
//   smaller.  It is unnecessary with gcc 4.1.2, but gcc 2.x apparently
//   replicated the ".NOT_SUPPORTED" label in each location the function was
//   inlined, leading to compilation errors due to the "multiply defined"
//   label.  Old workaround was to leave the function at the end of this
//   file; new one (still testing) is to use a gcc-specific function attribute
//   to prevent local inlining.
int PNGAPI
png_mmx_support(void) __attribute__((noinline));

int PNGAPI
png_mmx_support(void)
{
#if defined(PNG_MMX_CODE_SUPPORTED)  // superfluous, but what the heck
    int result;
    __asm__ __volatile__ (
#if defined(__x86_64__)
        "pushq %%rbx          \n\t"  // rbx gets clobbered by CPUID instruction
        "pushq %%rcx          \n\t"  // so does rcx...
        "pushq %%rdx          \n\t"  // ...and rdx (but rcx & rdx safe on Linux)
        "pushfq               \n\t"  // save Eflag to stack
        "popq %%rax           \n\t"  // get Eflag from stack into rax
        "movq %%rax, %%rcx    \n\t"  // make another copy of Eflag in rcx
        "xorl $0x200000, %%eax \n\t" // toggle ID bit in Eflag (i.e., bit 21)
        "pushq %%rax          \n\t"  // save modified Eflag back to stack
        "popfq                \n\t"  // restore modified value to Eflag reg
        "pushfq               \n\t"  // save Eflag to stack
        "popq %%rax           \n\t"  // get Eflag from stack
        "pushq %%rcx          \n\t"  // save original Eflag to stack
        "popfq                \n\t"  // restore original Eflag
#else
        "pushl %%ebx          \n\t"  // ebx gets clobbered by CPUID instruction
        "pushl %%ecx          \n\t"  // so does ecx...
        "pushl %%edx          \n\t"  // ...and edx (but ecx & edx safe on Linux)
        "pushfl               \n\t"  // save Eflag to stack
        "popl %%eax           \n\t"  // get Eflag from stack into eax
        "movl %%eax, %%ecx    \n\t"  // make another copy of Eflag in ecx
        "xorl $0x200000, %%eax \n\t" // toggle ID bit in Eflag (i.e., bit 21)
        "pushl %%eax          \n\t"  // save modified Eflag back to stack
        "popfl                \n\t"  // restore modified value to Eflag reg
        "pushfl               \n\t"  // save Eflag to stack
        "popl %%eax           \n\t"  // get Eflag from stack
        "pushl %%ecx          \n\t"  // save original Eflag to stack
        "popfl                \n\t"  // restore original Eflag
#endif
        "xorl %%ecx, %%eax    \n\t"  // compare new Eflag with original Eflag
        "jz 0f                \n\t"  // if same, CPUID instr. is not supported

        "xorl %%eax, %%eax    \n\t"  // set eax to zero
//      ".byte  0x0f, 0xa2    \n\t"  // CPUID instruction (two-byte opcode)
        "cpuid                \n\t"  // get the CPU identification info
        "cmpl $1, %%eax       \n\t"  // make sure eax return non-zero value
        "jl 0f                \n\t"  // if eax is zero, MMX is not supported

        "xorl %%eax, %%eax    \n\t"  // set eax to zero and...
        "incl %%eax           \n\t"  // ...increment eax to 1.  This pair is
                                     // faster than the instruction "mov eax, 1"
        "cpuid                \n\t"  // get the CPU identification info again
        "andl $0x800000, %%edx \n\t" // mask out all bits but MMX bit (23)
        "cmpl $0, %%edx       \n\t"  // 0 = MMX not supported
        "jz 0f                \n\t"  // non-zero = yes, MMX IS supported

        "movl $1, %%eax       \n\t"  // set return value to 1
        "jmp  1f              \n\t"  // DONE:  have MMX support

    "0:                       \n\t"  // .NOT_SUPPORTED: target label for jump instructions
        "movl $0, %%eax       \n\t"  // set return value to 0
    "1:                       \n\t"  // .RETURN: target label for jump instructions
#if defined(__x86_64__)
        "popq %%rdx           \n\t"  // restore rdx
        "popq %%rcx           \n\t"  // restore rcx
        "popq %%rbx           \n\t"  // restore rbx
#else
        "popl %%edx           \n\t"  // restore edx
        "popl %%ecx           \n\t"  // restore ecx
        "popl %%ebx           \n\t"  // restore ebx
#endif

//      "ret                  \n\t"  // DONE:  no MMX support
                                     // (fall through to standard C "ret")

        : "=a" (result)              // output list

        :                            // any variables used on input (none)

                                     // no clobber list
//      , "%ebx", "%ecx", "%edx"     // GRR:  we handle these manually
//      , "memory"   // if write to a variable gcc thought was in a reg
//      , "cc"       // "condition codes" (flag bits)
    );
    _mmx_supported = result;
#else
    _mmx_supported = 0;
#endif /* PNG_MMX_CODE_SUPPORTED */

    return _mmx_supported;
}


/*===========================================================================*/
/*                                                                           */
/*                       P N G _ C O M B I N E _ R O W                       */
/*                                                                           */
/*===========================================================================*/

#if defined(PNG_HAVE_MMX_COMBINE_ROW)

/* Combines the row recently read in with the previous row.
   This routine takes care of alpha and transparency if requested.
   This routine also handles the two methods of progressive display
   of interlaced images, depending on the mask value.
   The mask value describes which pixels are to be combined with
   the row.  The pattern always repeats every 8 pixels, so just 8
   bits are needed.  A one indicates the pixel is to be combined; a
   zero indicates the pixel is to be skipped.  This is in addition
   to any alpha or transparency value associated with the pixel.
   If you want all pixels to be combined, pass 0xff (255) in mask. */

/* Use this routine for the x86 platform - it uses a faster MMX routine
   if the machine supports MMX. */

void /* PRIVATE */
png_combine_row(png_structp png_ptr, png_bytep row, int mask)
{
   int dummy_value_a;    // fix 'forbidden register spilled' error
   int dummy_value_c;
   int dummy_value_d;
   png_bytep dummy_value_S;
   png_bytep dummy_value_D;

   png_debug(1, "in png_combine_row (pnggccrd.c)\n");

   if (_mmx_supported == 2) {
#if !defined(PNG_1_0_X)
       /* this should have happened in png_init_mmx_flags() already */
       png_warning(png_ptr, "asm_flags may not have been initialized");
#endif
       png_mmx_support();
   }

   if (mask == 0xff)
   {
      png_debug(2,"mask == 0xff:  doing single png_memcpy()\n");
      png_memcpy(row, png_ptr->row_buf + 1,
       (png_size_t)PNG_ROWBYTES(png_ptr->row_info.pixel_depth,png_ptr->width));
   }
   else   /* (png_combine_row() is never called with mask == 0) */
   {
      switch (png_ptr->row_info.pixel_depth)
      {
         case 24:       /* png_ptr->row_info.pixel_depth */
         {
            png_bytep srcptr;
            png_bytep dstptr;

#if !defined(PNG_1_0_X)
            if (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
#else
            if (_mmx_supported)
#endif
            {
               png_uint_32 len;
               int diff;

               srcptr = png_ptr->row_buf + 1;
               dstptr = row;
               len  = png_ptr->width & ~7;          // reduce to multiple of 8
               diff = (int) (png_ptr->width & 7);   // amount lost

               __asm__ __volatile__ (
                  "not       %%edx            \n\t" // mask => unmask
                  "movd      %%edx, %%mm7     \n\t" // load bit pattern
                  "not       %%edx            \n\t" // unmask => mask for later
                  "psubb     %%mm6, %%mm6     \n\t" // zero mm6
                  "punpcklbw %%mm7, %%mm7     \n\t"
                  "punpcklwd %%mm7, %%mm7     \n\t"
                  "punpckldq %%mm7, %%mm7     \n\t" // fill reg with 8 masks

                  LOAD_GOT_rbp
                  "movq   " MASK24_0 ", %%mm0 \n\t" // _mask24_0 -> mm0
                  "movq   " MASK24_1 ", %%mm1 \n\t" // _mask24_1 -> mm1
                  "movq   " MASK24_2 ", %%mm2 \n\t" // _mask24_2 -> mm2
                  RESTORE_rbp

                  "pand      %%mm7, %%mm0     \n\t"
                  "pand      %%mm7, %%mm1     \n\t"
                  "pand      %%mm7, %%mm2     \n\t"

                  "pcmpeqb   %%mm6, %%mm0     \n\t"
                  "pcmpeqb   %%mm6, %%mm1     \n\t"
                  "pcmpeqb   %%mm6, %%mm2     \n\t"

// preload        "movl      len, %%ecx       \n\t" // load length of line
// preload        "movl      srcptr, %3       \n\t" // load source
// preload        "movl      dstptr, %4       \n\t" // load dest

                  "cmpl      $0, %%ecx        \n\t"
                  "jz        mainloop24end    \n\t"

                "mainloop24:                  \n\t"
                  "movq      (%3), %%mm4      \n\t"
                  "pand      %%mm0, %%mm4     \n\t"
                  "movq      %%mm0, %%mm6     \n\t"
                  "movq      (%4), %%mm7      \n\t"
                  "pandn     %%mm7, %%mm6     \n\t"
                  "por       %%mm6, %%mm4     \n\t"
                  "movq      %%mm4, (%4)      \n\t"

                  "movq      8(%3), %%mm5     \n\t"
                  "pand      %%mm1, %%mm5     \n\t"
                  "movq      %%mm1, %%mm7     \n\t"
                  "movq      8(%4), %%mm6     \n\t"
                  "pandn     %%mm6, %%mm7     \n\t"
                  "por       %%mm7, %%mm5     \n\t"
                  "movq      %%mm5, 8(%4)     \n\t"

                  "movq      16(%3), %%mm6    \n\t"
                  "pand      %%mm2, %%mm6     \n\t"
                  "movq      %%mm2, %%mm4     \n\t"
                  "movq      16(%4), %%mm7    \n\t"
                  "pandn     %%mm7, %%mm4     \n\t"
                  "por       %%mm4, %%mm6     \n\t"
                  "movq      %%mm6, 16(%4)    \n\t"

                  "add       $24, %3          \n\t" // inc by 24 bytes processed
                  "add       $24, %4          \n\t"
                  "subl      $8, %%ecx        \n\t" // dec by 8 pixels processed

                  "ja        mainloop24       \n\t"

                "mainloop24end:               \n\t"
// preload        "movl      diff, %%ecx      \n\t" // (diff is in eax)
                  "movl      %%eax, %%ecx     \n\t"
                  "cmpl      $0, %%ecx        \n\t"
                  "jz        end24            \n\t"
// preload        "movl      mask, %%edx      \n\t"
                  "sall      $24, %%edx       \n\t" // make low byte, high byte

                "secondloop24:                \n\t"
                  "sall      %%edx            \n\t" // move high bit to CF
                  "jnc       skip24           \n\t" // if CF = 0
                  "movw      (%3), %%ax       \n\t"
                  "movw      %%ax, (%4)       \n\t"
                  "xorl      %%eax, %%eax     \n\t"
                  "movb      2(%3), %%al      \n\t"
                  "movb      %%al, 2(%4)      \n\t"

                "skip24:                      \n\t"
                  "add       $3, %3           \n\t"
                  "add       $3, %4           \n\t"
                  "decl      %%ecx            \n\t"
                  "jnz       secondloop24     \n\t"

                "end24:                       \n\t"
                  "EMMS                       \n\t" // DONE

                  : "=a" (dummy_value_a),           // output regs (dummy)
                    "=d" (dummy_value_d),
                    "=c" (dummy_value_c),
                    "=S" (dummy_value_S),
                    "=D" (dummy_value_D)

                  : "0" (diff),        // eax       // input regs
                    "1" (mask),        // edx
                    "2" (len),         // ecx
// was (unmask)     "b"    RESERVED    // ebx       // Global Offset Table idx
                    "3" (srcptr),      // esi/rsi
                    "4" (dstptr)       // edi/rdi

#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
                  : "%mm0", "%mm1", "%mm2"          // clobber list
                  , "%mm4", "%mm5", "%mm6", "%mm7"
#endif
               );
            }
            else /* not _mmx_supported - use modified C routine */
            {
               register png_uint_32 i;
               png_uint_32 initial_val = BPP3 * png_pass_start[png_ptr->pass];
                 /* png.c:  png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
               register int stride = BPP3 * png_pass_inc[png_ptr->pass];
                 /* png.c:  png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
               register int rep_bytes = BPP3 * png_pass_width[png_ptr->pass];
                 /* png.c:  png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
               png_uint_32 len = png_ptr->width &~7;  /* reduce to mult. of 8 */
               int diff = (int) (png_ptr->width & 7); /* amount lost */
               register png_uint_32 final_val = BPP3 * len;   /* GRR bugfix */

               srcptr = png_ptr->row_buf + 1 + initial_val;
               dstptr = row + initial_val;

               for (i = initial_val; i < final_val; i += stride)
               {
                  png_memcpy(dstptr, srcptr, rep_bytes);
                  srcptr += stride;
                  dstptr += stride;
               }
               if (diff)  /* number of leftover pixels:  3 for pngtest */
               {
                  final_val += diff*BPP3;
                  for (; i < final_val; i += stride)
                  {
                     if (rep_bytes > (int)(final_val-i))
                        rep_bytes = (int)(final_val-i);
                     png_memcpy(dstptr, srcptr, rep_bytes);
                     srcptr += stride;
                     dstptr += stride;
                  }
               }
            } /* end of else (_mmx_supported) */

            break;
         }       /* end 24 bpp */

         // formerly claimed to be most common case (combining 32-bit RGBA),
         // but almost certainly less common than 24-bit RGB case
         case 32:       /* png_ptr->row_info.pixel_depth */
         {
            png_bytep srcptr;
            png_bytep dstptr;

#if !defined(PNG_1_0_X)
            if (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
#else
            if (_mmx_supported)
#endif
            {
               png_uint_32 len;
               int diff;

               srcptr = png_ptr->row_buf + 1;
               dstptr = row;
               len  = png_ptr->width & ~7;          // reduce to multiple of 8
               diff = (int) (png_ptr->width & 7);   // amount lost

               __asm__ __volatile__ (
                  "not       %%edx            \n\t" // mask => unmask
                  "movd      %%edx, %%mm7     \n\t" // load bit pattern
                  "not       %%edx            \n\t" // unmask => mask for later
                  "psubb     %%mm6, %%mm6     \n\t" // zero mm6
                  "punpcklbw %%mm7, %%mm7     \n\t"
                  "punpcklwd %%mm7, %%mm7     \n\t"
                  "punpckldq %%mm7, %%mm7     \n\t" // fill reg with 8 masks

                  LOAD_GOT_rbp
                  "movq   " MASK32_0 ", %%mm0 \n\t" // _mask32_0
                  "movq   " MASK32_1 ", %%mm1 \n\t" // _mask32_1
                  "movq   " MASK32_2 ", %%mm2 \n\t" // _mask32_2
                  "movq   " MASK32_3 ", %%mm3 \n\t" // _mask32_3
                  RESTORE_rbp

                  "pand      %%mm7, %%mm0     \n\t"
                  "pand      %%mm7, %%mm1     \n\t"
                  "pand      %%mm7, %%mm2     \n\t"
                  "pand      %%mm7, %%mm3     \n\t"

                  "pcmpeqb   %%mm6, %%mm0     \n\t"
                  "pcmpeqb   %%mm6, %%mm1     \n\t"
                  "pcmpeqb   %%mm6, %%mm2     \n\t"
                  "pcmpeqb   %%mm6, %%mm3     \n\t"

// preload        "movl      len, %%ecx       \n\t" // load length of line
// preload        "movl      srcptr, %3       \n\t" // load source
// preload        "movl      dstptr, %4       \n\t" // load dest

                  "cmpl      $0, %%ecx        \n\t" // lcr
                  "jz        mainloop32end    \n\t"

                "mainloop32:                  \n\t"
                  "movq      (%3), %%mm4      \n\t"
                  "pand      %%mm0, %%mm4     \n\t"
                  "movq      %%mm0, %%mm6     \n\t"
                  "movq      (%4), %%mm7      \n\t"
                  "pandn     %%mm7, %%mm6     \n\t"
                  "por       %%mm6, %%mm4     \n\t"
                  "movq      %%mm4, (%4)      \n\t"

                  "movq      8(%3), %%mm5     \n\t"
                  "pand      %%mm1, %%mm5     \n\t"
                  "movq      %%mm1, %%mm7     \n\t"
                  "movq      8(%4), %%mm6     \n\t"
                  "pandn     %%mm6, %%mm7     \n\t"
                  "por       %%mm7, %%mm5     \n\t"
                  "movq      %%mm5, 8(%4)     \n\t"

                  "movq      16(%3), %%mm6    \n\t"
                  "pand      %%mm2, %%mm6     \n\t"
                  "movq      %%mm2, %%mm4     \n\t"
                  "movq      16(%4), %%mm7    \n\t"
                  "pandn     %%mm7, %%mm4     \n\t"
                  "por       %%mm4, %%mm6     \n\t"
                  "movq      %%mm6, 16(%4)    \n\t"

                  "movq      24(%3), %%mm7    \n\t"
                  "pand      %%mm3, %%mm7     \n\t"
                  "movq      %%mm3, %%mm5     \n\t"
                  "movq      24(%4), %%mm4    \n\t"
                  "pandn     %%mm4, %%mm5     \n\t"
                  "por       %%mm5, %%mm7     \n\t"
                  "movq      %%mm7, 24(%4)    \n\t"

                  "add       $32, %3          \n\t" // inc by 32 bytes processed
                  "add       $32, %4          \n\t"
                  "subl      $8, %%ecx        \n\t" // dec by 8 pixels processed
                  "ja        mainloop32       \n\t"

                "mainloop32end:               \n\t"
// preload        "movl      diff, %%ecx      \n\t" // (diff is in eax)
                  "movl      %%eax, %%ecx     \n\t"
                  "cmpl      $0, %%ecx        \n\t"
                  "jz        end32            \n\t"
// preload        "movl      mask, %%edx      \n\t"
                  "sall      $24, %%edx       \n\t" // low byte => high byte

                "secondloop32:                \n\t"
                  "sall      %%edx            \n\t" // move high bit to CF
                  "jnc       skip32           \n\t" // if CF = 0
                  "movl      (%3), %%eax      \n\t"
                  "movl      %%eax, (%4)      \n\t"

                "skip32:                      \n\t"
                  "add       $4, %3           \n\t"
                  "add       $4, %4           \n\t"
                  "decl      %%ecx            \n\t"
                  "jnz       secondloop32     \n\t"

                "end32:                       \n\t"
                  "EMMS                       \n\t" // DONE

                  : "=a" (dummy_value_a),           // output regs (dummy)
                    "=d" (dummy_value_d),
                    "=c" (dummy_value_c),
                    "=S" (dummy_value_S),
                    "=D" (dummy_value_D)

                  : "0" (diff),        // eax       // input regs
                    "1" (mask),        // edx
                    "2" (len),         // ecx
// was (unmask)     "b"    RESERVED    // ebx       // Global Offset Table idx
                    "3" (srcptr),      // esi/rsi
                    "4" (dstptr)       // edi/rdi

#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
                  : "%mm0", "%mm1", "%mm2", "%mm3"  // clobber list
                  , "%mm4", "%mm5", "%mm6", "%mm7"
#endif
               );
            }
            else /* not _mmx_supported - use modified C routine */
            {
               register png_uint_32 i;
               png_uint_32 initial_val = BPP4 * png_pass_start[png_ptr->pass];
                 /* png.c:  png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
               register int stride = BPP4 * png_pass_inc[png_ptr->pass];
                 /* png.c:  png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
               register int rep_bytes = BPP4 * png_pass_width[png_ptr->pass];
                 /* png.c:  png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
               png_uint_32 len = png_ptr->width &~7;  /* reduce to mult. of 8 */
               int diff = (int) (png_ptr->width & 7); /* amount lost */
               register png_uint_32 final_val = BPP4 * len;   /* GRR bugfix */

               srcptr = png_ptr->row_buf + 1 + initial_val;
               dstptr = row + initial_val;

               for (i = initial_val; i < final_val; i += stride)
               {
                  png_memcpy(dstptr, srcptr, rep_bytes);
                  srcptr += stride;
                  dstptr += stride;
               }
               if (diff)  /* number of leftover pixels:  3 for pngtest */
               {
                  final_val += diff*BPP4;
                  for (; i < final_val; i += stride)
                  {
                     if (rep_bytes > (int)(final_val-i))
                        rep_bytes = (int)(final_val-i);
                     png_memcpy(dstptr, srcptr, rep_bytes);
                     srcptr += stride;
                     dstptr += stride;
                  }
               }
            } /* end of else (_mmx_supported) */

            break;
         }       /* end 32 bpp */

         case 8:        /* png_ptr->row_info.pixel_depth */
         {
            png_bytep srcptr;
            png_bytep dstptr;

#if !defined(PNG_1_0_X)
            if (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
#else
            if (_mmx_supported)
#endif
            {
               png_uint_32 len;
               int diff;

               srcptr = png_ptr->row_buf + 1;
               dstptr = row;
               len  = png_ptr->width & ~7;          // reduce to multiple of 8
               diff = (int) (png_ptr->width & 7);   // amount lost

               __asm__ __volatile__ (
                  "not       %%edx            \n\t" // mask => unmask
                  "movd      %%edx, %%mm7     \n\t" // load bit pattern
                  "not       %%edx            \n\t" // unmask => mask for later
                  "psubb     %%mm6, %%mm6     \n\t" // zero mm6
                  "punpcklbw %%mm7, %%mm7     \n\t"
                  "punpcklwd %%mm7, %%mm7     \n\t"
                  "punpckldq %%mm7, %%mm7     \n\t" // fill reg with 8 masks

                  LOAD_GOT_rbp
                  "movq   " MASK8_0 ", %%mm0  \n\t" // _mask8_0 -> mm0
                  RESTORE_rbp

                  "pand      %%mm7, %%mm0     \n\t" // nonzero if keep byte
                  "pcmpeqb   %%mm6, %%mm0     \n\t" // zeros->1s, v versa

// preload        "movl      len, %%ecx       \n\t" // load length of line
// preload        "movl      srcptr, %3       \n\t" // load source
// preload        "movl      dstptr, %4       \n\t" // load dest

                  "cmpl      $0, %%ecx        \n\t" // len == 0 ?
                  "je        mainloop8end     \n\t"

                "mainloop8:                   \n\t"
                  "movq      (%3), %%mm4      \n\t" // *srcptr
                  "pand      %%mm0, %%mm4     \n\t"
                  "movq      %%mm0, %%mm6     \n\t"
                  "pandn     (%4), %%mm6      \n\t" // *dstptr
                  "por       %%mm6, %%mm4     \n\t"
                  "movq      %%mm4, (%4)      \n\t"
                  "add       $8, %3           \n\t" // inc by 8 bytes processed
                  "add       $8, %4           \n\t"
                  "subl      $8, %%ecx        \n\t" // dec by 8 pixels processed
                  "ja        mainloop8        \n\t"

                "mainloop8end:                \n\t"
// preload        "movl      diff, %%ecx      \n\t" // (diff is in eax)
                  "movl      %%eax, %%ecx     \n\t"
                  "cmpl      $0, %%ecx        \n\t"
                  "jz        end8             \n\t"
// preload        "movl      mask, %%edx      \n\t"
                  "sall      $24, %%edx       \n\t" // make low byte, high byte

                "secondloop8:                 \n\t"
                  "sall      %%edx            \n\t" // move high bit to CF
                  "jnc       skip8            \n\t" // if CF = 0
                  "movb      (%3), %%al       \n\t"
                  "movb      %%al, (%4)       \n\t"

                "skip8:                       \n\t"
                  "inc       %3               \n\t"
                  "inc       %4               \n\t"
                  "decl      %%ecx            \n\t"
                  "jnz       secondloop8      \n\t"

                "end8:                        \n\t"
                  "EMMS                       \n\t" // DONE

                  : "=a" (dummy_value_a),           // output regs (dummy)
                    "=d" (dummy_value_d),
                    "=c" (dummy_value_c),
                    "=S" (dummy_value_S),
                    "=D" (dummy_value_D)

                  : "0" (diff),        // eax       // input regs
                    "1" (mask),        // edx
                    "2" (len),         // ecx
// was (unmask)     "b"    RESERVED    // ebx       // Global Offset Table idx
                    "3" (srcptr),      // esi/rsi
                    "4" (dstptr)       // edi/rdi

#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
                  : "%mm0", "%mm4", "%mm6", "%mm7"  // clobber list
#endif
               );
            }
            else /* not _mmx_supported - use modified C routine */
            {
               register png_uint_32 i;
               png_uint_32 initial_val = png_pass_start[png_ptr->pass];
                 /* png.c:  png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
               register int stride = png_pass_inc[png_ptr->pass];
                 /* png.c:  png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
               register int rep_bytes = png_pass_width[png_ptr->pass];
                 /* png.c:  png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
               png_uint_32 len = png_ptr->width &~7;  /* reduce to mult. of 8 */
               int diff = (int) (png_ptr->width & 7); /* amount lost */
               register png_uint_32 final_val = len;  /* GRR bugfix */

               srcptr = png_ptr->row_buf + 1 + initial_val;
               dstptr = row + initial_val;

               for (i = initial_val; i < final_val; i += stride)
               {
                  png_memcpy(dstptr, srcptr, rep_bytes);
                  srcptr += stride;
                  dstptr += stride;
               }
               if (diff)  /* number of leftover pixels:  3 for pngtest */
               {
                  final_val += diff /* *BPP1 */ ;
                  for (; i < final_val; i += stride)
                  {
                     if (rep_bytes > (int)(final_val-i))
                        rep_bytes = (int)(final_val-i);
                     png_memcpy(dstptr, srcptr, rep_bytes);
                     srcptr += stride;
                     dstptr += stride;
                  }
               }

            } /* end of else (_mmx_supported) */

            break;
         }       /* end 8 bpp */

         case 1:        /* png_ptr->row_info.pixel_depth */
         {
            png_bytep sp;
            png_bytep dp;
            int s_inc, s_start, s_end;
            int m;
            int shift;
            png_uint_32 i;

            sp = png_ptr->row_buf + 1;
            dp = row;
            m = 0x80;
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
            if (png_ptr->transformations & PNG_PACKSWAP)
            {
               s_start = 0;
               s_end = 7;
               s_inc = 1;
            }
            else
#endif
            {
               s_start = 7;
               s_end = 0;
               s_inc = -1;
            }

            shift = s_start;

            for (i = 0; i < png_ptr->width; i++)
            {
               if (m & mask)
               {
                  int value;

                  value = (*sp >> shift) & 0x1;
                  *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
                  *dp |= (png_byte)(value << shift);
               }

               if (shift == s_end)
               {
                  shift = s_start;
                  sp++;
                  dp++;
               }
               else
                  shift += s_inc;

               if (m == 1)
                  m = 0x80;
               else
                  m >>= 1;
            }
            break;
         }       /* end 1 bpp */

         case 2:        /* png_ptr->row_info.pixel_depth */
         {
            png_bytep sp;
            png_bytep dp;
            int s_start, s_end, s_inc;
            int m;
            int shift;
            png_uint_32 i;
            int value;

            sp = png_ptr->row_buf + 1;
            dp = row;
            m = 0x80;
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
            if (png_ptr->transformations & PNG_PACKSWAP)
            {
               s_start = 0;
               s_end = 6;
               s_inc = 2;
            }
            else
#endif
            {
               s_start = 6;
               s_end = 0;
               s_inc = -2;
            }

            shift = s_start;

            for (i = 0; i < png_ptr->width; i++)
            {
               if (m & mask)
               {
                  value = (*sp >> shift) & 0x3;
                  *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
                  *dp |= (png_byte)(value << shift);
               }

               if (shift == s_end)
               {
                  shift = s_start;
                  sp++;
                  dp++;
               }
               else
                  shift += s_inc;
               if (m == 1)
                  m = 0x80;
               else
                  m >>= 1;
            }
            break;
         }       /* end 2 bpp */

         case 4:        /* png_ptr->row_info.pixel_depth */
         {
            png_bytep sp;
            png_bytep dp;
            int s_start, s_end, s_inc;
            int m;
            int shift;
            png_uint_32 i;
            int value;

            sp = png_ptr->row_buf + 1;
            dp = row;
            m = 0x80;
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
            if (png_ptr->transformations & PNG_PACKSWAP)
            {
               s_start = 0;
               s_end = 4;
               s_inc = 4;
            }
            else
#endif
            {
               s_start = 4;
               s_end = 0;
               s_inc = -4;
            }

            shift = s_start;

            for (i = 0; i < png_ptr->width; i++)
            {
               if (m & mask)
               {
                  value = (*sp >> shift) & 0xf;
                  *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
                  *dp |= (png_byte)(value << shift);
               }

               if (shift == s_end)
               {
                  shift = s_start;
                  sp++;
                  dp++;
               }
               else
                  shift += s_inc;
               if (m == 1)
                  m = 0x80;
               else
                  m >>= 1;
            }
            break;
         }       /* end 4 bpp */

         case 16:       /* png_ptr->row_info.pixel_depth */
         {
            png_bytep srcptr;
            png_bytep dstptr;

#if !defined(PNG_1_0_X)
            if (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
#else
            if (_mmx_supported)
#endif
            {
               png_uint_32 len;
               int diff;

               srcptr = png_ptr->row_buf + 1;
               dstptr = row;
               len  = png_ptr->width & ~7;          // reduce to multiple of 8
               diff = (int) (png_ptr->width & 7);   // amount lost

               __asm__ __volatile__ (
                  "not       %%edx            \n\t" // mask => unmask
                  "movd      %%edx, %%mm7     \n\t" // load bit pattern
                  "not       %%edx            \n\t" // unmask => mask for later
                  "psubb     %%mm6, %%mm6     \n\t" // zero mm6
                  "punpcklbw %%mm7, %%mm7     \n\t"
                  "punpcklwd %%mm7, %%mm7     \n\t"
                  "punpckldq %%mm7, %%mm7     \n\t" // fill reg with 8 masks

                  LOAD_GOT_rbp
                  "movq   " MASK16_0 ", %%mm0 \n\t" // _mask16_0 -> mm0
                  "movq   " MASK16_1 ", %%mm1 \n\t" // _mask16_1 -> mm1
                  RESTORE_rbp

                  "pand      %%mm7, %%mm0     \n\t"
                  "pand      %%mm7, %%mm1     \n\t"

                  "pcmpeqb   %%mm6, %%mm0     \n\t"
                  "pcmpeqb   %%mm6, %%mm1     \n\t"

// preload        "movl      len, %%ecx       \n\t" // load length of line
// preload        "movl      srcptr, %3       \n\t" // load source
// preload        "movl      dstptr, %4       \n\t" // load dest

                  "cmpl      $0, %%ecx        \n\t"
                  "jz        mainloop16end    \n\t"

                "mainloop16:                  \n\t"
                  "movq      (%3), %%mm4      \n\t"
                  "pand      %%mm0, %%mm4     \n\t"
                  "movq      %%mm0, %%mm6     \n\t"
                  "movq      (%4), %%mm7      \n\t"
                  "pandn     %%mm7, %%mm6     \n\t"
                  "por       %%mm6, %%mm4     \n\t"
                  "movq      %%mm4, (%4)      \n\t"

                  "movq      8(%3), %%mm5     \n\t"
                  "pand      %%mm1, %%mm5     \n\t"
                  "movq      %%mm1, %%mm7     \n\t"
                  "movq      8(%4), %%mm6     \n\t"
                  "pandn     %%mm6, %%mm7     \n\t"
                  "por       %%mm7, %%mm5     \n\t"
                  "movq      %%mm5, 8(%4)     \n\t"

                  "add       $16, %3          \n\t" // inc by 16 bytes processed
                  "add       $16, %4          \n\t"
                  "subl      $8, %%ecx        \n\t" // dec by 8 pixels processed
                  "ja        mainloop16       \n\t"

                "mainloop16end:               \n\t"
// preload        "movl      diff, %%ecx      \n\t" // (diff is in eax)
                  "movl      %%eax, %%ecx     \n\t"
                  "cmpl      $0, %%ecx        \n\t"
                  "jz        end16            \n\t"
// preload        "movl      mask, %%edx      \n\t"
                  "sall      $24, %%edx       \n\t" // make low byte, high byte

                "secondloop16:                \n\t"
                  "sall      %%edx            \n\t" // move high bit to CF
                  "jnc       skip16           \n\t" // if CF = 0
                  "movw      (%3), %%ax       \n\t"
                  "movw      %%ax, (%4)       \n\t"

                "skip16:                      \n\t"
                  "add       $2, %3           \n\t"
                  "add       $2, %4           \n\t"
                  "decl      %%ecx            \n\t"
                  "jnz       secondloop16     \n\t"

                "end16:                       \n\t"
                  "EMMS                       \n\t" // DONE

                  : "=a" (dummy_value_a),           // output regs (dummy)
                    "=d" (dummy_value_d),
                    "=c" (dummy_value_c),
                    "=S" (dummy_value_S),
                    "=D" (dummy_value_D)

                  : "0" (diff),        // eax       // input regs
                    "1" (mask),        // edx
                    "2" (len),         // ecx
// was (unmask)     "b"    RESERVED    // ebx       // Global Offset Table idx
                    "3" (srcptr),      // esi/rsi
                    "4" (dstptr)       // edi/rdi

#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
                  : "%mm0", "%mm1", "%mm4"          // clobber list
                  , "%mm5", "%mm6", "%mm7"
#endif
               );
            }
            else /* not _mmx_supported - use modified C routine */
            {
               register png_uint_32 i;
               png_uint_32 initial_val = BPP2 * png_pass_start[png_ptr->pass];
                 /* png.c:  png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
               register int stride = BPP2 * png_pass_inc[png_ptr->pass];
                 /* png.c:  png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
               register int rep_bytes = BPP2 * png_pass_width[png_ptr->pass];
                 /* png.c:  png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
               png_uint_32 len = png_ptr->width &~7;  /* reduce to mult. of 8 */
               int diff = (int) (png_ptr->width & 7); /* amount lost */
               register png_uint_32 final_val = BPP2 * len;   /* GRR bugfix */

               srcptr = png_ptr->row_buf + 1 + initial_val;
               dstptr = row + initial_val;

               for (i = initial_val; i < final_val; i += stride)
               {
                  png_memcpy(dstptr, srcptr, rep_bytes);
                  srcptr += stride;
                  dstptr += stride;
               }
               if (diff)  /* number of leftover pixels:  3 for pngtest */
               {
                  final_val += diff*BPP2;
                  for (; i < final_val; i += stride)
                  {
                     if (rep_bytes > (int)(final_val-i))
                        rep_bytes = (int)(final_val-i);
                     png_memcpy(dstptr, srcptr, rep_bytes);
                     srcptr += stride;
                     dstptr += stride;
                  }
               }
            } /* end of else (_mmx_supported) */

            break;
         }       /* end 16 bpp */

         case 48:       /* png_ptr->row_info.pixel_depth */
         {
            png_bytep srcptr;
            png_bytep dstptr;

#if !defined(PNG_1_0_X)
            if (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
#else
            if (_mmx_supported)
#endif
            {
               png_uint_32 len;
               int diff;

               srcptr = png_ptr->row_buf + 1;
               dstptr = row;
               len  = png_ptr->width & ~7;          // reduce to multiple of 8
               diff = (int) (png_ptr->width & 7);   // amount lost

               __asm__ __volatile__ (
                  "not       %%edx            \n\t" // mask => unmask
                  "movd      %%edx, %%mm7     \n\t" // load bit pattern
                  "not       %%edx            \n\t" // unmask => mask for later
                  "psubb     %%mm6, %%mm6     \n\t" // zero mm6
                  "punpcklbw %%mm7, %%mm7     \n\t"
                  "punpcklwd %%mm7, %%mm7     \n\t"
                  "punpckldq %%mm7, %%mm7     \n\t" // fill reg with 8 masks

                  LOAD_GOT_rbp
                  "movq   " MASK48_0 ", %%mm0 \n\t" // _mask48_0 -> mm0
                  "movq   " MASK48_1 ", %%mm1 \n\t" // _mask48_1 -> mm1
                  "movq   " MASK48_2 ", %%mm2 \n\t" // _mask48_2 -> mm2
                  "movq   " MASK48_3 ", %%mm3 \n\t" // _mask48_3 -> mm3
                  "movq   " MASK48_4 ", %%mm4 \n\t" // _mask48_4 -> mm4
                  "movq   " MASK48_5 ", %%mm5 \n\t" // _mask48_5 -> mm5
                  RESTORE_rbp

                  "pand      %%mm7, %%mm0     \n\t"
                  "pand      %%mm7, %%mm1     \n\t"
                  "pand      %%mm7, %%mm2     \n\t"
                  "pand      %%mm7, %%mm3     \n\t"
                  "pand      %%mm7, %%mm4     \n\t"
                  "pand      %%mm7, %%mm5     \n\t"

                  "pcmpeqb   %%mm6, %%mm0     \n\t"
                  "pcmpeqb   %%mm6, %%mm1     \n\t"
                  "pcmpeqb   %%mm6, %%mm2     \n\t"
                  "pcmpeqb   %%mm6, %%mm3     \n\t"
                  "pcmpeqb   %%mm6, %%mm4     \n\t"
                  "pcmpeqb   %%mm6, %%mm5     \n\t"

// preload        "movl      len, %%ecx       \n\t" // load length of line
// preload        "movl      srcptr, %3       \n\t" // load source
// preload        "movl      dstptr, %4       \n\t" // load dest

                  "cmpl      $0, %%ecx        \n\t"
                  "jz        mainloop48end    \n\t"

                "mainloop48:                  \n\t"
                  "movq      (%3), %%mm7      \n\t"
                  "pand      %%mm0, %%mm7     \n\t"
                  "movq      %%mm0, %%mm6     \n\t"
                  "pandn     (%4), %%mm6      \n\t"
                  "por       %%mm6, %%mm7     \n\t"
                  "movq      %%mm7, (%4)      \n\t"

                  "movq      8(%3), %%mm6     \n\t"
                  "pand      %%mm1, %%mm6     \n\t"
                  "movq      %%mm1, %%mm7     \n\t"
                  "pandn     8(%4), %%mm7     \n\t"
                  "por       %%mm7, %%mm6     \n\t"
                  "movq      %%mm6, 8(%4)     \n\t"

                  "movq      16(%3), %%mm6    \n\t"
                  "pand      %%mm2, %%mm6     \n\t"
                  "movq      %%mm2, %%mm7     \n\t"
                  "pandn     16(%4), %%mm7    \n\t"
                  "por       %%mm7, %%mm6     \n\t"
                  "movq      %%mm6, 16(%4)    \n\t"

                  "movq      24(%3), %%mm7    \n\t"
                  "pand      %%mm3, %%mm7     \n\t"
                  "movq      %%mm3, %%mm6     \n\t"
                  "pandn     24(%4), %%mm6    \n\t"
                  "por       %%mm6, %%mm7     \n\t"
                  "movq      %%mm7, 24(%4)    \n\t"

                  "movq      32(%3), %%mm6    \n\t"
                  "pand      %%mm4, %%mm6     \n\t"
                  "movq      %%mm4, %%mm7     \n\t"
                  "pandn     32(%4), %%mm7    \n\t"
                  "por       %%mm7, %%mm6     \n\t"
                  "movq      %%mm6, 32(%4)    \n\t"

                  "movq      40(%3), %%mm7    \n\t"
                  "pand      %%mm5, %%mm7     \n\t"
                  "movq      %%mm5, %%mm6     \n\t"
                  "pandn     40(%4), %%mm6    \n\t"
                  "por       %%mm6, %%mm7     \n\t"
                  "movq      %%mm7, 40(%4)    \n\t"

                  "add       $48, %3          \n\t" // inc by 48 bytes processed
                  "add       $48, %4          \n\t"
                  "subl      $8, %%ecx        \n\t" // dec by 8 pixels processed

                  "ja        mainloop48       \n\t"

                "mainloop48end:               \n\t"
// preload        "movl      diff, %%ecx      \n\t" // (diff is in eax)
                  "movl      %%eax, %%ecx     \n\t"
                  "cmpl      $0, %%ecx        \n\t"
                  "jz        end48            \n\t"
// preload        "movl      mask, %%edx      \n\t"
                  "sall      $24, %%edx       \n\t" // make low byte, high byte

                "secondloop48:                \n\t"
                  "sall      %%edx            \n\t" // move high bit to CF
                  "jnc       skip48           \n\t" // if CF = 0
                  "movl      (%3), %%eax      \n\t"
                  "movl      %%eax, (%4)      \n\t"
                  "movw      4(%3), %%ax      \n\t" // GR-P bugfix 20070717
                  "movw      %%ax, 4(%4)      \n\t" // GR-P bugfix 20070717

                "skip48:                      \n\t"
                  "add       $6, %3           \n\t" // GR-P bugfix 20070717
                  "add       $6, %4           \n\t" // GR-P bugfix 20070717
                  "decl      %%ecx            \n\t"
                  "jnz       secondloop48     \n\t"

                "end48:                       \n\t"
                  "EMMS                       \n\t" // DONE

                  : "=a" (dummy_value_a),           // output regs (dummy)
                    "=d" (dummy_value_d),
                    "=c" (dummy_value_c),
                    "=S" (dummy_value_S),
                    "=D" (dummy_value_D)

                  : "0" (diff),        // eax       // input regs
                    "1" (mask),        // edx
                    "2" (len),         // ecx
// was (unmask)     "b"    RESERVED    // ebx       // Global Offset Table idx
                    "3" (srcptr),      // esi/rsi
                    "4" (dstptr)       // edi/rdi

#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
                  : "%mm0", "%mm1", "%mm2", "%mm3"  // clobber list
                  , "%mm4", "%mm5", "%mm6", "%mm7"
#endif
               );
            }
            else /* not _mmx_supported - use modified C routine */
            {
               register png_uint_32 i;
               png_uint_32 initial_val = BPP6 * png_pass_start[png_ptr->pass];
                 /* png.c:  png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
               register int stride = BPP6 * png_pass_inc[png_ptr->pass];
                 /* png.c:  png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
               register int rep_bytes = BPP6 * png_pass_width[png_ptr->pass];
                 /* png.c:  png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
               png_uint_32 len = png_ptr->width &~7;  /* reduce to mult. of 8 */
               int diff = (int) (png_ptr->width & 7); /* amount lost */
               register png_uint_32 final_val = BPP6 * len;   /* GRR bugfix */

               srcptr = png_ptr->row_buf + 1 + initial_val;
               dstptr = row + initial_val;

               for (i = initial_val; i < final_val; i += stride)
               {
                  png_memcpy(dstptr, srcptr, rep_bytes);
                  srcptr += stride;
                  dstptr += stride;
               }
               if (diff)  /* number of leftover pixels:  3 for pngtest */
               {
                  final_val += diff*BPP6;
                  for (; i < final_val; i += stride)
                  {
                     if (rep_bytes > (int)(final_val-i))
                        rep_bytes = (int)(final_val-i);
                     png_memcpy(dstptr, srcptr, rep_bytes);
                     srcptr += stride;
                     dstptr += stride;
                  }
               }
            } /* end of else (_mmx_supported) */

            break;
         }       /* end 48 bpp */

         case 64:       /* png_ptr->row_info.pixel_depth */
         {
            png_bytep srcptr;
            png_bytep dstptr;
            register png_uint_32 i;
            png_uint_32 initial_val = BPP8 * png_pass_start[png_ptr->pass];
              /* png.c:  png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
            register int stride = BPP8 * png_pass_inc[png_ptr->pass];
              /* png.c:  png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
            register int rep_bytes = BPP8 * png_pass_width[png_ptr->pass];
              /* png.c:  png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
            png_uint_32 len = png_ptr->width &~7;  /* reduce to mult. of 8 */
            int diff = (int) (png_ptr->width & 7); /* amount lost */
            register png_uint_32 final_val = BPP8 * len;   /* GRR bugfix */

            srcptr = png_ptr->row_buf + 1 + initial_val;
            dstptr = row + initial_val;

            for (i = initial_val; i < final_val; i += stride)
            {
               png_memcpy(dstptr, srcptr, rep_bytes);
               srcptr += stride;
               dstptr += stride;
            }
            if (diff)  /* number of leftover pixels:  3 for pngtest */
            {
               final_val += diff*BPP8;
               for (; i < final_val; i += stride)
               {
                  if (rep_bytes > (int)(final_val-i))
                     rep_bytes = (int)(final_val-i);
                  png_memcpy(dstptr, srcptr, rep_bytes);
                  srcptr += stride;
                  dstptr += stride;
               }
            }

            break;
         }       /* end 64 bpp */

         default: /* png_ptr->row_info.pixel_depth != 1,2,4,8,16,24,32,48,64 */
         {
            // ERROR:  SHOULD NEVER BE REACHED
#if defined(PNG_DEBUG)
            png_debug(1, "Internal libpng logic error (GCC "
              "png_combine_row() pixel_depth)\n");
#endif
            break;
         }
      } /* end switch (png_ptr->row_info.pixel_depth) */

   } /* end if (non-trivial mask) */

} /* end png_combine_row() */

#endif /* PNG_HAVE_MMX_COMBINE_ROW */




/*===========================================================================*/
/*                                                                           */
/*                 P N G _ D O _ R E A D _ I N T E R L A C E                 */
/*                                                                           */
/*===========================================================================*/

#if defined(PNG_READ_INTERLACING_SUPPORTED)
#if defined(PNG_HAVE_MMX_READ_INTERLACE)

/* png_do_read_interlace() is called after any 16-bit to 8-bit conversion
 * has taken place.  [GRR: what other steps come before and/or after?]
 */

void /* PRIVATE */
png_do_read_interlace(png_structp png_ptr)
{
   png_row_infop row_info = &(png_ptr->row_info);
   png_bytep row = png_ptr->row_buf + 1;
   int pass = png_ptr->pass;
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
   png_uint_32 transformations = png_ptr->transformations;
#endif

   png_debug(1, "in png_do_read_interlace (pnggccrd.c)\n");

   if (_mmx_supported == 2) {
#if !defined(PNG_1_0_X)
       /* this should have happened in png_init_mmx_flags() already */
       png_warning(png_ptr, "asm_flags may not have been initialized");
#endif
       png_mmx_support();
   }

   if (row != NULL && row_info != NULL)
   {
      png_uint_32 final_width;

      final_width = row_info->width * png_pass_inc[pass];

      switch (row_info->pixel_depth)
      {
         case 1:
         {
            png_bytep sp, dp;
            int sshift, dshift;
            int s_start, s_end, s_inc;
            png_byte v;
            png_uint_32 i;
            int j;

            sp = row + (png_size_t)((row_info->width - 1) >> 3);
            dp = row + (png_size_t)((final_width - 1) >> 3);
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
            if (transformations & PNG_PACKSWAP)
            {
               sshift = (int)((row_info->width + 7) & 7);
               dshift = (int)((final_width + 7) & 7);
               s_start = 7;
               s_end = 0;
               s_inc = -1;
            }
            else
#endif
            {
               sshift = 7 - (int)((row_info->width + 7) & 7);
               dshift = 7 - (int)((final_width + 7) & 7);
               s_start = 0;
               s_end = 7;
               s_inc = 1;
            }

            for (i = row_info->width; i; i--)
            {
               v = (png_byte)((*sp >> sshift) & 0x1);
               for (j = 0; j < png_pass_inc[pass]; j++)
               {
                  *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
                  *dp |= (png_byte)(v << dshift);
                  if (dshift == s_end)
                  {
                     dshift = s_start;
                     dp--;
                  }
                  else
                     dshift += s_inc;
               }
               if (sshift == s_end)
               {
                  sshift = s_start;
                  sp--;
               }
               else
                  sshift += s_inc;
            }
            break;
         }

         case 2:
         {
            png_bytep sp, dp;
            int sshift, dshift;
            int s_start, s_end, s_inc;
            png_uint_32 i;

            sp = row + (png_size_t)((row_info->width - 1) >> 2);
            dp = row + (png_size_t)((final_width - 1) >> 2);
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
            if (transformations & PNG_PACKSWAP)
            {
               sshift = (png_size_t)(((row_info->width + 3) & 3) << 1);
               dshift = (png_size_t)(((final_width + 3) & 3) << 1);
               s_start = 6;
               s_end = 0;
               s_inc = -2;
            }
            else
#endif
            {
               sshift = (png_size_t)((3 - ((row_info->width + 3) & 3)) << 1);
               dshift = (png_size_t)((3 - ((final_width + 3) & 3)) << 1);
               s_start = 0;
               s_end = 6;
               s_inc = 2;
            }

            for (i = row_info->width; i; i--)
            {
               png_byte v;
               int j;

               v = (png_byte)((*sp >> sshift) & 0x3);
               for (j = 0; j < png_pass_inc[pass]; j++)
               {
                  *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
                  *dp |= (png_byte)(v << dshift);
                  if (dshift == s_end)
                  {
                     dshift = s_start;
                     dp--;
                  }
                  else
                     dshift += s_inc;
               }
               if (sshift == s_end)
               {
                  sshift = s_start;
                  sp--;
               }
               else
                  sshift += s_inc;
            }
            break;
         }

         case 4:
         {
            png_bytep sp, dp;
            int sshift, dshift;
            int s_start, s_end, s_inc;
            png_uint_32 i;

            sp = row + (png_size_t)((row_info->width - 1) >> 1);
            dp = row + (png_size_t)((final_width - 1) >> 1);
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
            if (transformations & PNG_PACKSWAP)
            {
               sshift = (png_size_t)(((row_info->width + 1) & 1) << 2);
               dshift = (png_size_t)(((final_width + 1) & 1) << 2);
               s_start = 4;
               s_end = 0;
               s_inc = -4;
            }
            else
#endif
            {
               sshift = (png_size_t)((1 - ((row_info->width + 1) & 1)) << 2);
               dshift = (png_size_t)((1 - ((final_width + 1) & 1)) << 2);
               s_start = 0;
               s_end = 4;
               s_inc = 4;
            }

            for (i = row_info->width; i; i--)
            {
               png_byte v;
               int j;

               v = (png_byte)((*sp >> sshift) & 0xf);
               for (j = 0; j < png_pass_inc[pass]; j++)
               {
                  *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
                  *dp |= (png_byte)(v << dshift);
                  if (dshift == s_end)
                  {
                     dshift = s_start;
                     dp--;
                  }
                  else
                     dshift += s_inc;
               }
               if (sshift == s_end)
               {
                  sshift = s_start;
                  sp--;
               }
               else
                  sshift += s_inc;
            }
            break;
         }

       /*====================================================================*/

         default: /* 8-bit or larger (this is where the routine is modified) */
         {
            png_bytep sptr, dp;
            png_uint_32 i;
            png_size_t pixel_bytes;
            int width = (int)row_info->width;

            pixel_bytes = (row_info->pixel_depth >> 3);

            /* point sptr at the last pixel in the pre-expanded row: */
            sptr = row + (width - 1) * pixel_bytes;

            /* point dp at the last pixel position in the expanded row: */
            dp = row + (final_width - 1) * pixel_bytes;

            /* New code by Nirav Chhatrapati - Intel Corporation */

#if !defined(PNG_1_0_X)
            if (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_INTERLACE)
#else
            if (_mmx_supported)
#endif
            {
               int dummy_value_c;        // fix 'forbidden register spilled'
               png_bytep dummy_value_S;
               png_bytep dummy_value_D;
               png_bytep dummy_value_a;
               png_bytep dummy_value_d;

               //--------------------------------------------------------------
               if (pixel_bytes == BPP3)
               {
                  if (((pass == 4) || (pass == 5)) && width)
                  {
                     int width_mmx = ((width >> 1) << 1) - 8;   // GRR:  huh?
                     if (width_mmx < 0)
                         width_mmx = 0;
                     width -= width_mmx;        // 8 or 9 pix, 24 or 27 bytes
                     if (width_mmx)
                     {
                        // png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
                        // sptr points at last pixel in pre-expanded row
                        // dp points at last pixel position in expanded row
                        __asm__ __volatile__ (
                           "sub  $3, %1             \n\t"
                           "sub  $9, %2             \n\t"
                                        // (png_pass_inc[pass] + 1)*pixel_bytes

                        ".loop3_pass4:              \n\t"
                           "movq (%1), %%mm0        \n\t" // x x 5 4 3 2 1 0
                           "movq %%mm0, %%mm1       \n\t" // x x 5 4 3 2 1 0
                           "movq %%mm0, %%mm2       \n\t" // x x 5 4 3 2 1 0
                           "psllq $24, %%mm0        \n\t" // 4 3 2 1 0 z z z
                           "pand (%3), %%mm1        \n\t" // z z z z z 2 1 0
                           "psrlq $24, %%mm2        \n\t" // z z z x x 5 4 3
                           "por %%mm1, %%mm0        \n\t" // 4 3 2 1 0 2 1 0
                           "movq %%mm2, %%mm3       \n\t" // z z z x x 5 4 3
                           "psllq $8, %%mm2         \n\t" // z z x x 5 4 3 z
                           "movq %%mm0, (%2)        \n\t"
                           "psrlq $16, %%mm3        \n\t" // z z z z z x x 5
                           "pand (%4), %%mm3        \n\t" // z z z z z z z 5
                           "por %%mm3, %%mm2        \n\t" // z z x x 5 4 3 5
                           "sub  $6, %1             \n\t"
                           "movd %%mm2, 8(%2)       \n\t"
                           "sub  $12, %2            \n\t"
                           "subl $2, %%ecx          \n\t"
                           "jnz .loop3_pass4        \n\t"
                           "EMMS                    \n\t" // DONE

                           : "=c" (dummy_value_c),        // output regs (dummy)
                             "=S" (dummy_value_S),
                             "=D" (dummy_value_D),
                             "=a" (dummy_value_a),
                             "=d" (dummy_value_d)

                           : "0" (width_mmx),     // ecx  // input regs
                             "1" (sptr),          // esi/rsi
                             "2" (dp),            // edi/rdi
#if defined(PNG_x86_64_USE_GOTPCREL)     // formerly _const4 and _const6:
                             "3" (&_c64._amask5_3_0), // (0x0000000000FFFFFFLL)
                             "4" (&_c64._amask7_1_0)  // (0x00000000000000FFLL)
#else
                             "3" (&_amask5_3_0),  // eax (0x0000000000FFFFFFLL)
                             "4" (&_amask7_1_0)   // edx (0x00000000000000FFLL)
#endif

#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
                           : "%mm0", "%mm1"               // clobber list
                           , "%mm2", "%mm3"
#endif
                        );
                     }

                     sptr -= width_mmx*BPP3;
                     dp -= width_mmx*2*BPP3;
                     for (i = width; i; i--)
                     {
                        png_byte v[8];
                        int j;

                        png_memcpy(v, sptr, BPP3);
                        for (j = 0; j < png_pass_inc[pass]; j++)
                        {
                           png_memcpy(dp, v, BPP3);
                           dp -= BPP3;
                        }
                        sptr -= BPP3;
                     }
                  }
                  else if (((pass == 2) || (pass == 3)) && width)
                  {
                     __asm__ __volatile__ (
                        "sub  $9, %2             \n\t"
                                     // (png_pass_inc[pass] - 1)*pixel_bytes

                     ".loop3_pass2:              \n\t"
                        "movd (%1), %%mm0        \n\t" // x x x x x 2 1 0
                        "pand (%3), %%mm0        \n\t" // z z z z z 2 1 0
                        "movq %%mm0, %%mm1       \n\t" // z z z z z 2 1 0
                        "psllq $16, %%mm0        \n\t" // z z z 2 1 0 z z
                        "movq %%mm0, %%mm2       \n\t" // z z z 2 1 0 z z
                        "psllq $24, %%mm0        \n\t" // 2 1 0 z z z z z
                        "psrlq $8, %%mm1         \n\t" // z z z z z z 2 1
                        "por %%mm2, %%mm0        \n\t" // 2 1 0 2 1 0 z z
                        "por %%mm1, %%mm0        \n\t" // 2 1 0 2 1 0 2 1
                        "movq %%mm0, 4(%2)       \n\t"
                        "psrlq $16, %%mm0        \n\t" // z z 2 1 0 2 1 0
                        "sub  $3, %1             \n\t"
                        "movd %%mm0, (%2)        \n\t"
                        "sub  $12, %2            \n\t"
                        "decl %%ecx              \n\t"
                        "jnz .loop3_pass2        \n\t"
                        "EMMS                    \n\t" // DONE

                        : "=c" (dummy_value_c),        // output regs (dummy)
                          "=S" (dummy_value_S),
                          "=D" (dummy_value_D),
                          "=a" (dummy_value_a)

                        : "0" (width),         // ecx  // input regs
                          "1" (sptr),          // esi/rsi
                          "2" (dp),            // edi/rdi
#if defined(PNG_x86_64_USE_GOTPCREL)           // formerly _const4:
                          "3" (&_c64._amask5_3_0)  // (0x0000000000FFFFFFLL)
#else
                          "3" (&_amask5_3_0)   // eax (0x0000000000FFFFFFLL)
#endif

#if defined(CLOBBER_MMX_REGS_SUPPORTED)
                        : "%mm0", "%mm1", "%mm2"       // clobber list
#endif
                     );
                  }
                  else if (width)  // && ((pass == 0) || (pass == 1))
                  {
                     __asm__ __volatile__ (
                        "sub  $21, %2            \n\t"
                                     // (png_pass_inc[pass] - 1)*pixel_bytes

                     ".loop3_pass0:              \n\t"
                        "movd (%1), %%mm0        \n\t" // x x x x x 2 1 0
                        "pand (%3), %%mm0        \n\t" // z z z z z 2 1 0
                        "movq %%mm0, %%mm1       \n\t" // z z z z z 2 1 0
                        "psllq $16, %%mm0        \n\t" // z z z 2 1 0 z z
                        "movq %%mm0, %%mm2       \n\t" // z z z 2 1 0 z z
                        "psllq $24, %%mm0        \n\t" // 2 1 0 z z z z z
                        "psrlq $8, %%mm1         \n\t" // z z z z z z 2 1
                        "por %%mm2, %%mm0        \n\t" // 2 1 0 2 1 0 z z
                        "por %%mm1, %%mm0        \n\t" // 2 1 0 2 1 0 2 1
                        "movq %%mm0, %%mm3       \n\t" // 2 1 0 2 1 0 2 1
                        "psllq $16, %%mm0        \n\t" // 0 2 1 0 2 1 z z
                        "movq %%mm3, %%mm4       \n\t" // 2 1 0 2 1 0 2 1
                        "punpckhdq %%mm0, %%mm3  \n\t" // 0 2 1 0 2 1 0 2
                        "movq %%mm4, 16(%2)      \n\t"
                        "psrlq $32, %%mm0        \n\t" // z z z z 0 2 1 0
                        "movq %%mm3, 8(%2)       \n\t"
                        "punpckldq %%mm4, %%mm0  \n\t" // 1 0 2 1 0 2 1 0
                        "sub  $3, %1             \n\t"
                        "movq %%mm0, (%2)        \n\t"
                        "sub  $24, %2            \n\t"
                        "decl %%ecx              \n\t"
                        "jnz .loop3_pass0        \n\t"
                        "EMMS                    \n\t" // DONE

                        : "=c" (dummy_value_c),        // output regs (dummy)
                          "=S" (dummy_value_S),
                          "=D" (dummy_value_D),
                          "=a" (dummy_value_a)

                        : "0" (width),         // ecx  // input regs
                          "1" (sptr),          // esi/rsi
                          "2" (dp),            // edi/rdi
#if defined(PNG_x86_64_USE_GOTPCREL)           // formerly _const4:
                          "3" (&_c64._amask5_3_0)  // (0x0000000000FFFFFFLL)
#else
                          "3" (&_amask5_3_0)   // eax (0x0000000000FFFFFFLL)
#endif

#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
                        : "%mm0", "%mm1", "%mm2"       // clobber list
                        , "%mm3", "%mm4"
#endif
                     );
                  }
               } /* end of pixel_bytes == 3 */

               //--------------------------------------------------------------
               else if (pixel_bytes == BPP4)
               {
                  if (((pass == 4) || (pass == 5)) && width)
                  {
                     int width_mmx = ((width >> 1) << 1) ;
                     width -= width_mmx;        // 0,1 pixels => 0,4 bytes
                     if (width_mmx)
                     {
                        __asm__ __volatile__ (
                           "sub  $4, %1             \n\t"
                           "sub  $12, %2            \n\t"

                        ".loop4_pass4:              \n\t"
                           "movq (%1), %%mm0        \n\t" // 7 6 5 4 3 2 1 0
                           "movq %%mm0, %%mm1       \n\t" // 7 6 5 4 3 2 1 0
                           "punpckldq %%mm0, %%mm0  \n\t" // 3 2 1 0 3 2 1 0
                           "punpckhdq %%mm1, %%mm1  \n\t" // 7 6 5 4 7 6 5 4
                           "movq %%mm0, (%2)        \n\t"
                           "sub  $8, %1             \n\t"
                           "movq %%mm1, 8(%2)       \n\t"
                           "sub  $16, %2            \n\t"
                           "subl $2, %%ecx          \n\t"
                           "jnz .loop4_pass4        \n\t"
                           "EMMS                    \n\t" // DONE

                           : "=c" (dummy_value_c),        // output regs (dummy)
                             "=S" (dummy_value_S),
                             "=D" (dummy_value_D)

                           : "0" (width_mmx),     // ecx  // input regs
                             "1" (sptr),          // esi/rsi
                             "2" (dp)             // edi/rdi

#if defined(CLOBBER_MMX_REGS_SUPPORTED)
                           : "%mm0", "%mm1"               // clobber list
#endif
                        );
                     }

                     sptr -= (width_mmx*BPP4 - BPP4); // sign fixed
                     dp -= (width_mmx*2*BPP4 - BPP4); // sign fixed
                     for (i = width; i; i--)
                     {
                        png_byte v[8];
                        int j;
                        sptr -= BPP4;
                        png_memcpy(v, sptr, BPP4);
                        for (j = 0; j < png_pass_inc[pass]; j++)
                        {
                           dp -= BPP4;
                           png_memcpy(dp, v, BPP4);
                        }
                     }
                  }
                  else if (((pass == 2) || (pass == 3)) && width)
                  {
                     int width_mmx = ((width >> 1) << 1);
                     width -= width_mmx;        // 0,1 pixels => 0,4 bytes
                     if (width_mmx)
                     {
                        __asm__ __volatile__ (
                           "sub  $4, %1             \n\t"
                           "sub  $28, %2            \n\t"

                        ".loop4_pass2:              \n\t"
                           "movq (%1), %%mm0        \n\t" // 7 6 5 4 3 2 1 0
                           "movq %%mm0, %%mm1       \n\t" // 7 6 5 4 3 2 1 0
                           "punpckldq %%mm0, %%mm0  \n\t" // 3 2 1 0 3 2 1 0
                           "punpckhdq %%mm1, %%mm1  \n\t" // 7 6 5 4 7 6 5 4
                           "movq %%mm0, (%2)        \n\t"
                           "movq %%mm0, 8(%2)       \n\t"
                           "movq %%mm1, 16(%2)      \n\t"
                           "movq %%mm1, 24(%2)      \n\t"
                           "sub  $8, %1             \n\t"
                           "sub  $32, %2            \n\t"
                           "subl $2, %%ecx          \n\t"
                           "jnz .loop4_pass2        \n\t"
                           "EMMS                    \n\t" // DONE

                           : "=c" (dummy_value_c),        // output regs (dummy)
                             "=S" (dummy_value_S),
                             "=D" (dummy_value_D)

                           : "0" (width_mmx),     // ecx  // input regs
                             "1" (sptr),          // esi/rsi
                             "2" (dp)             // edi/rdi

#if defined(CLOBBER_MMX_REGS_SUPPORTED)
                           : "%mm0", "%mm1"               // clobber list
#endif
                        );
                     }

                     sptr -= (width_mmx*4 - 4); // sign fixed
                     dp -= (width_mmx*16 - 4);  // sign fixed
                     for (i = width; i; i--)
                     {
                        png_byte v[8];
                        int j;
                        sptr -= 4;
                        png_memcpy(v, sptr, 4);
                        for (j = 0; j < png_pass_inc[pass]; j++)
                        {
                           dp -= 4;
                           png_memcpy(dp, v, 4);
                        }
                     }
                  }
                  else if (width)  // && ((pass == 0) || (pass == 1))
                  {
                     int width_mmx = ((width >> 1) << 1);
                     width -= width_mmx;        // 0,1 pixels => 0,4 bytes
                     if (width_mmx)
                     {
                        __asm__ __volatile__ (
                           "sub  $4, %1             \n\t"
                           "sub  $60, %2            \n\t"

                        ".loop4_pass0:              \n\t"
                           "movq (%1), %%mm0        \n\t" // 7 6 5 4 3 2 1 0
                           "movq %%mm0, %%mm1       \n\t" // 7 6 5 4 3 2 1 0
                           "punpckldq %%mm0, %%mm0  \n\t" // 3 2 1 0 3 2 1 0
                           "punpckhdq %%mm1, %%mm1  \n\t" // 7 6 5 4 7 6 5 4
                           "movq %%mm0, (%2)        \n\t"
                           "movq %%mm0, 8(%2)       \n\t"
                           "movq %%mm0, 16(%2)      \n\t"
                           "movq %%mm0, 24(%2)      \n\t"
                           "movq %%mm1, 32(%2)      \n\t"
                           "movq %%mm1, 40(%2)      \n\t"
                           "movq %%mm1, 48(%2)      \n\t"
                           "sub  $8, %1             \n\t"
                           "movq %%mm1, 56(%2)      \n\t"
                           "sub  $64, %2            \n\t"
                           "subl $2, %%ecx          \n\t"
                           "jnz .loop4_pass0        \n\t"
                           "EMMS                    \n\t" // DONE

                           : "=c" (dummy_value_c),        // output regs (dummy)
                             "=S" (dummy_value_S),
                             "=D" (dummy_value_D)

                           : "0" (width_mmx),     // ecx  // input regs
                             "1" (sptr),          // esi/rsi
                             "2" (dp)             // edi/rdi

#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
                           : "%mm0", "%mm1"               // clobber list
#endif
                        );
                     }

                     sptr -= (width_mmx*4 - 4); // sign fixed
                     dp -= (width_mmx*32 - 4);  // sign fixed
                     for (i = width; i; i--)
                     {
                        png_byte v[8];
                        int j;
                        sptr -= 4;
                        png_memcpy(v, sptr, 4);
                        for (j = 0; j < png_pass_inc[pass]; j++)
                        {
                           dp -= 4;
                           png_memcpy(dp, v, 4);
                        }
                     }
                  }
               } /* end of pixel_bytes == 4 */

               //--------------------------------------------------------------
               else if (pixel_bytes == 1)
               {
                  if (((pass == 4) || (pass == 5)) && width)
                  {
                     int width_mmx = ((width >> 3) << 3);
                     width -= width_mmx;        // 0-3 pixels => 0-3 bytes
                     if (width_mmx)
                     {
                        __asm__ __volatile__ (
                           "sub  $7, %1             \n\t"
                           "sub  $15, %2            \n\t"

                        ".loop1_pass4:              \n\t"
                           "movq (%1), %%mm0        \n\t" // 7 6 5 4 3 2 1 0
                           "movq %%mm0, %%mm1       \n\t" // 7 6 5 4 3 2 1 0
                           "punpcklbw %%mm0, %%mm0  \n\t" // 3 3 2 2 1 1 0 0
                           "punpckhbw %%mm1, %%mm1  \n\t" // 7 7 6 6 5 5 4 4
                           "movq %%mm1, 8(%2)       \n\t"
                           "sub  $8, %1             \n\t"
                           "movq %%mm0, (%2)        \n\t"
                           "sub  $16, %2            \n\t"
                           "subl $8, %%ecx          \n\t"
                           "jnz .loop1_pass4        \n\t"
                           "EMMS                    \n\t" // DONE

                           : "=c" (dummy_value_c),        // output regs (dummy)
                             "=S" (dummy_value_S),
                             "=D" (dummy_value_D)

                           : "0" (width_mmx),     // ecx  // input regs
                             "1" (sptr),          // esi/rsi
                             "2" (dp)             // edi/rdi

#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
                           : "%mm0", "%mm1"               // clobber list
#endif
                        );
                     }

                     sptr -= width_mmx;
                     dp -= width_mmx*2;
                     for (i = width; i; i--)
                     {
                        int j;

                        for (j = 0; j < png_pass_inc[pass]; j++)
                        {
                           *dp-- = *sptr;
                        }
                        --sptr;
                     }
                  }
                  else if (((pass == 2) || (pass == 3)) && width)
                  {
                     int width_mmx = ((width >> 2) << 2);
                     width -= width_mmx;        // 0-3 pixels => 0-3 bytes
                     if (width_mmx)
                     {
                        __asm__ __volatile__ (
                           "sub  $3, %1             \n\t"
                           "sub  $15, %2            \n\t"

                        ".loop1_pass2:              \n\t"
                           "movd (%1), %%mm0        \n\t" // x x x x 3 2 1 0
                           "punpcklbw %%mm0, %%mm0  \n\t" // 3 3 2 2 1 1 0 0
                           "movq %%mm0, %%mm1       \n\t" // 3 3 2 2 1 1 0 0
                           "punpcklwd %%mm0, %%mm0  \n\t" // 1 1 1 1 0 0 0 0
                           "punpckhwd %%mm1, %%mm1  \n\t" // 3 3 3 3 2 2 2 2
                           "movq %%mm0, (%2)        \n\t"
                           "sub  $4, %1             \n\t"
                           "movq %%mm1, 8(%2)       \n\t"
                           "sub  $16, %2            \n\t"
                           "subl $4, %%ecx          \n\t"
                           "jnz .loop1_pass2        \n\t"
                           "EMMS                    \n\t" // DONE

                           : "=c" (dummy_value_c),        // output regs (dummy)
                             "=S" (dummy_value_S),
                             "=D" (dummy_value_D)

                           : "0" (width_mmx),     // ecx  // input regs
                             "1" (sptr),          // esi/rsi
                             "2" (dp)             // edi/rdi

#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
                           : "%mm0", "%mm1"               // clobber list
#endif
                        );
                     }

                     sptr -= width_mmx;
                     dp -= width_mmx*4;
                     for (i = width; i; i--)
                     {
                        int j;

                        for (j = 0; j < png_pass_inc[pass]; j++)
                        {
                           *dp-- = *sptr;
                        }
                        --sptr;
                     }
                  }
                  else if (width)  // && ((pass == 0) || (pass == 1))
                  {
                     int width_mmx = ((width >> 2) << 2);
                     width -= width_mmx;        // 0-3 pixels => 0-3 bytes
                     if (width_mmx)
                     {
                        __asm__ __volatile__ (
                           "sub  $3, %1             \n\t"
                           "sub  $31, %2            \n\t"

                        ".loop1_pass0:              \n\t"
                           "movd (%1), %%mm0        \n\t" // x x x x 3 2 1 0
                           "movq %%mm0, %%mm1       \n\t" // x x x x 3 2 1 0
                           "punpcklbw %%mm0, %%mm0  \n\t" // 3 3 2 2 1 1 0 0
                           "movq %%mm0, %%mm2       \n\t" // 3 3 2 2 1 1 0 0
                           "punpcklwd %%mm0, %%mm0  \n\t" // 1 1 1 1 0 0 0 0
                           "movq %%mm0, %%mm3       \n\t" // 1 1 1 1 0 0 0 0
                           "punpckldq %%mm0, %%mm0  \n\t" // 0 0 0 0 0 0 0 0
                           "punpckhdq %%mm3, %%mm3  \n\t" // 1 1 1 1 1 1 1 1
                           "movq %%mm0, (%2)        \n\t"
                           "punpckhwd %%mm2, %%mm2  \n\t" // 3 3 3 3 2 2 2 2
                           "movq %%mm3, 8(%2)       \n\t"
                           "movq %%mm2, %%mm4       \n\t" // 3 3 3 3 2 2 2 2
                           "punpckldq %%mm2, %%mm2  \n\t" // 2 2 2 2 2 2 2 2
                           "punpckhdq %%mm4, %%mm4  \n\t" // 3 3 3 3 3 3 3 3
                           "movq %%mm2, 16(%2)      \n\t"
                           "sub  $4, %1             \n\t"
                           "movq %%mm4, 24(%2)      \n\t"
                           "sub  $32, %2            \n\t"
                           "subl $4, %%ecx          \n\t"
                           "jnz .loop1_pass0        \n\t"
                           "EMMS                    \n\t" // DONE

                           : "=c" (dummy_value_c),        // output regs (dummy)
                             "=S" (dummy_value_S),
                             "=D" (dummy_value_D)

                           : "0" (width_mmx),     // ecx  // input regs
                             "1" (sptr),          // esi/rsi
                             "2" (dp)             // edi/rdi

#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
                           : "%mm0", "%mm1", "%mm2"       // clobber list
                           , "%mm3", "%mm4"
#endif
                        );
                     }

                     sptr -= width_mmx;
                     dp -= width_mmx*8;
                     for (i = width; i; i--)
                     {
                        int j;

                       /* I simplified this part in version 1.0.4e
                        * here and in several other instances where
                        * pixel_bytes == 1  -- GR-P
                        *
                        * Original code:
                        *
                        * png_byte v[8];
                        * png_memcpy(v, sptr, pixel_bytes);
                        * for (j = 0; j < png_pass_inc[pass]; j++)
                        * {
                        *    png_memcpy(dp, v, pixel_bytes);
                        *    dp -= pixel_bytes;
                        * }
                        * sptr -= pixel_bytes;
                        *
                        * Replacement code is in the next three lines:
                        */

                        for (j = 0; j < png_pass_inc[pass]; j++)
                        {
                           *dp-- = *sptr;
                        }
                        --sptr;
                     }
                  }
               } /* end of pixel_bytes == 1 */

               //--------------------------------------------------------------
               else if (pixel_bytes == BPP2)
               {
                  if (((pass == 4) || (pass == 5)) && width)
                  {
                     int width_mmx = ((width >> 1) << 1) ;
                     width -= width_mmx;        // 0,1 pixels => 0,2 bytes
                     if (width_mmx)
                     {
                        __asm__ __volatile__ (
                           "sub  $2, %1             \n\t"
                           "sub  $6, %2             \n\t"

                        ".loop2_pass4:              \n\t"
                           "movd (%1), %%mm0        \n\t" // x x x x 3 2 1 0
                           "punpcklwd %%mm0, %%mm0  \n\t" // 3 2 3 2 1 0 1 0
                           "sub  $4, %1             \n\t"
                           "movq %%mm0, (%2)        \n\t"
                           "sub  $8, %2             \n\t"
                           "subl $2, %%ecx          \n\t"
                           "jnz .loop2_pass4        \n\t"
                           "EMMS                    \n\t" // DONE

                           : "=c" (dummy_value_c),        // output regs (dummy)
                             "=S" (dummy_value_S),
                             "=D" (dummy_value_D)

                           : "0" (width_mmx),     // ecx  // input regs
                             "1" (sptr),          // esi/rsi
                             "2" (dp)             // edi/rdi

#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
                           : "%mm0"                       // clobber list
#endif
                        );
                     }

                     sptr -= (width_mmx*BPP2 - BPP2); // sign fixed
                     dp -= (width_mmx*2*BPP2 - BPP2); // sign fixed
                     for (i = width; i; i--)
                     {
                        png_byte v[8];
                        int j;
                        sptr -= BPP2;
                        png_memcpy(v, sptr, BPP2);
                        for (j = 0; j < png_pass_inc[pass]; j++)
                        {
                           dp -= BPP2;
                           png_memcpy(dp, v, BPP2);
                        }
                     }
                  }
                  else if (((pass == 2) || (pass == 3)) && width)
                  {
                     int width_mmx = ((width >> 1) << 1) ;
                     width -= width_mmx;        // 0,1 pixels => 0,2 bytes
                     if (width_mmx)
                     {
                        __asm__ __volatile__ (
                           "sub  $2, %1             \n\t"
                           "sub  $14, %2            \n\t"

                        ".loop2_pass2:              \n\t"
                           "movd (%1), %%mm0        \n\t" // x x x x 3 2 1 0
                           "punpcklwd %%mm0, %%mm0  \n\t" // 3 2 3 2 1 0 1 0
                           "movq %%mm0, %%mm1       \n\t" // 3 2 3 2 1 0 1 0
                           "punpckldq %%mm0, %%mm0  \n\t" // 1 0 1 0 1 0 1 0
                           "punpckhdq %%mm1, %%mm1  \n\t" // 3 2 3 2 3 2 3 2
                           "movq %%mm0, (%2)        \n\t"
                           "sub  $4, %1             \n\t"
                           "movq %%mm1, 8(%2)       \n\t"
                           "sub  $16, %2            \n\t"
                           "subl $2, %%ecx          \n\t"
                           "jnz .loop2_pass2        \n\t"
                           "EMMS                    \n\t" // DONE

                           : "=c" (dummy_value_c),        // output regs (dummy)
                             "=S" (dummy_value_S),
                             "=D" (dummy_value_D)

                           : "0" (width_mmx),     // ecx  // input regs
                             "1" (sptr),          // esi/rsi
                             "2" (dp)             // edi/rdi

#if defined(CLOBBER_MMX_REGS_SUPPORTED)
                           : "%mm0", "%mm1"               // clobber list
#endif
                        );
                     }

                     sptr -= (width_mmx*2 - 2); // sign fixed
                     dp -= (width_mmx*8 - 2);   // sign fixed
                     for (i = width; i; i--)
                     {
                        png_byte v[8];
                        int j;
                        sptr -= 2;
                        png_memcpy(v, sptr, 2);
                        for (j = 0; j < png_pass_inc[pass]; j++)
                        {
                           dp -= 2;
                           png_memcpy(dp, v, 2);
                        }
                     }
                  }
                  else if (width)  // && ((pass == 0) || (pass == 1))
                  {
                     int width_mmx = ((width >> 1) << 1);
                     width -= width_mmx;        // 0,1 pixels => 0,2 bytes
                     if (width_mmx)
                     {
                        __asm__ __volatile__ (
                           "sub  $2, %1             \n\t"
                           "sub  $30, %2            \n\t"

                        ".loop2_pass0:              \n\t"
                           "movd (%1), %%mm0        \n\t" // x x x x 3 2 1 0
                           "punpcklwd %%mm0, %%mm0  \n\t" // 3 2 3 2 1 0 1 0
                           "movq %%mm0, %%mm1       \n\t" // 3 2 3 2 1 0 1 0
                           "punpckldq %%mm0, %%mm0  \n\t" // 1 0 1 0 1 0 1 0
                           "punpckhdq %%mm1, %%mm1  \n\t" // 3 2 3 2 3 2 3 2
                           "movq %%mm0, (%2)        \n\t"
                           "movq %%mm0, 8(%2)       \n\t"
                           "movq %%mm1, 16(%2)      \n\t"
                           "sub  $4, %1             \n\t"
                           "movq %%mm1, 24(%2)      \n\t"
                           "sub  $32, %2            \n\t"
                           "subl $2, %%ecx          \n\t"
                           "jnz .loop2_pass0        \n\t"
                           "EMMS                    \n\t" // DONE

                           : "=c" (dummy_value_c),        // output regs (dummy)
                             "=S" (dummy_value_S),
                             "=D" (dummy_value_D)

                           : "0" (width_mmx),     // ecx  // input regs
                             "1" (sptr),          // esi/rsi
                             "2" (dp)             // edi/rdi

#if defined(CLOBBER_MMX_REGS_SUPPORTED)
                           : "%mm0", "%mm1"               // clobber list
#endif
                        );
                     }

                     sptr -= (width_mmx*2 - 2); // sign fixed
                     dp -= (width_mmx*16 - 2);  // sign fixed
                     for (i = width; i; i--)
                     {
                        png_byte v[8];
                        int j;
                        sptr -= 2;
                        png_memcpy(v, sptr, 2);
                        for (j = 0; j < png_pass_inc[pass]; j++)
                        {
                           dp -= 2;
                           png_memcpy(dp, v, 2);
                        }
                     }
                  }
               } /* end of pixel_bytes == 2 */

               //--------------------------------------------------------------
               else if (pixel_bytes == BPP8)
               {
// GRR TEST:  should work, but needs testing (special 64-bit version of rpng2?)
                  // GRR NOTE:  no need to combine passes here!
                  if (((pass == 4) || (pass == 5)) && width)
                  {
                     // source is 8-byte RRGGBBAA
                     // dest is 16-byte RRGGBBAA RRGGBBAA
                     __asm__ __volatile__ (
                        "sub  $8, %2             \n\t" // start of last block

                     ".loop8_pass4:              \n\t"
                        "movq (%1), %%mm0        \n\t" // 7 6 5 4 3 2 1 0
                        "movq %%mm0, (%2)        \n\t"
                        "sub  $8, %1             \n\t"
                        "movq %%mm0, 8(%2)       \n\t"
                        "sub  $16, %2            \n\t"
                        "decl %%ecx              \n\t"
                        "jnz .loop8_pass4        \n\t"
                        "EMMS                    \n\t" // DONE

                        : "=c" (dummy_value_c),        // output regs (dummy)
                          "=S" (dummy_value_S),
                          "=D" (dummy_value_D)

                        : "0" (width),         // ecx  // input regs
                          "1" (sptr),          // esi/rsi
                          "2" (dp)             // edi/rdi

#if defined(CLOBBER_MMX_REGS_SUPPORTED)
                        : "%mm0"                       // clobber list
#endif
                     );
                  }
                  else if (((pass == 2) || (pass == 3)) && width)
                  {
                     // source is 8-byte RRGGBBAA
                     // dest is 32-byte RRGGBBAA RRGGBBAA RRGGBBAA RRGGBBAA
                     // (recall that expansion is _in place_:  sptr and dp
                     //  both point at locations within same row buffer)
                     __asm__ __volatile__ (
                        "sub  $24, %2            \n\t" // start of last block

                     ".loop8_pass2:              \n\t"
                        "movq (%1), %%mm0        \n\t" // 7 6 5 4 3 2 1 0
                        "movq %%mm0, (%2)        \n\t"
                        "movq %%mm0, 8(%2)       \n\t"
                        "movq %%mm0, 16(%2)      \n\t"
                        "sub  $8, %1             \n\t"
                        "movq %%mm0, 24(%2)      \n\t"
                        "sub  $32, %2            \n\t"
                        "decl %%ecx              \n\t"
                        "jnz .loop8_pass2        \n\t"
                        "EMMS                    \n\t" // DONE

                        : "=c" (dummy_value_c),        // output regs (dummy)
                          "=S" (dummy_value_S),
                          "=D" (dummy_value_D)

                        : "0" (width),         // ecx  // input regs
                          "1" (sptr),          // esi/rsi
                          "2" (dp)             // edi/rdi

#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
                        : "%mm0"                       // clobber list
#endif
                     );
                  }
                  else if (width)  // && ((pass == 0) || (pass == 1))
                  {
                     // source is 8-byte RRGGBBAA
                     // dest is 64-byte RRGGBBAA RRGGBBAA RRGGBBAA RRGGBBAA ...
                     __asm__ __volatile__ (
                        "sub  $56, %2            \n\t" // start of last block

                     ".loop8_pass0:              \n\t"
                        "movq (%1), %%mm0        \n\t" // 7 6 5 4 3 2 1 0
                        "movq %%mm0, (%2)        \n\t"
                        "movq %%mm0, 8(%2)       \n\t"
                        "movq %%mm0, 16(%2)      \n\t"
                        "movq %%mm0, 24(%2)      \n\t"
                        "movq %%mm0, 32(%2)      \n\t"
                        "movq %%mm0, 40(%2)      \n\t"
                        "movq %%mm0, 48(%2)      \n\t"
                        "sub  $8, %1             \n\t"
                        "movq %%mm0, 56(%2)      \n\t"
                        "sub  $64, %2            \n\t"
                        "decl %%ecx              \n\t"
                        "jnz .loop8_pass0        \n\t"
                        "EMMS                    \n\t" // DONE

                        : "=c" (dummy_value_c),        // output regs (dummy)
                          "=S" (dummy_value_S),
                          "=D" (dummy_value_D)

                        : "0" (width),         // ecx  // input regs
                          "1" (sptr),          // esi/rsi
                          "2" (dp)             // edi/rdi

#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
                        : "%mm0"                       // clobber list
#endif
                     );
                  }
               } /* end of pixel_bytes == 8 */

               //--------------------------------------------------------------
               else if (pixel_bytes == BPP6)   // why no MMX for this case?
               {
                  for (i = width; i; i--)
                  {
                     png_byte v[8];
                     int j;
                     png_memcpy(v, sptr, BPP6);
                     for (j = 0; j < png_pass_inc[pass]; j++)
                     {
                        png_memcpy(dp, v, BPP6);
                        dp -= BPP6;
                     }
                     sptr -= BPP6;
                  }
               } /* end of pixel_bytes == 6 */

               //--------------------------------------------------------------
               else
               {
                  // ERROR:  SHOULD NEVER BE REACHED
#if defined(PNG_DEBUG)
                  png_debug(1, "Internal libpng logic error (GCC "
                    "png_do_read_interlace() _mmx_supported)\n");
#endif
               }

            } // end of _mmx_supported ========================================

            else /* MMX not supported:  use modified C code - takes advantage
                  *   of inlining of png_memcpy for a constant */
            {
               if (pixel_bytes == BPP3)
               {
                  for (i = width; i; i--)
                  {
                     png_byte v[8];
                     int j;
                     png_memcpy(v, sptr, BPP3);
                     for (j = 0; j < png_pass_inc[pass]; j++)
                     {
                        png_memcpy(dp, v, BPP3);
                        dp -= BPP3;
                     }
                     sptr -= BPP3;
                  }
               }
               else if (pixel_bytes == BPP4)
               {
                  for (i = width; i; i--)
                  {
                     png_byte v[8];
                     int j;
                     png_memcpy(v, sptr, BPP4);
                     for (j = 0; j < png_pass_inc[pass]; j++)
                     {
#if defined(PNG_DEBUG) && defined(PNG_1_0_X)  // row_buf_size gone in 1.2.x
                        if (dp < row || dp+3 > row+png_ptr->row_buf_size)
                        {
                           printf("dp out of bounds: row=%10p, dp=%10p, "
                             "rp=%10p\n", row, dp, row+png_ptr->row_buf_size);
                           printf("row_buf_size=%lu\n", png_ptr->row_buf_size);
                        }
#endif
                        png_memcpy(dp, v, BPP4);
                        dp -= BPP4;
                     }
                     sptr -= BPP4;
                  }
               }
               else if (pixel_bytes == 1)
               {
                  for (i = width; i; i--)
                  {
                     int j;
                     for (j = 0; j < png_pass_inc[pass]; j++)
                     {
                        *dp-- = *sptr;
                     }
                     --sptr;
                  }
               }
               else if (pixel_bytes == BPP2)
               {
                  for (i = width; i; i--)
                  {
                     png_byte v[8];
                     int j;
                     png_memcpy(v, sptr, BPP2);
                     for (j = 0; j < png_pass_inc[pass]; j++)
                     {
                        png_memcpy(dp, v, BPP2);
                        dp -= BPP2;
                     }
                     sptr -= BPP2;
                  }
               }
               else if (pixel_bytes == BPP6)
               {
                  for (i = width; i; i--)
                  {
                     png_byte v[8];
                     int j;
                     png_memcpy(v, sptr, BPP6);
                     for (j = 0; j < png_pass_inc[pass]; j++)
                     {
                        png_memcpy(dp, v, BPP6);
                        dp -= BPP6;
                     }
                     sptr -= BPP6;
                  }
               }
               else if (pixel_bytes == BPP8)
               {
                  for (i = width; i; i--)
                  {
                     png_byte v[8];
                     int j;
                     png_memcpy(v, sptr, BPP8);
                     for (j = 0; j < png_pass_inc[pass]; j++)
                     {
                        png_memcpy(dp, v, BPP8);
                        dp -= BPP8;
                     }
                     sptr -= BPP8;
                  }
               }
               else
               {
                  // ERROR:  SHOULD NEVER BE REACHED
#if defined(PNG_DEBUG)
                  png_debug(1, "Internal libpng logic error (GCC "
                    "png_do_read_interlace() !_mmx_supported)\n");
#endif
               }

            } /* end if (MMX not supported) */
            break;
         } /* end default (8-bit or larger) */
      } /* end switch (row_info->pixel_depth) */

      row_info->width = final_width;

      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
   }

} /* end png_do_read_interlace() */

#endif /* PNG_HAVE_MMX_READ_INTERLACE */
#endif /* PNG_READ_INTERLACING_SUPPORTED */



#if defined(PNG_HAVE_MMX_READ_FILTER_ROW)
#if defined(PNG_MMX_READ_FILTER_AVG_SUPPORTED)

//===========================================================================//
//                                                                           //
//           P N G _ R E A D _ F I L T E R _ R O W _ M M X _ A V G           //
//                                                                           //
//===========================================================================//

// Optimized code for PNG Average filter decoder

static void /* PRIVATE */
png_read_filter_row_mmx_avg(png_row_infop row_info, png_bytep row,
                            png_bytep prev_row)
{
   unsigned FullLength, MMXLength;  // png_uint_32 is actually 64-bit on x86-64
   int bpp;
   int dummy_value_a;
   int dummy_value_c;   // fix 'forbidden register 2 (cx) was spilled' error
   int dummy_value_d;
   png_bytep dummy_value_S;
   png_bytep dummy_value_D;
   int diff; //     __attribute__((used));

   bpp = (row_info->pixel_depth + 7) >> 3;  // calc number of bytes per pixel
   FullLength = row_info->rowbytes;         // number of bytes to filter

   __asm__ __volatile__ (
   "avg_top:                       \n\t"
      SAVE_GOT_ebx
      SAVE_r15
      SAVE_ebp
      // initialize address pointers and offset
//pre "movl row, %5                \n\t" // edi/rdi:  ptr to Avg(x)
      "xorl %%ebx, %%ebx           \n\t" // ebx:  x
//pre "movl prev_row, %4           \n\t" // esi/rsi:  ptr to Prior(x)
      "mov  %5, " PDX "            \n\t" // copy of row ptr...
//pre "subl bpp, " PDX "           \n\t" // (bpp is preloaded into ecx)
      "sub  " PCX "," PDX "        \n\t" // edx/rdx:  ptr to Raw(x-bpp)
//pre "movl FullLength, %%eax      \n\t" // bring in via eax...
      SAVE_FullLength                    // ...but store for later use
      "xorl %%eax, %%eax           \n\t"

      // Compute the Raw value for the first bpp bytes
      //    Raw(x) = Avg(x) + (Prior(x)/2)
   "avg_rlp:                       \n\t"
      "movb (%4," PBX ",), %%al    \n\t" // load al with Prior(x)
      "incl %%ebx                  \n\t"
      "shrb %%al                   \n\t" // divide by 2
      "addb -1(%5," PBX ",), %%al  \n\t" // add Avg(x); -1 to offset inc ebx
//pre "cmpl bpp, %%ebx             \n\t" // (bpp is preloaded into ecx)
      "cmpl %%ecx, %%ebx           \n\t"
      "movb %%al, -1(%5," PBX ",)  \n\t" // write Raw(x); -1 to offset inc ebx
      "jb avg_rlp                  \n\t" // mov does not affect flags

      // get # of bytes to alignment (32-bit mask _would_ be good enough
      // [computing delta], but 32-bit ops are zero-extended on 64-bit, argh)
      // (if swapped edx and ebp, could do 8-bit or 16-bit mask...FIXME?)
      "mov  %5, " PBP "            \n\t" // take start of row
      "add  " PBX "," PBP "        \n\t" // add bpp
      "add  $0xf, " PBP "          \n\t" // add 7+8 to incr past alignment bdry
//    "andl $0xfffffff8, %%ebp     \n\t" // mask to alignment boundary (32-bit!)
      CLEAR_BOTTOM_3_BITS  PBP    "\n\t" // mask to alignment boundary
      "sub  %5, " PBP "            \n\t" // subtract row ptr again => ebp =
      "jz avg_go                   \n\t" //  target value of ebx at alignment

      "xorl %%ecx, %%ecx           \n\t"

      // fix alignment
      // Compute the Raw value for the bytes up to the alignment boundary
      //    Raw(x) = Avg(x) + ((Raw(x-bpp) + Prior(x))/2)
   "avg_lp1:                       \n\t"
      "xorl %%eax, %%eax           \n\t"
      "movb (%4," PBX ",), %%cl    \n\t" // load cl with Prior(x)
      "movb (" PDX "," PBX ",), %%al \n\t" // load al with Raw(x-bpp)
      "addw %%cx, %%ax             \n\t"
      "incl %%ebx                  \n\t"
      "shrw %%ax                   \n\t" // divide by 2
      "addb -1(%5," PBX ",), %%al  \n\t" // add Avg(x); -1 to offset inc ebx
      "cmpl %%ebp, %%ebx           \n\t" // check if at alignment boundary
      "movb %%al, -1(%5," PBX ",)  \n\t" // write Raw(x); -1 to offset inc ebx
      "jb avg_lp1                  \n\t" // repeat until at alignment boundary

   "avg_go:                        \n\t"
      RESTORE_FullLength "%%eax    \n\t" // FullLength -> eax
      "movl %%eax, %%ecx           \n\t" // copy -> ecx
      "subl %%ebx, %%eax           \n\t" // subtract alignment fix
      "andl $0x00000007, %%eax     \n\t" // calc bytes over mult of 8
      "subl %%eax, %%ecx           \n\t" // sub over-bytes from original length
//out "movl %%ecx, MMXLength       \n\t"
      "movl %%ebp, %%eax           \n\t" // ebp = diff, but no reg constraint(?)
      RESTORE_ebp                        //  (could swap ebp and edx functions)
      RESTORE_r15
      RESTORE_GOT_ebx

// "There is no way for you to specify that an input operand is modified
// without also specifying it as an output operand."  [makes sense]

// "Unless an output operand has the `&' constraint modifier, GCC may
// allocate it in the same register as an unrelated input operand, on the
// assumption the inputs are consumed before the outputs are produced."
// [trying to _force_ this]

// "`='   Means that this operand is write-only for this instruction:
//        the previous value is discarded and replaced by output data."
//        [operand == variable name, presumably]

      // output regs
      // these are operands 0-1 (originally 0-3):
      : "=c" (MMXLength),      // %0 -> %0
        "=a" (diff)            // %3 -> %1
//      "=S" (dummy_value_S),  // %1 -> GONE
//      "=D" (dummy_value_D),  // %2 -> GONE

      // input regs
      // these are operands 2-5 (originally 4-7); two of their constraints say
      // they must go in same places as operands 0-1 (originally 0-3) above:
      : "0" (bpp),         // %4 -> %2 ecx
        "1" (FullLength),  // %7 -> %3 eax
        "S" (prev_row),    // %5 -> %4 esi/rsi
        "D" (row)          // %6 -> %5 edi/rdi

      : "%edx"                           // clobber list
        _CLOBBER_r15
        _CLOBBER_ebp
        _CLOBBER_GOT_ebx
   );

   // now do the math for the rest of the row
   switch (bpp)
   {
      case 3:
      {
//       _ShiftBpp = 24;    // == 3 * 8
//       _ShiftRem = 40;    // == 64 - 24

         __asm__ __volatile__ (
            // re-init address pointers and offset
            LOAD_GOT_rbp
            "movq " AMASK5_3_0 ", %%mm7    \n\t" // _amask5_3_0 -> mm7
// preload  "movl  diff, %%ecx             \n\t" // ecx:  x = offset to
                                                 //  alignment boundary
            "movq " LB_CARRY_MASK ", %%mm5 \n\t" // [interleave for parallel.?]
// preload  "movl  row, %1                 \n\t" // edi:  Avg(x)
            "movq " HB_CLEAR_MASK ", %%mm4 \n\t" // _HBClearMask -> mm4
// preload  "movl  prev_row, %0            \n\t" // esi:  Prior(x)
            RESTORE_rbp

            // prime the pump:  load the first Raw(x-bpp) data set
            "movq  -8(%1," PCX ",), %%mm2 \n\t"// load previous aligned 8 bytes
                                               // (correct pos. in loop below)
         "avg_3lp:                        \n\t"
            "movq  (%1," PCX ",), %%mm0   \n\t" // load mm0 with Avg(x)
            "movq  %%mm5, %%mm3           \n\t"
            "psrlq $40, %%mm2             \n\t" // correct position Raw(x-bpp)
                                                // data
            "movq  (%0," PCX ",), %%mm1   \n\t" // load mm1 with Prior(x)
            "movq  %%mm7, %%mm6           \n\t"
            "pand  %%mm1, %%mm3           \n\t" // get lsb for each prevrow byte
            "psrlq $1, %%mm1              \n\t" // divide prev_row bytes by 2
            "pand  %%mm4, %%mm1           \n\t" // clear invalid bit 7 of each
                                                // byte
            "paddb %%mm1, %%mm0           \n\t" // add (Prev_row/2) to Avg for
                                                // each byte
            // add 1st active group (Raw(x-bpp)/2) to average with LBCarry
            "movq  %%mm3, %%mm1           \n\t" // now use mm1 for getting
                                                // LBCarrys
            "pand  %%mm2, %%mm1           \n\t" // get LBCarrys for each byte
                                                // where both lsb's were == 1
                                                // (valid only for active group)
            "psrlq $1, %%mm2              \n\t" // divide raw bytes by 2
            "pand  %%mm4, %%mm2           \n\t" // clear invalid bit 7 of each
                                                // byte
            "paddb %%mm1, %%mm2           \n\t" // add LBCarrys to Raw(x-bpp)/2
                                                // for each byte
            "pand  %%mm6, %%mm2           \n\t" // leave only Active Group 1
                                                // bytes to add to Avg
            "paddb %%mm2, %%mm0           \n\t" // add (Raw/2) + LBCarrys to
                                                // Avg for each Active byte
            // add 2nd active group (Raw(x-bpp)/2) to average with _LBCarry
            "psllq $24, %%mm6             \n\t" // shift the mm6 mask to cover
                                                // bytes 3-5
            "movq  %%mm0, %%mm2           \n\t" // mov updated Raws to mm2
            "psllq $24, %%mm2             \n\t" // shift data to pos. correctly
            "movq  %%mm3, %%mm1           \n\t" // now use mm1 for getting
                                                // LBCarrys
            "pand  %%mm2, %%mm1           \n\t" // get LBCarrys for each byte
                                                // where both lsb's were == 1
                                                // (valid only for active group)
            "psrlq $1, %%mm2              \n\t" // divide raw bytes by 2
            "pand  %%mm4, %%mm2           \n\t" // clear invalid bit 7 of each
                                                // byte
            "paddb %%mm1, %%mm2           \n\t" // add LBCarrys to Raw(x-bpp)/2
                                                // for each byte
            "pand  %%mm6, %%mm2           \n\t" // leave only Active Group 2
                                                // bytes to add to Avg
            "paddb %%mm2, %%mm0           \n\t" // add (Raw/2) + LBCarrys to
                                                // Avg for each Active byte

            // add 3rd active group (Raw(x-bpp)/2) to average with _LBCarry
            "psllq $24, %%mm6             \n\t" // shift mm6 mask to cover last
                                                // two bytes
            "movq  %%mm0, %%mm2           \n\t" // mov updated Raws to mm2
            "psllq $24, %%mm2             \n\t" // shift data to pos. correctly
                              // Data need be shifted only once here to
                              // get the correct x-bpp offset.
            "movq  %%mm3, %%mm1           \n\t" // now use mm1 for getting
                                                // LBCarrys
            "pand  %%mm2, %%mm1           \n\t" // get LBCarrys for each byte
                                                // where both
                              // lsb's were == 1 (only valid for active group)
            "psrlq $1, %%mm2              \n\t" // divide raw bytes by 2
            "pand  %%mm4, %%mm2           \n\t" // clear invalid bit 7 of each
                                                // byte
            "paddb %%mm1, %%mm2           \n\t" // add LBCarrys to Raw(x-bpp)/2
                                                // for each byte
            "pand  %%mm6, %%mm2           \n\t" // leave only Active Group 2
                                                // bytes to add to Avg
            "addl  $8, %%ecx              \n\t"
            "paddb %%mm2, %%mm0           \n\t" // add (Raw/2) + LBCarrys to
                                                // Avg for each Active byte
            // now ready to write back to memory
            "movq  %%mm0, -8(%1," PCX ",) \n\t"
            // move updated Raw(x) to use as Raw(x-bpp) for next loop
            "cmpl  %%eax, %%ecx           \n\t" // MMXLength
            "movq  %%mm0, %%mm2           \n\t" // mov updated Raw(x) to mm2
            "jb avg_3lp                   \n\t"

            : "=S" (dummy_value_S),            // output regs (dummy)
              "=D" (dummy_value_D),
              "=c" (dummy_value_c),
              "=a" (dummy_value_a)

            : "0" (prev_row),    // esi/rsi    // input regs
              "1" (row),         // edi/rdi
              "2" (diff),        // ecx
              "3" (MMXLength)    // eax

#if defined(CLOBBER_MMX_REGS_SUPPORTED)
            : "%mm0", "%mm1", "%mm2", "%mm3"   // clobber list
            , "%mm4", "%mm5", "%mm6", "%mm7"
#endif
         );
      }
      break;  // end 3 bpp

      case 4:   // formerly shared with 6 bpp case via _ShiftBpp and _ShiftRem,
      {         // but loop uses all 8 MMX regs, and psrlq/psllq require 64-bit
                // mem (PIC/.so problems), MMX reg (none left), or immediate
//       _ShiftBpp = bpp << 3;        // 32 (psllq)
//       _ShiftRem = 64 - _ShiftBpp;  // 32 (psrlq)

         __asm__ __volatile__ (
            LOAD_GOT_rbp
            "movq " HB_CLEAR_MASK ", %%mm4 \n\t" // _HBClearMask -> mm4
            "movq " LB_CARRY_MASK ", %%mm5 \n\t" // _LBCarryMask -> mm5
            // re-init address pointers and offset
// preload  "movl  diff, %%ecx             \n\t" // ecx:  x = offset to
                                                 // alignment boundary
            "movq " AMASK0_8_0 ", %%mm7    \n\t" // _amask0_8_0 -> mm7
            RESTORE_rbp

            // ... and clear all bytes except for 1st active group
// preload  "movl  row, %1               \n\t" // edi:  Avg(x)
            "psrlq $32, %%mm7            \n\t" // was _ShiftRem
// preload  "movl  prev_row, %0          \n\t" // esi:  Prior(x)
            "movq  %%mm7, %%mm6          \n\t"
            "psllq $32, %%mm6            \n\t" // mask for 2nd active group

            // prime the pump:  load the first Raw(x-bpp) data set
            "movq -8(%1," PCX ",), %%mm2 \n\t" // load previous aligned 8 bytes
                                             // (we correct pos. in loop below)
         "avg_4lp:                       \n\t"
            "movq (%1," PCX ",), %%mm0   \n\t"
            "psrlq $32, %%mm2            \n\t" // shift data to pos. correctly
            "movq (%0," PCX ",), %%mm1   \n\t"
            // add (Prev_row/2) to average
            "movq %%mm5, %%mm3           \n\t"
            "pand %%mm1, %%mm3           \n\t" // get lsb for each prev_row byte
            "psrlq $1, %%mm1             \n\t" // divide prev_row bytes by 2
            "pand  %%mm4, %%mm1          \n\t" // clear invalid bit 7 of each
                                               // byte
            "paddb %%mm1, %%mm0          \n\t" // add (Prev_row/2) to Avg for
                                               // each byte
            // add 1st active group (Raw(x-bpp)/2) to average with _LBCarry
            "movq %%mm3, %%mm1           \n\t" // now use mm1 for getting
                                               // LBCarrys
            "pand %%mm2, %%mm1           \n\t" // get LBCarrys for each byte
                                               // where both
                              // lsb's were == 1 (only valid for active group)
            "psrlq $1, %%mm2             \n\t" // divide raw bytes by 2
            "pand  %%mm4, %%mm2          \n\t" // clear invalid bit 7 of each
                                               // byte
            "paddb %%mm1, %%mm2          \n\t" // add LBCarrys to (Raw(x-bpp)/2)
                                               // for each byte
            "pand %%mm7, %%mm2           \n\t" // leave only Active Group 1
                                               // bytes to add to Avg
            "paddb %%mm2, %%mm0          \n\t" // add (Raw/2) + LBCarrys to Avg
                                               // for each Active
                              // byte
            // add 2nd active group (Raw(x-bpp)/2) to average with _LBCarry
            "movq %%mm0, %%mm2           \n\t" // mov updated Raws to mm2
            "psllq $32, %%mm2            \n\t" // shift data to pos. correctly
            "addl $8, %%ecx              \n\t"
            "movq %%mm3, %%mm1           \n\t" // now use mm1 for getting
                                               // LBCarrys
            "pand %%mm2, %%mm1           \n\t" // get LBCarrys for each byte
                                               // where both
                              // lsb's were == 1 (only valid for active group)
            "psrlq $1, %%mm2             \n\t" // divide raw bytes by 2
            "pand  %%mm4, %%mm2          \n\t" // clear invalid bit 7 of each
                                               // byte
            "paddb %%mm1, %%mm2          \n\t" // add LBCarrys to (Raw(x-bpp)/2)
                                               // for each byte
            "pand %%mm6, %%mm2           \n\t" // leave only Active Group 2
                                               // bytes to add to Avg
            "paddb %%mm2, %%mm0          \n\t" // add (Raw/2) + LBCarrys to
                                               // Avg for each Active byte
            "cmpl %%eax, %%ecx           \n\t" // MMXLength
            // now ready to write back to memory
            "movq %%mm0, -8(%1," PCX ",) \n\t"
            // prep Raw(x-bpp) for next loop
            "movq %%mm0, %%mm2           \n\t" // mov updated Raws to mm2
            "jb avg_4lp                  \n\t"

            : "=S" (dummy_value_S),            // output regs (dummy)
              "=D" (dummy_value_D),
              "=c" (dummy_value_c),
              "=a" (dummy_value_a)

            : "0" (prev_row),    // esi/rsi    // input regs
              "1" (row),         // edi/rdi
              "2" (diff),        // ecx
              "3" (MMXLength)    // eax

#if defined(CLOBBER_MMX_REGS_SUPPORTED)
            : "%mm0", "%mm1", "%mm2", "%mm3"   // clobber list
            , "%mm4", "%mm5", "%mm6", "%mm7"
#endif
         );
      }
      break;  // end 4 bpp

      case 1:
      {
         __asm__ __volatile__ (
            // re-init address pointers and offset
// preload  "movl diff, %%ecx            \n\t" // ecx: x = offset to align. bdry
// preload  "movl row, %1                \n\t" // edi/rdi:  Avg(x)
// preload  "movl FullLength, %%eax      \n\t"
            "cmpl %%eax, %%ecx           \n\t" // test if offset at end of array
            "jnb avg_1end                \n\t"

            SAVE_ebp

            // do Avg decode for remaining bytes
// preload  "movl prev_row, %0           \n\t" // esi/rsi:  Prior(x)
            "mov  %1, " PBP "            \n\t" // copy of row pointer...
            "dec  " PBP "                \n\t" // ebp/rbp:  Raw(x-bpp)
            "xorl %%edx, %%edx           \n\t" // zero edx before using dl & dx
                                               //  in loop below
            SAVE_GOT_ebx

         "avg_1lp:                       \n\t"
            // Raw(x) = Avg(x) + ((Raw(x-bpp) + Prior(x))/2)
            "xorl %%ebx, %%ebx           \n\t"
            "movb (%0," PCX ",), %%dl    \n\t" // load dl with Prior(x)
            "movb (" PBP "," PCX ",), %%bl \n\t" // load bl with Raw(x-bpp)
            "addw %%dx, %%bx             \n\t"
            "incl %%ecx                  \n\t"
            "shrw %%bx                   \n\t" // divide by 2
            "addb -1(%1," PCX ",), %%bl  \n\t" // add Avg(x); -1 to offset
                                               // inc ecx
            "cmpl %%eax, %%ecx           \n\t" // check if at end of array
            "movb %%bl, -1(%1," PCX ",)  \n\t" // write back Raw(x);
                         // mov does not affect flags; -1 to offset inc ecx
            "jb avg_1lp                  \n\t"

            RESTORE_GOT_ebx
            RESTORE_ebp

         "avg_1end:                      \n\t"

            : "=S" (dummy_value_S),            // output regs (dummy)
              "=D" (dummy_value_D),
              "=c" (dummy_value_c),
              "=a" (dummy_value_a)

            : "0" (prev_row),    // esi/rsi    // input regs
              "1" (row),         // edi/rdi
              "2" (diff),        // ecx
              "3" (FullLength)   // eax

            : "%edx"                           // clobber list
              _CLOBBER_GOT_ebx
              _CLOBBER_ebp
         );
      }
      return;  // end 1 bpp

      case 2:
      {
//       _ShiftBpp = 16;   // == 2 * 8
//       _ShiftRem = 48;   // == 64 - _ShiftBpp

         __asm__ __volatile__ (
            LOAD_GOT_rbp
            // load (former) _ActiveMask
            "movq " AMASK6_2_0 ", %%mm7    \n\t" // _amask6_2_0 -> mm7
            // re-init address pointers and offset
// preload  "movl  diff, %%ecx             \n\t" // ecx:  x = offset to
                                                 // alignment boundary
            "movq " LB_CARRY_MASK ", %%mm5 \n\t" // _LBCarryMask -> mm5
// preload  "movl  row, %1                 \n\t" // edi:  Avg(x)
            "movq " HB_CLEAR_MASK ", %%mm4 \n\t" // _HBClearMask -> mm4
// preload  "movl  prev_row, %0            \n\t" // esi:  Prior(x)
            RESTORE_rbp

            // prime the pump:  load the first Raw(x-bpp) data set
            "movq -8(%1," PCX ",), %%mm2 \n\t" // load previous aligned 8 bytes
                                             // (we correct pos. in loop below)
         "avg_2lp:                       \n\t"
            "movq (%1," PCX ",), %%mm0   \n\t"
            "psrlq $48, %%mm2            \n\t" // shift data to pos. correctly
            "movq (%0," PCX ",), %%mm1   \n\t" //  (GRR BUGFIX:  was psllq)
            // add (Prev_row/2) to average
            "movq %%mm5, %%mm3           \n\t"
            "pand %%mm1, %%mm3           \n\t" // get lsb for each prev_row byte
            "psrlq $1, %%mm1             \n\t" // divide prev_row bytes by 2
            "pand  %%mm4, %%mm1          \n\t" // clear invalid bit 7 of each
                                               // byte
            "movq %%mm7, %%mm6           \n\t"
            "paddb %%mm1, %%mm0          \n\t" // add (Prev_row/2) to Avg for
                                               // each byte

            // add 1st active group (Raw(x-bpp)/2) to average with _LBCarry
            "movq %%mm3, %%mm1           \n\t" // now use mm1 for getting
                                               // LBCarrys
            "pand %%mm2, %%mm1           \n\t" // get LBCarrys for each byte
                                               // where both
                                               // lsb's were == 1 (only valid
                                               // for active group)
            "psrlq $1, %%mm2             \n\t" // divide raw bytes by 2
            "pand  %%mm4, %%mm2          \n\t" // clear invalid bit 7 of each
                                               // byte
            "paddb %%mm1, %%mm2          \n\t" // add LBCarrys to (Raw(x-bpp)/2)
                                               // for each byte
            "pand %%mm6, %%mm2           \n\t" // leave only Active Group 1
                                               // bytes to add to Avg
            "paddb %%mm2, %%mm0          \n\t" // add (Raw/2) + LBCarrys to Avg
                                               // for each Active byte

            // add 2nd active group (Raw(x-bpp)/2) to average with _LBCarry
            "psllq $16, %%mm6            \n\t" // shift the mm6 mask to cover
                                               // bytes 2 & 3
            "movq %%mm0, %%mm2           \n\t" // mov updated Raws to mm2
            "psllq $16, %%mm2            \n\t" // shift data to pos. correctly
            "movq %%mm3, %%mm1           \n\t" // now use mm1 for getting
                                               // LBCarrys
            "pand %%mm2, %%mm1           \n\t" // get LBCarrys for each byte
                                               // where both
                                               // lsb's were == 1 (only valid
                                               // for active group)
            "psrlq $1, %%mm2             \n\t" // divide raw bytes by 2
            "pand  %%mm4, %%mm2          \n\t" // clear invalid bit 7 of each
                                               // byte
            "paddb %%mm1, %%mm2          \n\t" // add LBCarrys to (Raw(x-bpp)/2)
                                               // for each byte
            "pand %%mm6, %%mm2           \n\t" // leave only Active Group 2
                                               // bytes to add to Avg
            "paddb %%mm2, %%mm0          \n\t" // add (Raw/2) + LBCarrys to
                                               // Avg for each Active byte

            // add 3rd active group (Raw(x-bpp)/2) to average with _LBCarry
            "psllq $16, %%mm6            \n\t" // shift the mm6 mask to cover
                                               // bytes 4 & 5
            "movq %%mm0, %%mm2           \n\t" // mov updated Raws to mm2
            "psllq $16, %%mm2            \n\t" // shift data to pos. correctly
            "movq %%mm3, %%mm1           \n\t" // now use mm1 for getting
                                               // LBCarrys
            "pand %%mm2, %%mm1           \n\t" // get LBCarrys for each byte
                                               // where both lsb's were == 1
                                               // (only valid for active group)
            "psrlq $1, %%mm2             \n\t" // divide raw bytes by 2
            "pand  %%mm4, %%mm2          \n\t" // clear invalid bit 7 of each
                                               // byte
            "paddb %%mm1, %%mm2          \n\t" // add LBCarrys to (Raw(x-bpp)/2)
                                               // for each byte
            "pand %%mm6, %%mm2           \n\t" // leave only Active Group 2
                                               // bytes to add to Avg
            "paddb %%mm2, %%mm0          \n\t" // add (Raw/2) + LBCarrys to
                                               // Avg for each Active byte

            // add 4th active group (Raw(x-bpp)/2) to average with _LBCarry
            "psllq $16, %%mm6            \n\t" // shift the mm6 mask to cover
                                               // bytes 6 & 7
            "movq %%mm0, %%mm2           \n\t" // mov updated Raws to mm2
            "psllq $16, %%mm2            \n\t" // shift data to pos. correctly
            "addl $8, %%ecx              \n\t"
            "movq %%mm3, %%mm1           \n\t" // now use mm1 for getting
                                               // LBCarrys
            "pand %%mm2, %%mm1           \n\t" // get LBCarrys for each byte
                                               // where both
                                               // lsb's were == 1 (only valid
                                               // for active group)
            "psrlq $1, %%mm2             \n\t" // divide raw bytes by 2
            "pand  %%mm4, %%mm2          \n\t" // clear invalid bit 7 of each
                                               // byte
            "paddb %%mm1, %%mm2          \n\t" // add LBCarrys to (Raw(x-bpp)/2)
                                               // for each byte
            "pand %%mm6, %%mm2           \n\t" // leave only Active Group 2
                                               // bytes to add to Avg
            "paddb %%mm2, %%mm0          \n\t" // add (Raw/2) + LBCarrys to
                                               // Avg for each Active byte
            "cmpl %%eax, %%ecx           \n\t" // MMXLength
            // now ready to write back to memory
            "movq %%mm0, -8(%1," PCX ",) \n\t"
            // prep Raw(x-bpp) for next loop
            "movq %%mm0, %%mm2           \n\t" // mov updated Raws to mm2
            "jb avg_2lp                  \n\t"

            : "=S" (dummy_value_S),            // output regs (dummy)
              "=D" (dummy_value_D),
              "=c" (dummy_value_c),
              "=a" (dummy_value_a)

            : "0" (prev_row),    // esi/rsi    // input regs
              "1" (row),         // edi/rdi
              "2" (diff),        // ecx
              "3" (MMXLength)    // eax

#if defined(CLOBBER_MMX_REGS_SUPPORTED)
            : "%mm0", "%mm1", "%mm2", "%mm3"   // clobber list
            , "%mm4", "%mm5", "%mm6", "%mm7"
#endif
         );
      }
      break;  // end 2 bpp

      case 6:   // formerly shared with 4 bpp case (see comments there)
      {
//       _ShiftBpp = bpp << 3;        // 48 (psllq)
//       _ShiftRem = 64 - _ShiftBpp;  // 16 (psrlq)

         __asm__ __volatile__ (
            LOAD_GOT_rbp
            "movq " HB_CLEAR_MASK ", %%mm4 \n\t" // _HBClearMask -> mm4
            "movq " LB_CARRY_MASK ", %%mm5 \n\t" // _LBCarryMask -> mm5
            // re-init address pointers and offset
// preload  "movl  diff, %%ecx             \n\t" // ecx:  x = offset to
                                                 // alignment boundary
            "movq " AMASK0_8_0 ", %%mm7    \n\t" // _amask0_8_0 -> mm7
            RESTORE_rbp

            // ... and clear all bytes except for 1st active group
// preload  "movl  row, %1               \n\t" // edi:  Avg(x)
            "psrlq $16, %%mm7            \n\t"
// preload  "movl  prev_row, %0          \n\t" // esi:  Prior(x)
            "movq  %%mm7, %%mm6          \n\t"
            "psllq $48, %%mm6            \n\t" // mask for 2nd active group

            // prime the pump:  load the first Raw(x-bpp) data set
            "movq -8(%1," PCX ",), %%mm2 \n\t" // load previous aligned 8 bytes
                                             // (we correct pos. in loop below)
         "avg_6lp:                       \n\t"
            "movq (%1," PCX ",), %%mm0   \n\t"
            "psrlq $16, %%mm2            \n\t" // shift data to pos. correctly
            "movq (%0," PCX ",), %%mm1   \n\t"
            // add (Prev_row/2) to average
            "movq %%mm5, %%mm3           \n\t"
            "pand %%mm1, %%mm3           \n\t" // get lsb for each prev_row byte
            "psrlq $1, %%mm1             \n\t" // divide prev_row bytes by 2
            "pand  %%mm4, %%mm1          \n\t" // clear invalid bit 7 of each
                                               // byte
            "paddb %%mm1, %%mm0          \n\t" // add (Prev_row/2) to Avg for
                                               // each byte
            // add 1st active group (Raw(x-bpp)/2) to average with _LBCarry
            "movq %%mm3, %%mm1           \n\t" // now use mm1 for getting
                                               // LBCarrys
            "pand %%mm2, %%mm1           \n\t" // get LBCarrys for each byte
                                               // where both
                              // lsb's were == 1 (only valid for active group)
            "psrlq $1, %%mm2             \n\t" // divide raw bytes by 2
            "pand  %%mm4, %%mm2          \n\t" // clear invalid bit 7 of each
                                               // byte
            "paddb %%mm1, %%mm2          \n\t" // add LBCarrys to (Raw(x-bpp)/2)
                                               // for each byte
            "pand %%mm7, %%mm2           \n\t" // leave only Active Group 1
                                               // bytes to add to Avg
            "paddb %%mm2, %%mm0          \n\t" // add (Raw/2) + LBCarrys to Avg
                                               // for each Active
                              // byte
            // add 2nd active group (Raw(x-bpp)/2) to average with _LBCarry
            "movq %%mm0, %%mm2           \n\t" // mov updated Raws to mm2
            "psllq $48, %%mm2            \n\t" // shift data to pos. correctly
            "addl $8, %%ecx              \n\t"
            "movq %%mm3, %%mm1           \n\t" // now use mm1 for getting
                                               // LBCarrys
            "pand %%mm2, %%mm1           \n\t" // get LBCarrys for each byte
                                               // where both
                              // lsb's were == 1 (only valid for active group)
            "psrlq $1, %%mm2             \n\t" // divide raw bytes by 2
            "pand  %%mm4, %%mm2          \n\t" // clear invalid bit 7 of each
                                               // byte
            "paddb %%mm1, %%mm2          \n\t" // add LBCarrys to (Raw(x-bpp)/2)
                                               // for each byte
            "pand %%mm6, %%mm2           \n\t" // leave only Active Group 2
                                               // bytes to add to Avg
            "paddb %%mm2, %%mm0          \n\t" // add (Raw/2) + LBCarrys to
                                               // Avg for each Active byte
            "cmpl %%eax, %%ecx           \n\t" // MMXLength
            // now ready to write back to memory
            "movq %%mm0, -8(%1," PCX ",) \n\t"
            // prep Raw(x-bpp) for next loop
            "movq %%mm0, %%mm2           \n\t" // mov updated Raws to mm2
            "jb avg_6lp                  \n\t"

            : "=S" (dummy_value_S),            // output regs (dummy)
              "=D" (dummy_value_D),
              "=c" (dummy_value_c),
              "=a" (dummy_value_a)

            : "0" (prev_row),    // esi/rsi    // input regs
              "1" (row),         // edi/rdi
              "2" (diff),        // ecx
              "3" (MMXLength)    // eax

#if defined(CLOBBER_MMX_REGS_SUPPORTED)
            : "%mm0", "%mm1", "%mm2", "%mm3"   // clobber list
            , "%mm4", "%mm5", "%mm6", "%mm7"
#endif
         );
      }
      break;  // end 6 bpp

      case 8:
      {
         __asm__ __volatile__ (
            // re-init address pointers and offset
// preload  "movl  diff, %%ecx             \n\t" // ecx:  x = offset to
                                                 // alignment boundary
            LOAD_GOT_rbp
            "movq " LB_CARRY_MASK ", %%mm5 \n\t" // [interleave for parallel.?]
// preload  "movl  row, %1                 \n\t" // edi:  Avg(x)
            "movq " HB_CLEAR_MASK ", %%mm4 \n\t" // _HBClearMask -> mm4
// preload  "movl  prev_row, %0            \n\t" // esi:  Prior(x)
            RESTORE_rbp

            // prime the pump:  load the first Raw(x-bpp) data set
            "movq -8(%1," PCX ",), %%mm2 \n\t" // load previous aligned 8 bytes
                                      // (NO NEED to correct pos. in loop below)

         "avg_8lp:                       \n\t"
            "movq (%1," PCX ",), %%mm0   \n\t"
            "movq %%mm5, %%mm3           \n\t"
            "movq (%0," PCX ",), %%mm1   \n\t"
            "addl $8, %%ecx              \n\t"
            "pand %%mm1, %%mm3           \n\t" // get lsb for each prev_row byte
            "psrlq $1, %%mm1             \n\t" // divide prev_row bytes by 2
            "pand %%mm2, %%mm3           \n\t" // get LBCarrys for each byte
                                               //  where both lsb's were == 1
            "psrlq $1, %%mm2             \n\t" // divide raw bytes by 2
            "pand  %%mm4, %%mm1          \n\t" // clear invalid bit 7, each byte
            "paddb %%mm3, %%mm0          \n\t" // add LBCarrys to Avg, each byte
            "pand  %%mm4, %%mm2          \n\t" // clear invalid bit 7, each byte
            "paddb %%mm1, %%mm0          \n\t" // add (Prev_row/2) to Avg, each
            "paddb %%mm2, %%mm0          \n\t" // add (Raw/2) to Avg for each
            "cmpl %%eax, %%ecx           \n\t" // MMXLength
            "movq %%mm0, -8(%1," PCX ",) \n\t"
            "movq %%mm0, %%mm2           \n\t" // reuse as Raw(x-bpp)
            "jb avg_8lp                  \n\t"

            : "=S" (dummy_value_S),            // output regs (dummy)
              "=D" (dummy_value_D),
              "=c" (dummy_value_c),
              "=a" (dummy_value_a)

            : "0" (prev_row),    // esi/rsi    // input regs
              "1" (row),         // edi/rdi
              "2" (diff),        // ecx
              "3" (MMXLength)    // eax

#if defined(CLOBBER_MMX_REGS_SUPPORTED)
            : "%mm0", "%mm1", "%mm2"           // clobber list
            , "%mm3", "%mm4", "%mm5"
#endif
         );
      }
      break;  // end 8 bpp

      default:                // bpp != 1,2,3,4,6,8:  doesn't exist
      {
         // ERROR:  SHOULD NEVER BE REACHED
#if defined(PNG_DEBUG)
         png_debug(1, "Internal libpng logic error (GCC "
           "png_read_filter_row_mmx_avg())\n");
#endif
      }
      break;

   } // end switch (bpp)

   __asm__ __volatile__ (
      // MMX acceleration complete; now do clean-up
      // check if any remaining bytes left to decode
//pre "movl FullLength, %%edx      \n\t"
//pre "movl MMXLength, %%eax       \n\t" // eax:  x == offset bytes after MMX
//pre "movl row, %2                \n\t" // edi:  Avg(x)
      "cmpl %%edx, %%eax           \n\t" // test if offset at end of array
      "jnb avg_end                 \n\t"

      SAVE_ebp

      // do Avg decode for remaining bytes
//pre "movl prev_row, %1           \n\t" // esi:  Prior(x)
      "mov  %2, " PBP "            \n\t" // copy of row pointer...
//pre "subl bpp, " PBP "           \n\t" // (bpp is preloaded into ecx)
      "sub  " PCX "," PBP "        \n\t" // ebp:  Raw(x-bpp)
      "xorl %%ecx, %%ecx           \n\t" // zero ecx before using cl & cx below

      SAVE_GOT_ebx

   "avg_lp2:                       \n\t"
      // Raw(x) = Avg(x) + ((Raw(x-bpp) + Prior(x))/2)
      "xorl %%ebx, %%ebx           \n\t"
      "movb (%1," PAX ",), %%cl    \n\t" // load cl with Prior(x)
      "movb (" PBP "," PAX ",), %%bl \n\t" // load bl with Raw(x-bpp)
      "addw %%cx, %%bx             \n\t"
      "incl %%eax                  \n\t"
      "shrw %%bx                   \n\t" // divide by 2
      "addb -1(%2," PAX ",), %%bl  \n\t" // add Avg(x); -1 to offset inc eax
      "cmpl %%edx, %%eax           \n\t" // check if at end of array
      "movb %%bl, -1(%2," PAX ",)  \n\t" // write back Raw(x) [mov does not
      "jb avg_lp2                  \n\t" //  affect flags; -1 to offset inc eax]

      RESTORE_GOT_ebx
      RESTORE_ebp

   "avg_end:                       \n\t"
      "EMMS                        \n\t" // end MMX; prep for poss. FP instrs.

      : "=c" (dummy_value_c),            // output regs (dummy)
        "=S" (dummy_value_S),
        "=D" (dummy_value_D),
        "=a" (dummy_value_a),
        "=d" (dummy_value_d)

      : "0" (bpp),         // ecx        // input regs
        "1" (prev_row),    // esi/rsi
        "2" (row),         // edi/rdi
        "3" (MMXLength),   // eax
        "4" (FullLength)   // edx

      CLOB_COLON_ebx_ebp                 // clobber list
        CLOBBER_GOT_ebx
        CLOB_COMMA_ebx_ebp
        CLOBBER_ebp
   );

} /* end png_read_filter_row_mmx_avg() */

#endif /* PNG_MMX_READ_FILTER_AVG_SUPPORTED */



#if defined(PNG_MMX_READ_FILTER_PAETH_SUPPORTED)
#if defined(PNG_x86_64_USE_GOTPCREL) || defined(PNG_THREAD_UNSAFE_OK)

//===========================================================================//
//                                                                           //
//         P N G _ R E A D _ F I L T E R _ R O W _ M M X _ P A E T H         //
//                                                                           //
//===========================================================================//

// Optimized code for PNG Paeth filter decoder

static void /* PRIVATE */
png_read_filter_row_mmx_paeth(png_row_infop row_info, png_bytep row,
                              png_bytep prev_row)
{
   unsigned FullLength, MMXLength;  // png_uint_32 is actually 64-bit on x86-64
   int bpp;
   int dummy_value_a;
   int dummy_value_c;   // fix 'forbidden register 2 (cx) was spilled' error
   int dummy_value_d;
   png_charp dummy_value_S;
   png_charp dummy_value_D;
   int diff; //     __attribute__((used));

   bpp = (row_info->pixel_depth + 7) >> 3;  // calc number of bytes per pixel
   FullLength = row_info->rowbytes;         // number of bytes to filter

   __asm__ __volatile__ (
      SAVE_GOT_ebx
      SAVE_r15
      SAVE_ebp
//pre "movl row, %2                \n\t" // edi/rdi
      "xorl %%ebx, %%ebx           \n\t" // ebx:  x offset
//pre "movl prev_row, %1           \n\t" // esi/rsi
      "xorl %%edx, %%edx           \n\t" // edx:  x-bpp offset
//pre "movl FullLength, %%eax      \n\t" // bring in via eax...
      SAVE_FullLength                    // ...but store for later use
      "xorl %%eax, %%eax           \n\t"

      // Compute the Raw value for the first bpp bytes
      // Note: the formula works out to be always
      //   Paeth(x) = Raw(x) + Prior(x)      where x < bpp
   "paeth_rlp:                     \n\t"
      "movb (%2," PBX ",), %%al    \n\t"
      "addb (%1," PBX ",), %%al    \n\t"
      "incl %%ebx                  \n\t"
//pre "cmpl bpp, %%ebx             \n\t" (bpp is preloaded into ecx)
      "cmpl %%ecx, %%ebx           \n\t"
      "movb %%al, -1(%2," PBX ",)  \n\t"
      "jb paeth_rlp                \n\t"

      // get # of bytes to alignment (note:  computing _delta_ of two pointers,
      // so hereafter %%ebp is sufficient even on 64-bit)
      "mov  %2, " PBP "            \n\t" // take start of row
      "add  " PBX "," PBP "        \n\t" // add bpp
      "add  $0xf, " PBP "          \n\t" // add 7+8 to incr past alignment bdry
//    "andl $0xfffffff8, %%ebp     \n\t" // mask to alignment boundary (32-bit!)
      CLEAR_BOTTOM_3_BITS  PBP    "\n\t" // mask to alignment boundary
      "sub  %2, " PBP "            \n\t" // subtract row ptr again => ebp =
      "jz paeth_go                 \n\t" //  target value of ebx at alignment

      "xorl %%ecx, %%ecx           \n\t"

      SAVE_r11_r12_r13

      // fix alignment
   "paeth_lp1:                     \n\t"
      "xorl %%eax, %%eax           \n\t"
      // pav = p - a = (a + b - c) - a = b - c
      "movb (%1," PBX ",), %%al    \n\t" // load Prior(x) into al
      "movb (%1," PDX ",), %%cl    \n\t" // load Prior(x-bpp) into cl
      "subl %%ecx, %%eax           \n\t" // subtract Prior(x-bpp)
      "movl %%eax, " pa_TEMP "     \n\t" // Save pav for later use
      "xorl %%eax, %%eax           \n\t"
      // pbv = p - b = (a + b - c) - b = a - c
      "movb (%2," PDX ",), %%al    \n\t" // load Raw(x-bpp) into al
      "subl %%ecx, %%eax           \n\t" // subtract Prior(x-bpp)
      "movl %%eax, %%ecx           \n\t"
      // pcv = p - c = (a + b - c) - c = (a - c) + (b - c) = pav + pbv
      "addl " pa_TEMP ", %%eax     \n\t" // pcv = pav + pbv
      // pc = abs(pcv)
      "testl $0x80000000, %%eax    \n\t"
      "jz paeth_pca                \n\t"
      "negl %%eax                  \n\t" // reverse sign of neg values

   "paeth_pca:                     \n\t"
      "movl %%eax, " pc_TEMP "     \n\t" // save pc for later use
      // pb = abs(pbv)
      "testl $0x80000000, %%ecx    \n\t"
      "jz paeth_pba                \n\t"
      "negl %%ecx                  \n\t" // reverse sign of neg values

   "paeth_pba:                     \n\t"
      "movl %%ecx, " pb_TEMP "     \n\t" // save pb for later use
      // pa = abs(pav)
      "movl " pa_TEMP ", %%eax     \n\t"
      "testl $0x80000000, %%eax    \n\t"
      "jz paeth_paa                \n\t"
      "negl %%eax                  \n\t" // reverse sign of neg values

   "paeth_paa:                     \n\t"
      "movl %%eax, " pa_TEMP "     \n\t" // save pa for later use
      // test if pa <= pb
      "cmpl %%ecx, %%eax           \n\t"
      "jna paeth_abb               \n\t"
      // pa > pb; now test if pb <= pc
      "cmpl " pc_TEMP ", %%ecx     \n\t"
      "jna paeth_bbc               \n\t"
      // pb > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
      "movb (%1," PDX ",), %%cl    \n\t" // load Prior(x-bpp) into cl
      "jmp paeth_paeth             \n\t"

   "paeth_bbc:                     \n\t"
      // pb <= pc; Raw(x) = Paeth(x) + Prior(x)
      "movb (%1," PBX ",), %%cl    \n\t" // load Prior(x) into cl
      "jmp paeth_paeth             \n\t"

   "paeth_abb:                     \n\t"
      // pa <= pb; now test if pa <= pc
      "cmpl " pc_TEMP ", %%eax     \n\t"
      "jna paeth_abc               \n\t"
      // pa > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
      "movb (%1," PDX ",), %%cl    \n\t" // load Prior(x-bpp) into cl
      "jmp paeth_paeth             \n\t"

   "paeth_abc:                     \n\t"
      // pa <= pc; Raw(x) = Paeth(x) + Raw(x-bpp)
      "movb (%2," PDX ",), %%cl    \n\t" // load Raw(x-bpp) into cl

   "paeth_paeth:                   \n\t"
      "incl %%ebx                  \n\t"
      "incl %%edx                  \n\t"
      // Raw(x) = (Paeth(x) + Paeth_Predictor( a, b, c )) mod 256
      "addb %%cl, -1(%2," PBX ",)  \n\t"
      "cmpl %%ebp, %%ebx           \n\t"
      "jb paeth_lp1                \n\t"

      RESTORE_r11_r12_r13

   "paeth_go:                      \n\t"
      RESTORE_FullLength "%%ecx    \n\t" // FullLength -> ecx
      "movl %%ecx, %%eax           \n\t"
      "subl %%ebx, %%eax           \n\t" // subtract alignment fix
      "andl $0x00000007, %%eax     \n\t" // calc bytes over mult of 8
      "subl %%eax, %%ecx           \n\t" // drop over bytes from original length
//out "movl %%ecx, MMXLength       \n\t"
      "movl %%ebp, %%eax           \n\t" // ebp = diff, but no reg constraint(?)
      RESTORE_ebp                        //  (could swap ebp and edx functions)
      RESTORE_r15
      RESTORE_GOT_ebx

      : "=c" (MMXLength),                // output regs
        "=S" (dummy_value_S),
        "=D" (dummy_value_D),
        "=a" (diff)

      : "0" (bpp),         // ecx        // input regs
        "1" (prev_row),    // esi/rsi
        "2" (row),         // edi/rdi
        "3" (FullLength)   // eax

      : "%edx"                           // clobber list
        _CLOBBER_r11_r12_r13
        _CLOBBER_r15
        _CLOBBER_ebp
        _CLOBBER_GOT_ebx
   );

   // now do the math for the rest of the row
   switch (bpp)
   {
      case 3:
      {
//       _ShiftBpp = 24;    // == bpp * 8
//       _ShiftRem = 40;    // == 64 - _ShiftBpp

         __asm__ __volatile__ (
            LOAD_GOT_rbp
// preload  "movl diff, %%ecx            \n\t"
// preload  "movl row, %1                \n\t" // edi/rdi
// preload  "movl prev_row, %0           \n\t" // esi/rsi
            "pxor %%mm0, %%mm0           \n\t"

            // prime the pump:  load the first Raw(x-bpp) data set
            "movq -8(%1," PCX ",), %%mm1 \n\t"
         "paeth_3lp:                     \n\t"
            "psrlq $40, %%mm1            \n\t" // shift last 3 bytes to 1st
                                               // 3 bytes
            "movq (%0," PCX ",), %%mm2   \n\t" // load b=Prior(x)
            "punpcklbw %%mm0, %%mm1      \n\t" // unpack High bytes of a
            "movq -8(%0," PCX ",), %%mm3 \n\t" // prep c=Prior(x-bpp) bytes
            "punpcklbw %%mm0, %%mm2      \n\t" // unpack High bytes of b
            "psrlq $40, %%mm3            \n\t" // shift last 3 bytes to 1st
                                               // 3 bytes
            // pav = p - a = (a + b - c) - a = b - c
            "movq %%mm2, %%mm4           \n\t"
            "punpcklbw %%mm0, %%mm3      \n\t" // unpack High bytes of c
            // pbv = p - b = (a + b - c) - b = a - c
            "movq %%mm1, %%mm5           \n\t"
            "psubw %%mm3, %%mm4          \n\t"
            "pxor %%mm7, %%mm7           \n\t"
            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
            "movq %%mm4, %%mm6           \n\t"
            "psubw %%mm3, %%mm5          \n\t"

            // pa = abs(p-a) = abs(pav)
            // pb = abs(p-b) = abs(pbv)
            // pc = abs(p-c) = abs(pcv)
            "pcmpgtw %%mm4, %%mm0        \n\t" // create mask pav bytes < 0
            "paddw %%mm5, %%mm6          \n\t"
            "pand %%mm4, %%mm0           \n\t" // only pav bytes < 0 in mm7
            "pcmpgtw %%mm5, %%mm7        \n\t" // create mask pbv bytes < 0
            "psubw %%mm0, %%mm4          \n\t"
            "pand %%mm5, %%mm7           \n\t" // only pbv bytes < 0 in mm0
            "psubw %%mm0, %%mm4          \n\t"
            "psubw %%mm7, %%mm5          \n\t"
            "pxor %%mm0, %%mm0           \n\t"
            "pcmpgtw %%mm6, %%mm0        \n\t" // create mask pcv bytes < 0
            "pand %%mm6, %%mm0           \n\t" // only pav bytes < 0 in mm7
            "psubw %%mm7, %%mm5          \n\t"
            "psubw %%mm0, %%mm6          \n\t"
            //  test pa <= pb
            "movq %%mm4, %%mm7           \n\t"
            "psubw %%mm0, %%mm6          \n\t"
            "pcmpgtw %%mm5, %%mm7        \n\t" // pa > pb?
            "movq %%mm7, %%mm0           \n\t"
            // use mm7 mask to merge pa & pb
            "pand %%mm7, %%mm5           \n\t"
            // use mm0 mask copy to merge a & b
            "pand %%mm0, %%mm2           \n\t"
            "pandn %%mm4, %%mm7          \n\t"
            "pandn %%mm1, %%mm0          \n\t"
            "paddw %%mm5, %%mm7          \n\t"
            "paddw %%mm2, %%mm0          \n\t"
            //  test  ((pa <= pb)? pa:pb) <= pc
            "pcmpgtw %%mm6, %%mm7        \n\t" // pab > pc?
            "pxor %%mm1, %%mm1           \n\t"
            "pand %%mm7, %%mm3           \n\t"
            "pandn %%mm0, %%mm7          \n\t"
            "paddw %%mm3, %%mm7          \n\t"
            "pxor %%mm0, %%mm0           \n\t"
            "packuswb %%mm1, %%mm7       \n\t"
            "movq (%0," PCX ",), %%mm3   \n\t" // load c=Prior(x-bpp)
            "pand " AMASK5_3_0 ", %%mm7  \n\t" // _amask5_3_0 (was _ActiveMask)
            "movq %%mm3, %%mm2           \n\t" // load b=Prior(x) step 1
            "paddb (%1," PCX ",), %%mm7  \n\t" // add Paeth predictor + Raw(x)
            "punpcklbw %%mm0, %%mm3      \n\t" // unpack High bytes of c
            "movq %%mm7, (%1," PCX ",)   \n\t" // write back updated value
            "movq %%mm7, %%mm1           \n\t" // now mm1 will be used as
                                               // Raw(x-bpp)
            // now do Paeth for 2nd set of bytes (3-5)
            "psrlq $24, %%mm2            \n\t" // load b=Prior(x) step 2
            "punpcklbw %%mm0, %%mm1      \n\t" // unpack High bytes of a
            "pxor %%mm7, %%mm7           \n\t"
            "punpcklbw %%mm0, %%mm2      \n\t" // unpack High bytes of b
            // pbv = p - b = (a + b - c) - b = a - c
            "movq %%mm1, %%mm5           \n\t"
            // pav = p - a = (a + b - c) - a = b - c
            "movq %%mm2, %%mm4           \n\t"
            "psubw %%mm3, %%mm5          \n\t"
            "psubw %%mm3, %%mm4          \n\t"
            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) =
            //       pav + pbv = pbv + pav
            "movq %%mm5, %%mm6           \n\t"
            "paddw %%mm4, %%mm6          \n\t"

            // pa = abs(p-a) = abs(pav)
            // pb = abs(p-b) = abs(pbv)
            // pc = abs(p-c) = abs(pcv)
            "pcmpgtw %%mm5, %%mm0        \n\t" // create mask pbv bytes < 0
            "pcmpgtw %%mm4, %%mm7        \n\t" // create mask pav bytes < 0
            "pand %%mm5, %%mm0           \n\t" // only pbv bytes < 0 in mm0
            "pand %%mm4, %%mm7           \n\t" // only pav bytes < 0 in mm7
            "psubw %%mm0, %%mm5          \n\t"
            "psubw %%mm7, %%mm4          \n\t"
            "psubw %%mm0, %%mm5          \n\t"
            "psubw %%mm7, %%mm4          \n\t"
            "pxor %%mm0, %%mm0           \n\t"
            "pcmpgtw %%mm6, %%mm0        \n\t" // create mask pcv bytes < 0
            "pand %%mm6, %%mm0           \n\t" // only pav bytes < 0 in mm7
            "psubw %%mm0, %%mm6          \n\t"
            //  test pa <= pb
            "movq %%mm4, %%mm7           \n\t"
            "psubw %%mm0, %%mm6          \n\t"
            "pcmpgtw %%mm5, %%mm7        \n\t" // pa > pb?
            "movq %%mm7, %%mm0           \n\t"
            // use mm7 mask to merge pa & pb
            "pand %%mm7, %%mm5           \n\t"
            // use mm0 mask copy to merge a & b
            "pand %%mm0, %%mm2           \n\t"
            "pandn %%mm4, %%mm7          \n\t"
            "pandn %%mm1, %%mm0          \n\t"
            "paddw %%mm5, %%mm7          \n\t"
            "paddw %%mm2, %%mm0          \n\t"
            //  test  ((pa <= pb)? pa:pb) <= pc
            "pcmpgtw %%mm6, %%mm7        \n\t" // pab > pc?
            "movq (%0," PCX ",), %%mm2   \n\t" // load b=Prior(x)
            "pand %%mm7, %%mm3           \n\t"
            "pandn %%mm0, %%mm7          \n\t"
            "pxor %%mm1, %%mm1           \n\t"
            "paddw %%mm3, %%mm7          \n\t"
            "pxor %%mm0, %%mm0           \n\t"
            "packuswb %%mm1, %%mm7       \n\t"
            "movq %%mm2, %%mm3           \n\t" // load c=Prior(x-bpp) step 1
            "pand " AMASK5_3_0 ", %%mm7  \n\t" // _amask5_3_0 (was _ActiveMask)
            "punpckhbw %%mm0, %%mm2      \n\t" // unpack High bytes of b
            "psllq $24, %%mm7            \n\t" // shift bytes to 2nd group of
                                               // 3 bytes
             // pav = p - a = (a + b - c) - a = b - c
            "movq %%mm2, %%mm4           \n\t"
            "paddb (%1," PCX ",), %%mm7  \n\t" // add Paeth predictor + Raw(x)
            "psllq $24, %%mm3            \n\t" // load c=Prior(x-bpp) step 2
            "movq %%mm7, (%1," PCX ",)   \n\t" // write back updated value
            "movq %%mm7, %%mm1           \n\t"
            "punpckhbw %%mm0, %%mm3      \n\t" // unpack High bytes of c
            "psllq $24, %%mm1            \n\t" // shift bytes (was _ShiftBpp)
                                    // now mm1 will be used as Raw(x-bpp)
            // now do Paeth for 3rd, and final, set of bytes (6-7)
            "pxor %%mm7, %%mm7           \n\t"
            "punpckhbw %%mm0, %%mm1      \n\t" // unpack High bytes of a
            "psubw %%mm3, %%mm4          \n\t"
            // pbv = p - b = (a + b - c) - b = a - c
            "movq %%mm1, %%mm5           \n\t"
            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
            "movq %%mm4, %%mm6           \n\t"
            "psubw %%mm3, %%mm5          \n\t"
            "pxor %%mm0, %%mm0           \n\t"
            "paddw %%mm5, %%mm6          \n\t"

            // pa = abs(p-a) = abs(pav)
            // pb = abs(p-b) = abs(pbv)
            // pc = abs(p-c) = abs(pcv)
            "pcmpgtw %%mm4, %%mm0        \n\t" // create mask pav bytes < 0
            "pcmpgtw %%mm5, %%mm7        \n\t" // create mask pbv bytes < 0
            "pand %%mm4, %%mm0           \n\t" // only pav bytes < 0 in mm7
            "pand %%mm5, %%mm7           \n\t" // only pbv bytes < 0 in mm0
            "psubw %%mm0, %%mm4          \n\t"
            "psubw %%mm7, %%mm5          \n\t"
            "psubw %%mm0, %%mm4          \n\t"
            "psubw %%mm7, %%mm5          \n\t"
            "pxor %%mm0, %%mm0           \n\t"
            "pcmpgtw %%mm6, %%mm0        \n\t" // create mask pcv bytes < 0
            "pand %%mm6, %%mm0           \n\t" // only pav bytes < 0 in mm7
            "psubw %%mm0, %%mm6          \n\t"
            //  test pa <= pb
            "movq %%mm4, %%mm7           \n\t"
            "psubw %%mm0, %%mm6          \n\t"
            "pcmpgtw %%mm5, %%mm7        \n\t" // pa > pb?
            "movq %%mm7, %%mm0           \n\t"
            // use mm0 mask copy to merge a & b
            "pand %%mm0, %%mm2           \n\t"
            // use mm7 mask to merge pa & pb
            "pand %%mm7, %%mm5           \n\t"
            "pandn %%mm1, %%mm0          \n\t"
            "pandn %%mm4, %%mm7          \n\t"
            "paddw %%mm2, %%mm0          \n\t"
            "paddw %%mm5, %%mm7          \n\t"
            //  test  ((pa <= pb)? pa:pb) <= pc
            "pcmpgtw %%mm6, %%mm7        \n\t" // pab > pc?
            "pand %%mm7, %%mm3           \n\t"
            "pandn %%mm0, %%mm7          \n\t"
            "paddw %%mm3, %%mm7          \n\t"
            "pxor %%mm1, %%mm1           \n\t"
            "packuswb %%mm7, %%mm1       \n\t"
            // step ecx to next set of 8 bytes and repeat loop til done
            "addl $8, %%ecx              \n\t"
            "pand " AMASK0_2_6 ", %%mm1  \n\t" // _amask0_2_6 (_ActiveMaskEnd)
            "paddb -8(%1," PCX ",), %%mm1 \n\t" // add Paeth predictor + Raw(x)
            "cmpl %%eax, %%ecx           \n\t" // MMXLength
            "pxor %%mm0, %%mm0           \n\t" // pxor does not affect flags
            "movq %%mm1, -8(%1," PCX ",) \n\t" // write back updated value
                                 // mm1 will be used as Raw(x-bpp) next loop
                           // mm3 ready to be used as Prior(x-bpp) next loop
            "jb paeth_3lp                \n\t"
            RESTORE_rbp

            : "=S" (dummy_value_S),            // output regs (dummy)
              "=D" (dummy_value_D),
              "=c" (dummy_value_c),
              "=a" (dummy_value_a)

            : "0" (prev_row),  // esi/rsi      // input regs
              "1" (row),       // edi/rdi
              "2" (diff),      // ecx
              "3" (MMXLength)  // eax

#if defined(CLOBBER_MMX_REGS_SUPPORTED)
            : "%mm0", "%mm1", "%mm2", "%mm3"   // clobber list
            , "%mm4", "%mm5", "%mm6", "%mm7"
#endif
         );
      }
      break;  // end 3 bpp

      case 4:
      {
         __asm__ __volatile__ (
// preload  "movl diff, %%ecx            \n\t"
// preload  "movl row, %1                \n\t" // edi/rdi
// preload  "movl prev_row, %0           \n\t" // esi/rsi
            "pxor %%mm0, %%mm0           \n\t"
            // prime the pump:  load the first Raw(x-bpp) data set
            "movq -8(%1," PCX ",), %%mm1 \n\t" // only time should need to read
                                               //  a=Raw(x-bpp) bytes
         "paeth_4lp:                     \n\t"
            // do first set of 4 bytes
            "movq -8(%0," PCX ",), %%mm3 \n\t" // read c=Prior(x-bpp) bytes
            "punpckhbw %%mm0, %%mm1      \n\t" // unpack Low bytes of a
            "movq (%0," PCX ",), %%mm2   \n\t" // load b=Prior(x)
            "punpcklbw %%mm0, %%mm2      \n\t" // unpack High bytes of b
            // pav = p - a = (a + b - c) - a = b - c
            "movq %%mm2, %%mm4           \n\t"
            "punpckhbw %%mm0, %%mm3      \n\t" // unpack High bytes of c
            // pbv = p - b = (a + b - c) - b = a - c
            "movq %%mm1, %%mm5           \n\t"
            "psubw %%mm3, %%mm4          \n\t"
            "pxor %%mm7, %%mm7           \n\t"
            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
            "movq %%mm4, %%mm6           \n\t"
            "psubw %%mm3, %%mm5          \n\t"
            // pa = abs(p-a) = abs(pav)
            // pb = abs(p-b) = abs(pbv)
            // pc = abs(p-c) = abs(pcv)
            "pcmpgtw %%mm4, %%mm0        \n\t" // create mask pav bytes < 0
            "paddw %%mm5, %%mm6          \n\t"
            "pand %%mm4, %%mm0           \n\t" // only pav bytes < 0 in mm7
            "pcmpgtw %%mm5, %%mm7        \n\t" // create mask pbv bytes < 0
            "psubw %%mm0, %%mm4          \n\t"
            "pand %%mm5, %%mm7           \n\t" // only pbv bytes < 0 in mm0
            "psubw %%mm0, %%mm4          \n\t"
            "psubw %%mm7, %%mm5          \n\t"
            "pxor %%mm0, %%mm0           \n\t"
            "pcmpgtw %%mm6, %%mm0        \n\t" // create mask pcv bytes < 0
            "pand %%mm6, %%mm0           \n\t" // only pav bytes < 0 in mm7
            "psubw %%mm7, %%mm5          \n\t"
            "psubw %%mm0, %%mm6          \n\t"
            //  test pa <= pb
            "movq %%mm4, %%mm7           \n\t"
            "psubw %%mm0, %%mm6          \n\t"
            "pcmpgtw %%mm5, %%mm7        \n\t" // pa > pb?
            "movq %%mm7, %%mm0           \n\t"
            // use mm7 mask to merge pa & pb
            "pand %%mm7, %%mm5           \n\t"
            // use mm0 mask copy to merge a & b
            "pand %%mm0, %%mm2           \n\t"
            "pandn %%mm4, %%mm7          \n\t"
            "pandn %%mm1, %%mm0          \n\t"
            "paddw %%mm5, %%mm7          \n\t"
            "paddw %%mm2, %%mm0          \n\t"
            //  test  ((pa <= pb)? pa:pb) <= pc
            "pcmpgtw %%mm6, %%mm7        \n\t" // pab > pc?
            "pxor %%mm1, %%mm1           \n\t"
            "pand %%mm7, %%mm3           \n\t"
            "pandn %%mm0, %%mm7          \n\t"
            "paddw %%mm3, %%mm7          \n\t"
            "pxor %%mm0, %%mm0           \n\t"
            "packuswb %%mm1, %%mm7       \n\t"
            "movq (%0," PCX ",), %%mm3   \n\t" // load c=Prior(x-bpp)
            LOAD_GOT_rbp
            "pand " AMASK4_4_0 ", %%mm7  \n\t" // _amask4_4_0 (was _ActiveMask)
            RESTORE_rbp
            "movq %%mm3, %%mm2           \n\t" // load b=Prior(x) step 1
            "paddb (%1," PCX ",), %%mm7  \n\t" // add Paeth predictor + Raw(x)
            "punpcklbw %%mm0, %%mm3      \n\t" // unpack High bytes of c
            "movq %%mm7, (%1," PCX ",)   \n\t" // write back updated value
            "movq %%mm7, %%mm1           \n\t" // now mm1 will be used as
                                               // Raw(x-bpp)
            // do second set of 4 bytes
            "punpckhbw %%mm0, %%mm2      \n\t" // unpack Low bytes of b
            "punpcklbw %%mm0, %%mm1      \n\t" // unpack Low bytes of a
            // pav = p - a = (a + b - c) - a = b - c
            "movq %%mm2, %%mm4           \n\t"
            // pbv = p - b = (a + b - c) - b = a - c
            "movq %%mm1, %%mm5           \n\t"
            "psubw %%mm3, %%mm4          \n\t"
            "pxor %%mm7, %%mm7           \n\t"
            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
            "movq %%mm4, %%mm6           \n\t"
            "psubw %%mm3, %%mm5          \n\t"
            // pa = abs(p-a) = abs(pav)
            // pb = abs(p-b) = abs(pbv)
            // pc = abs(p-c) = abs(pcv)
            "pcmpgtw %%mm4, %%mm0        \n\t" // create mask pav bytes < 0
            "paddw %%mm5, %%mm6          \n\t"
            "pand %%mm4, %%mm0           \n\t" // only pav bytes < 0 in mm7
            "pcmpgtw %%mm5, %%mm7        \n\t" // create mask pbv bytes < 0
            "psubw %%mm0, %%mm4          \n\t"
            "pand %%mm5, %%mm7           \n\t" // only pbv bytes < 0 in mm0
            "psubw %%mm0, %%mm4          \n\t"
            "psubw %%mm7, %%mm5          \n\t"
            "pxor %%mm0, %%mm0           \n\t"
            "pcmpgtw %%mm6, %%mm0        \n\t" // create mask pcv bytes < 0
            "pand %%mm6, %%mm0           \n\t" // only pav bytes < 0 in mm7
            "psubw %%mm7, %%mm5          \n\t"
            "psubw %%mm0, %%mm6          \n\t"
            //  test pa <= pb
            "movq %%mm4, %%mm7           \n\t"
            "psubw %%mm0, %%mm6          \n\t"
            "pcmpgtw %%mm5, %%mm7        \n\t" // pa > pb?
            "movq %%mm7, %%mm0           \n\t"
            // use mm7 mask to merge pa & pb
            "pand %%mm7, %%mm5           \n\t"
            // use mm0 mask copy to merge a & b
            "pand %%mm0, %%mm2           \n\t"
            "pandn %%mm4, %%mm7          \n\t"
            "pandn %%mm1, %%mm0          \n\t"
            "paddw %%mm5, %%mm7          \n\t"
            "paddw %%mm2, %%mm0          \n\t"
            //  test  ((pa <= pb)? pa:pb) <= pc
            "pcmpgtw %%mm6, %%mm7        \n\t" // pab > pc?
            "pxor %%mm1, %%mm1           \n\t"
            "pand %%mm7, %%mm3           \n\t"
            "pandn %%mm0, %%mm7          \n\t"
            "pxor %%mm1, %%mm1           \n\t"
            "paddw %%mm3, %%mm7          \n\t"
            "pxor %%mm0, %%mm0           \n\t"
            // step ecx to next set of 8 bytes and repeat loop til done
            "addl $8, %%ecx              \n\t"
            "packuswb %%mm7, %%mm1       \n\t"
            "paddb -8(%1," PCX ",), %%mm1 \n\t" // add predictor with Raw(x)
            "cmpl %%eax, %%ecx           \n\t" // MMXLength
            "movq %%mm1, -8(%1," PCX ",) \n\t" // write back updated value
                                 // mm1 will be used as Raw(x-bpp) next loop
            "jb paeth_4lp                \n\t"

            : "=S" (dummy_value_S),            // output regs (dummy)
              "=D" (dummy_value_D),
              "=c" (dummy_value_c),
              "=a" (dummy_value_a)

            : "0" (prev_row),  // esi/rsi      // input regs
              "1" (row),       // edi/rdi
              "2" (diff),      // ecx
              "3" (MMXLength)  // eax

#if defined(CLOBBER_MMX_REGS_SUPPORTED)
            : "%mm0", "%mm1", "%mm2", "%mm3"   // clobber list
            , "%mm4", "%mm5", "%mm6", "%mm7"
#endif
         );
      }
      break;  // end 4 bpp

      case 1:
      case 2:
      {
         __asm__ __volatile__ (
// preload  "movl diff, %%eax            \n\t" // eax: x = offset to align. bdry
// preload  "movl FullLength, %%edx      \n\t"
            "cmpl %%edx, %%eax           \n\t"
            "jnb paeth_dend              \n\t"

            SAVE_ebp

// preload  "movl row, %2                \n\t" // edi/rdi
            // do Paeth decode for remaining bytes
// preload  "movl prev_row, %1           \n\t" // esi/rsi
            "movl %%eax, %%ebp           \n\t"
// preload  "subl bpp, %%ebp             \n\t" // (bpp is preloaded into ecx)
            "subl %%ecx, %%ebp           \n\t" // ebp = eax - bpp
            "xorl %%ecx, %%ecx           \n\t" // zero ecx before using cl & cx

            SAVE_GOT_ebx
            SAVE_r11_r12_r13

         "paeth_dlp:                     \n\t"
            "xorl %%ebx, %%ebx           \n\t"
            // pav = p - a = (a + b - c) - a = b - c
            "movb (%1," PAX ",), %%bl    \n\t" // load Prior(x) into bl
            "movb (%1," PBP ",), %%cl    \n\t" // load Prior(x-bpp) into cl
            "subl %%ecx, %%ebx           \n\t" // subtract Prior(x-bpp)
            "movl %%ebx, " pa_TEMP "     \n\t" // Save pav for later use
            "xorl %%ebx, %%ebx           \n\t"
            // pbv = p - b = (a + b - c) - b = a - c
            "movb (%2," PBP ",), %%bl    \n\t" // load Raw(x-bpp) into bl
            "subl %%ecx, %%ebx           \n\t" // subtract Prior(x-bpp)
            "movl %%ebx, %%ecx           \n\t"
            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
            "addl " pa_TEMP ", %%ebx     \n\t" // pcv = pav + pbv
            // pc = abs(pcv)
            "testl $0x80000000, %%ebx    \n\t"
            "jz paeth_dpca               \n\t"
            "negl %%ebx                  \n\t" // reverse sign of neg values

         "paeth_dpca:                    \n\t"
            "movl %%ebx, " pc_TEMP "     \n\t" // save pc for later use
            // pb = abs(pbv)
            "testl $0x80000000, %%ecx    \n\t"
            "jz paeth_dpba               \n\t"
            "negl %%ecx                  \n\t" // reverse sign of neg values

         "paeth_dpba:                    \n\t"
            "movl %%ecx, " pb_TEMP "     \n\t" // save pb for later use
            // pa = abs(pav)
            "movl " pa_TEMP ", %%ebx     \n\t"
            "testl $0x80000000, %%ebx    \n\t"
            "jz paeth_dpaa               \n\t"
            "negl %%ebx                  \n\t" // reverse sign of neg values

         "paeth_dpaa:                    \n\t"
            "movl %%ebx, " pa_TEMP "     \n\t" // save pa for later use
            // test if pa <= pb
            "cmpl %%ecx, %%ebx           \n\t"
            "jna paeth_dabb              \n\t"
            // pa > pb; now test if pb <= pc
            "cmpl " pc_TEMP ", %%ecx     \n\t"
            "jna paeth_dbbc              \n\t"
            // pb > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
            "movb (%1," PBP ",), %%cl    \n\t" // load Prior(x-bpp) into cl
            "jmp paeth_dpaeth            \n\t"

         "paeth_dbbc:                    \n\t"
            // pb <= pc; Raw(x) = Paeth(x) + Prior(x)
            "movb (%1," PAX ",), %%cl    \n\t" // load Prior(x) into cl
            "jmp paeth_dpaeth            \n\t"

         "paeth_dabb:                    \n\t"
            // pa <= pb; now test if pa <= pc
            "cmpl " pc_TEMP ", %%ebx     \n\t"
            "jna paeth_dabc              \n\t"
            // pa > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
            "movb (%1," PBP ",), %%cl   \n\t" // load Prior(x-bpp) into cl
            "jmp paeth_dpaeth            \n\t"

         "paeth_dabc:                    \n\t"
            // pa <= pc; Raw(x) = Paeth(x) + Raw(x-bpp)
            "movb (%2," PBP ",), %%cl    \n\t" // load Raw(x-bpp) into cl

         "paeth_dpaeth:                  \n\t"
            "incl %%eax                  \n\t"
            "incl %%ebp                  \n\t"
            // Raw(x) = (Paeth(x) + Paeth_Predictor( a, b, c )) mod 256
            "addb %%cl, -1(%2," PAX ",)  \n\t"
            "cmpl %%edx, %%eax           \n\t" // check against FullLength
            "jb paeth_dlp                \n\t"

            RESTORE_r11_r12_r13
            RESTORE_GOT_ebx
            RESTORE_ebp

         "paeth_dend:                    \n\t"

            : "=c" (dummy_value_c),            // output regs (dummy)
              "=S" (dummy_value_S),
              "=D" (dummy_value_D),
              "=a" (dummy_value_a),
              "=d" (dummy_value_d)

            : "0" (bpp),         // ecx        // input regs
              "1" (prev_row),    // esi/rsi
              "2" (row),         // edi/rdi
              "3" (diff),        // eax
              "4" (FullLength)   // edx

            CLOB_COLON_ebx_ebp_r1X             // clobber list
              CLOBBER_GOT_ebx
              CLOB_COMMA_ebx_ebp
              CLOBBER_ebp
              CLOB_COMMA_ebX_r1X
              CLOBBER_r11_r12_r13
         );
      }
      return; // end 1 or 2 bpp (no need to go further with this one)

      case 6:
      {
//       _ActiveMask2 = 0xffffffff00000000LL;  // NOT USED ("_amask_0_4_4")
//       _ShiftBpp = 48;       // bpp << 3 == bpp * 8
//       _ShiftRem = 16;       // 64 - _ShiftBpp

         __asm__ __volatile__ (
// preload  "movl diff, %%ecx            \n\t"
// preload  "movl row, %1                \n\t" // edi/rdi
// preload  "movl prev_row, %0           \n\t" // esi/rsi
            // prime the pump:  load the first Raw(x-bpp) data set
            "movq -8(%1," PCX ",), %%mm1 \n\t"
            "pxor %%mm0, %%mm0           \n\t"

         "paeth_6lp:                     \n\t"
            // must shift to position Raw(x-bpp) data
            "psrlq $16, %%mm1            \n\t" // was _ShiftRem
            // do first set of 4 bytes
            "movq -8(%0," PCX ",), %%mm3 \n\t" // read c=Prior(x-bpp) bytes
            "punpcklbw %%mm0, %%mm1      \n\t" // unpack Low bytes of a
            "movq (%0," PCX ",), %%mm2   \n\t" // load b=Prior(x)
            "punpcklbw %%mm0, %%mm2      \n\t" // unpack Low bytes of b
            // must shift to position Prior(x-bpp) data
            "psrlq $16, %%mm3            \n\t" // was _ShiftRem
            // pav = p - a = (a + b - c) - a = b - c
            "movq %%mm2, %%mm4           \n\t"
            "punpcklbw %%mm0, %%mm3      \n\t" // unpack Low bytes of c
            // pbv = p - b = (a + b - c) - b = a - c
            "movq %%mm1, %%mm5           \n\t"
            "psubw %%mm3, %%mm4          \n\t"
            "pxor %%mm7, %%mm7           \n\t"
            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
            "movq %%mm4, %%mm6           \n\t"
            "psubw %%mm3, %%mm5          \n\t"
            // pa = abs(p-a) = abs(pav)
            // pb = abs(p-b) = abs(pbv)
            // pc = abs(p-c) = abs(pcv)
            "pcmpgtw %%mm4, %%mm0        \n\t" // create mask pav bytes < 0
            "paddw %%mm5, %%mm6          \n\t"
            "pand %%mm4, %%mm0           \n\t" // only pav bytes < 0 in mm7
            "pcmpgtw %%mm5, %%mm7        \n\t" // create mask pbv bytes < 0
            "psubw %%mm0, %%mm4          \n\t"
            "pand %%mm5, %%mm7           \n\t" // only pbv bytes < 0 in mm0
            "psubw %%mm0, %%mm4          \n\t"
            "psubw %%mm7, %%mm5          \n\t"
            "pxor %%mm0, %%mm0           \n\t"
            "pcmpgtw %%mm6, %%mm0        \n\t" // create mask pcv bytes < 0
            "pand %%mm6, %%mm0           \n\t" // only pav bytes < 0 in mm7
            "psubw %%mm7, %%mm5          \n\t"
            "psubw %%mm0, %%mm6          \n\t"
            //  test pa <= pb
            "movq %%mm4, %%mm7           \n\t"
            "psubw %%mm0, %%mm6          \n\t"
            "pcmpgtw %%mm5, %%mm7        \n\t" // pa > pb?
            "movq %%mm7, %%mm0           \n\t"
            // use mm7 mask to merge pa & pb
            "pand %%mm7, %%mm5           \n\t"
            // use mm0 mask copy to merge a & b
            "pand %%mm0, %%mm2           \n\t"
            "pandn %%mm4, %%mm7          \n\t"
            "pandn %%mm1, %%mm0          \n\t"
            "paddw %%mm5, %%mm7          \n\t"
            "paddw %%mm2, %%mm0          \n\t"
            //  test  ((pa <= pb)? pa:pb) <= pc
            "pcmpgtw %%mm6, %%mm7        \n\t" // pab > pc?
            "pxor %%mm1, %%mm1           \n\t"
            "pand %%mm7, %%mm3           \n\t"
            "pandn %%mm0, %%mm7          \n\t"
            "paddw %%mm3, %%mm7          \n\t"
            "pxor %%mm0, %%mm0           \n\t"
            "packuswb %%mm1, %%mm7       \n\t"
            "movq -8(%0," PCX ",), %%mm3 \n\t" // load c=Prior(x-bpp)
            LOAD_GOT_rbp
            "pand " AMASK4_4_0 ", %%mm7  \n\t" // _amask4_4_0 (was _ActiveMask)
            RESTORE_rbp
            "psrlq $16, %%mm3            \n\t"
            "movq (%0," PCX ",), %%mm2   \n\t" // load b=Prior(x) step 1
            "paddb (%1," PCX ",), %%mm7  \n\t" // add Paeth predictor + Raw(x)
            "movq %%mm2, %%mm6           \n\t"
            "movq %%mm7, (%1," PCX ",)   \n\t" // write back updated value
            "movq -8(%1," PCX ",), %%mm1 \n\t"
            "psllq $48, %%mm6            \n\t" // bpp * 8 = bits per pixel
            "movq %%mm7, %%mm5           \n\t"
            "psrlq $16, %%mm1            \n\t" // 64 - (bpp * 8) = remainder
            "por %%mm6, %%mm3            \n\t"
            "psllq $48, %%mm5            \n\t" // was _ShiftBpp
            "punpckhbw %%mm0, %%mm3      \n\t" // unpack High bytes of c
            "por %%mm5, %%mm1            \n\t"
            // do second set of 4 bytes
            "punpckhbw %%mm0, %%mm2      \n\t" // unpack High bytes of b
            "punpckhbw %%mm0, %%mm1      \n\t" // unpack High bytes of a
            // pav = p - a = (a + b - c) - a = b - c
            "movq %%mm2, %%mm4           \n\t"
            // pbv = p - b = (a + b - c) - b = a - c
            "movq %%mm1, %%mm5           \n\t"
            "psubw %%mm3, %%mm4          \n\t"
            "pxor %%mm7, %%mm7           \n\t"
            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
            "movq %%mm4, %%mm6           \n\t"
            "psubw %%mm3, %%mm5          \n\t"
            // pa = abs(p-a) = abs(pav)
            // pb = abs(p-b) = abs(pbv)
            // pc = abs(p-c) = abs(pcv)
            "pcmpgtw %%mm4, %%mm0        \n\t" // create mask pav bytes < 0
            "paddw %%mm5, %%mm6          \n\t"
            "pand %%mm4, %%mm0           \n\t" // only pav bytes < 0 in mm7
            "pcmpgtw %%mm5, %%mm7        \n\t" // create mask pbv bytes < 0
            "psubw %%mm0, %%mm4          \n\t"
            "pand %%mm5, %%mm7           \n\t" // only pbv bytes < 0 in mm0
            "psubw %%mm0, %%mm4          \n\t"
            "psubw %%mm7, %%mm5          \n\t"
            "pxor %%mm0, %%mm0           \n\t"
            "pcmpgtw %%mm6, %%mm0        \n\t" // create mask pcv bytes < 0
            "pand %%mm6, %%mm0           \n\t" // only pav bytes < 0 in mm7
            "psubw %%mm7, %%mm5          \n\t"
            "psubw %%mm0, %%mm6          \n\t"
            //  test pa <= pb
            "movq %%mm4, %%mm7           \n\t"
            "psubw %%mm0, %%mm6          \n\t"
            "pcmpgtw %%mm5, %%mm7        \n\t" // pa > pb?
            "movq %%mm7, %%mm0           \n\t"
            // use mm7 mask to merge pa & pb
            "pand %%mm7, %%mm5           \n\t"
            // use mm0 mask copy to merge a & b
            "pand %%mm0, %%mm2           \n\t"
            "pandn %%mm4, %%mm7          \n\t"
            "pandn %%mm1, %%mm0          \n\t"
            "paddw %%mm5, %%mm7          \n\t"
            "paddw %%mm2, %%mm0          \n\t"
            //  test  ((pa <= pb)? pa:pb) <= pc
            "pcmpgtw %%mm6, %%mm7        \n\t" // pab > pc?
            "pxor %%mm1, %%mm1           \n\t"
            "pand %%mm7, %%mm3           \n\t"
            "pandn %%mm0, %%mm7          \n\t"
            "pxor %%mm1, %%mm1           \n\t"
            "paddw %%mm3, %%mm7          \n\t"
            "pxor %%mm0, %%mm0           \n\t"
            // step ecx to next set of 8 bytes and repeat loop til done
            "addl $8, %%ecx              \n\t"
            "packuswb %%mm7, %%mm1       \n\t"
            "paddb -8(%1," PCX ",), %%mm1 \n\t" // add Paeth predictor + Raw(x)
            "cmpl %%eax, %%ecx           \n\t" // MMXLength
            "movq %%mm1, -8(%1," PCX ",) \n\t" // write back updated value
                                 // mm1 will be used as Raw(x-bpp) next loop
            "jb paeth_6lp                \n\t"

            : "=S" (dummy_value_S),            // output regs (dummy)
              "=D" (dummy_value_D),
              "=c" (dummy_value_c),
              "=a" (dummy_value_a)

            : "0" (prev_row),  // esi/rsi      // input regs
              "1" (row),       // edi/rdi
              "2" (diff),      // ecx
              "3" (MMXLength)  // eax

#if defined(CLOBBER_MMX_REGS_SUPPORTED)
            : "%mm0", "%mm1", "%mm2", "%mm3"   // clobber list
            , "%mm4", "%mm5", "%mm6", "%mm7"
#endif
         );
      }
      break;  // end 6 bpp

      case 8:                          // bpp == 8
      {
         __asm__ __volatile__ (
// preload  "movl diff, %%ecx            \n\t"
// preload  "movl row, %1                \n\t" // edi/rdi
// preload  "movl prev_row, %0           \n\t" // esi/rsi
            "pxor %%mm0, %%mm0           \n\t"
            // prime the pump:  load the first Raw(x-bpp) data set
            "movq -8(%1," PCX ",), %%mm1 \n\t" // only time should need to read
                                               //  a=Raw(x-bpp) bytes
         "paeth_8lp:                     \n\t"
            // do first set of 4 bytes
            "movq -8(%0," PCX ",), %%mm3 \n\t" // read c=Prior(x-bpp) bytes
            "punpcklbw %%mm0, %%mm1      \n\t" // unpack Low bytes of a
            "movq (%0," PCX ",), %%mm2   \n\t" // load b=Prior(x)
            "punpcklbw %%mm0, %%mm2      \n\t" // unpack Low bytes of b
            // pav = p - a = (a + b - c) - a = b - c
            "movq %%mm2, %%mm4           \n\t"
            "punpcklbw %%mm0, %%mm3      \n\t" // unpack Low bytes of c
            // pbv = p - b = (a + b - c) - b = a - c
            "movq %%mm1, %%mm5           \n\t"
            "psubw %%mm3, %%mm4          \n\t"
            "pxor %%mm7, %%mm7           \n\t"
            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
            "movq %%mm4, %%mm6           \n\t"
            "psubw %%mm3, %%mm5          \n\t"
            // pa = abs(p-a) = abs(pav)
            // pb = abs(p-b) = abs(pbv)
            // pc = abs(p-c) = abs(pcv)
            "pcmpgtw %%mm4, %%mm0        \n\t" // create mask pav bytes < 0
            "paddw %%mm5, %%mm6          \n\t"
            "pand %%mm4, %%mm0           \n\t" // only pav bytes < 0 in mm7
            "pcmpgtw %%mm5, %%mm7        \n\t" // create mask pbv bytes < 0
            "psubw %%mm0, %%mm4          \n\t"
            "pand %%mm5, %%mm7           \n\t" // only pbv bytes < 0 in mm0
            "psubw %%mm0, %%mm4          \n\t"
            "psubw %%mm7, %%mm5          \n\t"
            "pxor %%mm0, %%mm0           \n\t"
            "pcmpgtw %%mm6, %%mm0        \n\t" // create mask pcv bytes < 0
            "pand %%mm6, %%mm0           \n\t" // only pav bytes < 0 in mm7
            "psubw %%mm7, %%mm5          \n\t"
            "psubw %%mm0, %%mm6          \n\t"
            //  test pa <= pb
            "movq %%mm4, %%mm7           \n\t"
            "psubw %%mm0, %%mm6          \n\t"
            "pcmpgtw %%mm5, %%mm7        \n\t" // pa > pb?
            "movq %%mm7, %%mm0           \n\t"
            // use mm7 mask to merge pa & pb
            "pand %%mm7, %%mm5           \n\t"
            // use mm0 mask copy to merge a & b
            "pand %%mm0, %%mm2           \n\t"
            "pandn %%mm4, %%mm7          \n\t"
            "pandn %%mm1, %%mm0          \n\t"
            "paddw %%mm5, %%mm7          \n\t"
            "paddw %%mm2, %%mm0          \n\t"
            //  test  ((pa <= pb)? pa:pb) <= pc
            "pcmpgtw %%mm6, %%mm7        \n\t" // pab > pc?
            "pxor %%mm1, %%mm1           \n\t"
            "pand %%mm7, %%mm3           \n\t"
            "pandn %%mm0, %%mm7          \n\t"
            "paddw %%mm3, %%mm7          \n\t"
            "pxor %%mm0, %%mm0           \n\t"
            "packuswb %%mm1, %%mm7       \n\t"
            "movq -8(%0," PCX ",), %%mm3 \n\t" // read c=Prior(x-bpp) bytes
            LOAD_GOT_rbp
            "pand " AMASK4_4_0 ", %%mm7  \n\t" // _amask4_4_0 (was _ActiveMask)
            RESTORE_rbp
            "movq (%0," PCX ",), %%mm2   \n\t" // load b=Prior(x)
            "paddb (%1," PCX ",), %%mm7  \n\t" // add Paeth predictor + Raw(x)
            "punpckhbw %%mm0, %%mm3      \n\t" // unpack High bytes of c
            "movq %%mm7, (%1," PCX ",)   \n\t" // write back updated value
            "movq -8(%1," PCX ",), %%mm1 \n\t" // read a=Raw(x-bpp) bytes

            // do second set of 4 bytes
            "punpckhbw %%mm0, %%mm2      \n\t" // unpack High bytes of b
            "punpckhbw %%mm0, %%mm1      \n\t" // unpack High bytes of a
            // pav = p - a = (a + b - c) - a = b - c
            "movq %%mm2, %%mm4           \n\t"
            // pbv = p - b = (a + b - c) - b = a - c
            "movq %%mm1, %%mm5           \n\t"
            "psubw %%mm3, %%mm4          \n\t"
            "pxor %%mm7, %%mm7           \n\t"
            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
            "movq %%mm4, %%mm6           \n\t"
            "psubw %%mm3, %%mm5          \n\t"
            // pa = abs(p-a) = abs(pav)
            // pb = abs(p-b) = abs(pbv)
            // pc = abs(p-c) = abs(pcv)
            "pcmpgtw %%mm4, %%mm0        \n\t" // create mask pav bytes < 0
            "paddw %%mm5, %%mm6          \n\t"
            "pand %%mm4, %%mm0           \n\t" // only pav bytes < 0 in mm7
            "pcmpgtw %%mm5, %%mm7        \n\t" // create mask pbv bytes < 0
            "psubw %%mm0, %%mm4          \n\t"
            "pand %%mm5, %%mm7           \n\t" // only pbv bytes < 0 in mm0
            "psubw %%mm0, %%mm4          \n\t"
            "psubw %%mm7, %%mm5          \n\t"
            "pxor %%mm0, %%mm0           \n\t"
            "pcmpgtw %%mm6, %%mm0        \n\t" // create mask pcv bytes < 0
            "pand %%mm6, %%mm0           \n\t" // only pav bytes < 0 in mm7
            "psubw %%mm7, %%mm5          \n\t"
            "psubw %%mm0, %%mm6          \n\t"
            //  test pa <= pb
            "movq %%mm4, %%mm7           \n\t"
            "psubw %%mm0, %%mm6          \n\t"
            "pcmpgtw %%mm5, %%mm7        \n\t" // pa > pb?
            "movq %%mm7, %%mm0           \n\t"
            // use mm7 mask to merge pa & pb
            "pand %%mm7, %%mm5           \n\t"
            // use mm0 mask copy to merge a & b
            "pand %%mm0, %%mm2           \n\t"
            "pandn %%mm4, %%mm7          \n\t"
            "pandn %%mm1, %%mm0          \n\t"
            "paddw %%mm5, %%mm7          \n\t"
            "paddw %%mm2, %%mm0          \n\t"
            //  test  ((pa <= pb)? pa:pb) <= pc
            "pcmpgtw %%mm6, %%mm7        \n\t" // pab > pc?
            "pxor %%mm1, %%mm1           \n\t"
            "pand %%mm7, %%mm3           \n\t"
            "pandn %%mm0, %%mm7          \n\t"
            "pxor %%mm1, %%mm1           \n\t"
            "paddw %%mm3, %%mm7          \n\t"
            "pxor %%mm0, %%mm0           \n\t"
            // step ecx to next set of 8 bytes and repeat loop til done
            "addl $8, %%ecx              \n\t"
            "packuswb %%mm7, %%mm1       \n\t"
            "paddb -8(%1," PCX ",), %%mm1 \n\t" // add Paeth predictor + Raw(x)
            "cmpl %%eax, %%ecx           \n\t" // MMXLength
            "movq %%mm1, -8(%1," PCX ",) \n\t" // write back updated value
                                 // mm1 will be used as Raw(x-bpp) next loop
            "jb paeth_8lp                \n\t"

            : "=S" (dummy_value_S),            // output regs (dummy)
              "=D" (dummy_value_D),
              "=c" (dummy_value_c),
              "=a" (dummy_value_a)

            : "0" (prev_row),  // esi/rsi      // input regs
              "1" (row),       // edi/rdi
              "2" (diff),      // ecx
              "3" (MMXLength)  // eax

#if defined(CLOBBER_MMX_REGS_SUPPORTED)
            : "%mm0", "%mm1", "%mm2", "%mm3"   // clobber list
            , "%mm4", "%mm5", "%mm6", "%mm7"
#endif
         );
      }
      break;  // end 8 bpp

      default:                // bpp != 1,2,3,4,6,8:  doesn't exist
      {
         // ERROR:  SHOULD NEVER BE REACHED
#if defined(PNG_DEBUG)
         png_debug(1, "Internal libpng logic error (GCC "
           "png_read_filter_row_mmx_paeth())\n");
#endif
      }
      break;

   } // end switch (bpp)

   __asm__ __volatile__ (
      // MMX acceleration complete; now do clean-up
      // check if any remaining bytes left to decode
//pre "movl FullLength, %%edx      \n\t"
//pre "movl MMXLength, %%eax       \n\t"
      "cmpl %%edx, %%eax           \n\t"
      "jnb paeth_end               \n\t"

      SAVE_ebp

//pre "movl row, %2                \n\t" // edi/rdi
//pre "movl prev_row, %1           \n\t" // esi/rsi
      // do Paeth decode for remaining bytes
      "movl %%eax, %%ebp           \n\t"
//pre "subl bpp, %%ebp             \n\t" // (bpp is preloaded into ecx)
      "subl %%ecx, %%ebp           \n\t" // ebp = eax - bpp
      "xorl %%ecx, %%ecx           \n\t" // zero ecx before using cl & cx below

      SAVE_GOT_ebx
      SAVE_r11_r12_r13

   "paeth_lp2:                     \n\t"
      "xorl %%ebx, %%ebx           \n\t"
      // pav = p - a = (a + b - c) - a = b - c
      "movb (%1," PAX ",), %%bl    \n\t" // load Prior(x) into bl
      "movb (%1," PBP ",), %%cl    \n\t" // load Prior(x-bpp) into cl
      "subl %%ecx, %%ebx           \n\t" // subtract Prior(x-bpp)
      "movl %%ebx, " pa_TEMP "     \n\t" // Save pav for later use
      "xorl %%ebx, %%ebx           \n\t"
      // pbv = p - b = (a + b - c) - b = a - c
      "movb (%2," PBP ",), %%bl    \n\t" // load Raw(x-bpp) into bl
      "subl %%ecx, %%ebx           \n\t" // subtract Prior(x-bpp)
      "movl %%ebx, %%ecx           \n\t"
      // pcv = p - c = (a + b - c) - c = (a - c) + (b - c) = pav + pbv
      "addl " pa_TEMP ", %%ebx     \n\t" // pcv = pav + pbv
      // pc = abs(pcv)
      "testl $0x80000000, %%ebx    \n\t"
      "jz paeth_pca2               \n\t"
      "negl %%ebx                  \n\t" // reverse sign of neg values

   "paeth_pca2:                    \n\t"
      "movl %%ebx, " pc_TEMP "     \n\t" // save pc for later use
      // pb = abs(pbv)
      "testl $0x80000000, %%ecx    \n\t"
      "jz paeth_pba2               \n\t"
      "negl %%ecx                  \n\t" // reverse sign of neg values

   "paeth_pba2:                    \n\t"
      "movl %%ecx, " pb_TEMP "     \n\t" // save pb for later use
      // pa = abs(pav)
      "movl " pa_TEMP ", %%ebx     \n\t"
      "testl $0x80000000, %%ebx    \n\t"
      "jz paeth_paa2               \n\t"
      "negl %%ebx                  \n\t" // reverse sign of neg values

   "paeth_paa2:                    \n\t"
      "movl %%ebx, " pa_TEMP "     \n\t" // save pa for later use
      // test if pa <= pb
      "cmpl %%ecx, %%ebx           \n\t"
      "jna paeth_abb2              \n\t"
      // pa > pb; now test if pb <= pc
      "cmpl " pc_TEMP ", %%ecx     \n\t"
      "jna paeth_bbc2              \n\t"
      // pb > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
      "movb (%1," PBP ",), %%cl    \n\t" // load Prior(x-bpp) into cl
      "jmp paeth_paeth2            \n\t"

   "paeth_bbc2:                    \n\t"
      // pb <= pc; Raw(x) = Paeth(x) + Prior(x)
      "movb (%1," PAX ",), %%cl    \n\t" // load Prior(x) into cl
      "jmp paeth_paeth2            \n\t"

   "paeth_abb2:                    \n\t"
      // pa <= pb; now test if pa <= pc
      "cmpl " pc_TEMP ", %%ebx     \n\t"
      "jna paeth_abc2              \n\t"
      // pa > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
      "movb (%1," PBP ",), %%cl    \n\t" // load Prior(x-bpp) into cl
      "jmp paeth_paeth2            \n\t"

   "paeth_abc2:                    \n\t"
      // pa <= pc; Raw(x) = Paeth(x) + Raw(x-bpp)
      "movb (%2," PBP ",), %%cl    \n\t" // load Raw(x-bpp) into cl

   "paeth_paeth2:                  \n\t"
      "incl %%eax                  \n\t"
      "incl %%ebp                  \n\t"
      // Raw(x) = (Paeth(x) + Paeth_Predictor( a, b, c )) mod 256
      "addb %%cl, -1(%2," PAX ",)  \n\t"
      "cmpl %%edx, %%eax           \n\t" // check against FullLength
      "jb paeth_lp2                \n\t"

      RESTORE_r11_r12_r13
      RESTORE_GOT_ebx
      RESTORE_ebp

   "paeth_end:                     \n\t"
      "EMMS                        \n\t" // end MMX; prep for poss. FP instrs.

      : "=c" (dummy_value_c),            // output regs (dummy)
        "=S" (dummy_value_S),
        "=D" (dummy_value_D),
        "=a" (dummy_value_a),
        "=d" (dummy_value_d)

      : "0" (bpp),         // ecx        // input regs
        "1" (prev_row),    // esi/rsi
        "2" (row),         // edi/rdi
        "3" (MMXLength),   // eax
        "4" (FullLength)   // edx

      CLOB_COLON_ebx_ebp_r1X             // clobber list
        CLOBBER_GOT_ebx
        CLOB_COMMA_ebx_ebp
        CLOBBER_ebp
        CLOB_COMMA_ebX_r1X
        CLOBBER_r11_r12_r13
   );

} /* end png_read_filter_row_mmx_paeth() */

#endif // PNG_x86_64_USE_GOTPCREL || PNG_THREAD_UNSAFE_OK
#endif /* PNG_MMX_READ_FILTER_PAETH_SUPPORTED */




#if defined(PNG_MMX_READ_FILTER_SUB_SUPPORTED)

//===========================================================================//
//                                                                           //
//           P N G _ R E A D _ F I L T E R _ R O W _ M M X _ S U B           //
//                                                                           //
//===========================================================================//

// Optimized code for PNG Sub filter decoder

static void /* PRIVATE */
png_read_filter_row_mmx_sub(png_row_infop row_info, png_bytep row)
{
   unsigned FullLength, MMXLength;  // png_uint_32 is actually 64-bit on x86-64
   int bpp;
   int dummy_value_a;
   int dummy_value_c;
   int dummy_value_d;
   png_bytep dummy_value_D;
   int diff; //     __attribute__((used));

   bpp = (row_info->pixel_depth + 7) >> 3;  // calc number of bytes per pixel
   FullLength = row_info->rowbytes - bpp;   // number of bytes to filter
     // (why do we subtract off bpp?  not so in avg or paeth...)

   __asm__ __volatile__ (
      SAVE_r15
      SAVE_ebp
//pre "movl row, %1                \n\t" // edi/rdi
      "mov  %1, " PSI "            \n\t" // lp = row
//pre "movl bpp, %%ecx             \n\t"
      "add  " PCX ", %1            \n\t" // rp = row + bpp
//pre "movl FullLength, %%eax      \n\t" // bring in via eax...
      SAVE_FullLength                    // ...but store for later use

      "xorl %%eax, %%eax           \n\t"

      // get # of bytes to alignment (note:  computing _delta_ of two pointers,
      // so hereafter %%ebp is sufficient even on 64-bit)
      "mov  %1, " PBP "            \n\t" // take start of row
      "add  $0xf, " PBP "          \n\t" // add 7+8 to incr past alignment bdry
//    "andl $0xfffffff8, %%ebp     \n\t" // mask to alignment boundary (32-bit!)
      CLEAR_BOTTOM_3_BITS  PBP    "\n\t" // mask to alignment boundary
      "sub  %1, " PBP "            \n\t" // subtract row ptr again => ebp =
      "jz sub_go                   \n\t" //  target value of eax at alignment

   "sub_lp1:                       \n\t" // fix alignment
      "movb (" PSI "," PAX ",), %%cl \n\t"
      "addb %%cl, (%1," PAX ",)    \n\t"
      "incl %%eax                  \n\t"
      "cmpl %%ebp, %%eax           \n\t"
      "jb sub_lp1                  \n\t"

   "sub_go:                        \n\t"
      RESTORE_FullLength "%%ecx    \n\t" // FullLength -> ecx
      "movl %%ecx, %%edx           \n\t"
      "subl %%eax, %%edx           \n\t" // subtract alignment fix
      "andl $0x00000007, %%edx     \n\t" // calc bytes over mult of 8
      "subl %%edx, %%ecx           \n\t" // drop over bytes from length
//out "movl %%ecx, MMXLength       \n\t"
      "movl %%ebp, %%eax           \n\t" // ebp = diff, but no reg constraint(?)
      RESTORE_ebp                        //  (could swap ebp and ecx functions,
      RESTORE_r15                        //  but %%cl issues...)

      : "=c" (MMXLength),       // 0     // output regs
        "=D" (dummy_value_D),   // 1
        "=a" (diff)             // 2

      : "0" (bpp),              // ecx   // input regs
        "1" (row),              // edi
        "2" (FullLength)        // eax

      : "%esi", "%edx"                   // clobber list
        _CLOBBER_r15
        _CLOBBER_ebp
   );

   // now do the math for the rest of the row
   switch (bpp)
   {
      case 3:
      {
//       _ShiftBpp = 24;       // == 3 * 8
//       _ShiftRem  = 40;      // == 64 - 24

         __asm__ __volatile__ (
// preload  "mov  row, %1                 \n\t" // edi/rdi
            LOAD_GOT_rbp
            // load (former) _ActiveMask for 2nd active byte group
            "movq " AMASK2_3_3 ", %%mm7   \n\t" // _amask2_3_3
            RESTORE_rbp

// notused  "mov  %1, " PSI "             \n\t" // lp = row
// preload  "movl bpp, %%ecx              \n\t"
            "add  " PCX ", %1             \n\t" // rp = row + bpp
            "movq %%mm7, %%mm6            \n\t"
// preload  "movl diff, %%edx             \n\t"
            "psllq $24, %%mm6             \n\t" // move mask in mm6 to cover
                                                //  3rd active byte group
            // prime the pump:  load the first Raw(x-bpp) data set
            "movq -8(%1," PDX ",), %%mm1  \n\t"

         "sub_3lp:                        \n\t" // shift data for adding first
            "psrlq $40, %%mm1             \n\t" //  bpp bytes (no need for mask;
                                                //  shift clears inactive bytes)
            // add 1st active group
            "movq (%1," PDX ",), %%mm0    \n\t"
            "paddb %%mm1, %%mm0           \n\t"

            // add 2nd active group
            "movq %%mm0, %%mm1            \n\t" // mov updated Raws to mm1
            "psllq $24, %%mm1             \n\t" // shift data to pos. correctly
            "pand %%mm7, %%mm1            \n\t" // mask to use 2nd active group
            "paddb %%mm1, %%mm0           \n\t"

            // add 3rd active group
            "movq %%mm0, %%mm1            \n\t" // mov updated Raws to mm1
            "psllq $24, %%mm1             \n\t" // shift data to pos. correctly
            "pand %%mm6, %%mm1            \n\t" // mask to use 3rd active group
            "addl $8, %%edx               \n\t"
            "paddb %%mm1, %%mm0           \n\t"

            "cmpl %%eax, %%edx            \n\t" // MMXLength
            "movq %%mm0, -8(%1," PDX ",)  \n\t" // write updated Raws to array
            "movq %%mm0, %%mm1            \n\t" // prep 1st add at top of loop
            "jb sub_3lp                   \n\t"

            : "=c" (dummy_value_c),   // 0      // output regs (dummy)
              "=D" (dummy_value_D),   // 1
              "=d" (dummy_value_d),   // 2
              "=a" (dummy_value_a)    // 3

            : "0" (bpp),              // ecx    // input regs
              "1" (row),              // edi
              "2" (diff),             // edx
              "3" (MMXLength)         // eax

#if defined(CLOBBER_MMX_REGS_SUPPORTED)
            : "%mm0", "%mm1", "%mm6", "%mm7"    // clobber list
#endif
         );
      }
      break;  // end 3 bpp

      case 4:   // formerly shared with 6 bpp case via _ShiftBpp and _ShiftRem,
      {         // but 64-bit PIC/.so problems (could still share, moving vars
                // into unused MMX regs via ecx/edx, but kludgy)
//       _ShiftBpp = bpp << 3;        // 32 (psllq)
//       _ShiftRem = 64 - _ShiftBpp;  // 32 (psrlq)

         __asm__ __volatile__ (
// preload  "mov  row, %1                 \n\t" // edi/rdi
// preload  "movl diff, %%edx             \n\t"
// notused  "mov  %1, " PSI "             \n\t" // lp = row
// preload  "movl bpp, %%ecx              \n\t"
            "add  " PCX ", %1             \n\t" // rp = row + bpp

            // prime the pump:  load the first Raw(x-bpp) data set
            "movq -8(%1," PDX ",), %%mm1  \n\t"

         "sub_4lp:                        \n\t" // shift data for adding first
            "psrlq $32, %%mm1             \n\t" //  bpp bytes (no need for mask;
                                                //  shift clears inactive bytes)
            "movq (%1," PDX ",), %%mm0    \n\t"
            "paddb %%mm1, %%mm0           \n\t"

            // add 2nd active group
            "movq %%mm0, %%mm1            \n\t" // mov updated Raws to mm1
            "psllq $32, %%mm1             \n\t" // shift data to pos. correctly
            "addl $8, %%edx               \n\t"
            "paddb %%mm1, %%mm0           \n\t"

            "cmpl %%eax, %%edx            \n\t" // MMXLength
            "movq %%mm0, -8(%1," PDX ",)  \n\t" // write updated Raws to array
            "movq %%mm0, %%mm1            \n\t" // prep 1st add at top of loop
            "jb sub_4lp                   \n\t"

            : "=c" (dummy_value_c),   // 0      // output regs (dummy)
              "=D" (dummy_value_D),   // 1
              "=d" (dummy_value_d),   // 2
              "=a" (dummy_value_a)    // 3

            : "0" (bpp),              // ecx    // input regs
              "1" (row),              // edi
              "2" (diff),             // edx
              "3" (MMXLength)         // eax

#if defined(CLOBBER_MMX_REGS_SUPPORTED)
            : "%mm0", "%mm1"                    // clobber list
#endif
         );
      }
      break;  // end 4 bpp

      case 1:
      {
         __asm__ __volatile__ (
// preload  "movl diff, %%edx              \n\t"
// preload  "mov  row, %1                  \n\t" // edi/rdi
// preload  "cmpl FullLength, %%edx        \n\t"
            "cmpl %%eax, %%edx             \n\t"
            "jnb sub_1end                  \n\t"
            "mov  %1, " PSI "              \n\t" // lp = row
// irrel.   "xorl %%ecx, %%ecx             \n\t" // (actually bug with preload)
// preload  "movl bpp, %%ecx               \n\t"
            "add  " PCX ", %1              \n\t" // rp = row + bpp

         "sub_1lp:                         \n\t"
            "movb (" PSI "," PDX ",), %%cl \n\t"
            "addb %%cl, (%1," PDX ",)      \n\t"
            "incl %%edx                    \n\t"
            "cmpl %%eax, %%edx             \n\t" // compare with FullLength
            "jb sub_1lp                    \n\t"

         "sub_1end:                        \n\t"

            : "=c" (dummy_value_c),   // 0      // output regs (dummy)
              "=D" (dummy_value_D),   // 1
              "=d" (dummy_value_d),   // 2
              "=a" (dummy_value_a)    // 3

            : "0" (bpp),              // ecx    // input regs
              "1" (row),              // edi
              "2" (diff),             // edx
              "3" (FullLength)        // eax

            : "%esi"                            // clobber list
         );
      }
      return;  // end 1 bpp (bypassing cleanup block!)

      case 2:
      {
//       _ShiftBpp = 16;       // == 2 * 8
//       _ShiftRem = 48;       // == 64 - 16

         __asm__ __volatile__ (
            LOAD_GOT_rbp
            // load (former) _ActiveMask for 2nd active byte group
            "movq " AMASK4_2_2 ", %%mm7   \n\t" // _amask4_2_2
            RESTORE_rbp
// preload  "movl diff, %%edx             \n\t"
            "movq %%mm7, %%mm6            \n\t"
// preload  "mov  row, %1                 \n\t" // edi/rdi
            "psllq $16, %%mm6             \n\t" // move mask in mm6 to cover
                                                //  3rd active byte group
// notused  "mov  %1, " PSI "             \n\t" // lp = row
            "movq %%mm6, %%mm5            \n\t"
// preload  "movl bpp, %%ecx              \n\t"
            "add  " PCX ", %1             \n\t" // rp = row + bpp
            "psllq $16, %%mm5             \n\t" // move mask in mm5 to cover
                                                //  4th active byte group
            // prime the pump:  load the first Raw(x-bpp) data set
            "movq -8(%1," PDX ",), %%mm1  \n\t"

         "sub_2lp:                        \n\t" // shift data for adding first
            "psrlq $48, %%mm1             \n\t" //  bpp bytes (no need for mask;
                                                //  shift clears inactive bytes)
            // add 1st active group
            "movq (%1," PDX ",), %%mm0    \n\t"
            "paddb %%mm1, %%mm0           \n\t"

            // add 2nd active group
            "movq %%mm0, %%mm1            \n\t" // mov updated Raws to mm1
            "psllq $16, %%mm1             \n\t" // shift data to pos. correctly
            "pand %%mm7, %%mm1            \n\t" // mask to use 2nd active group
            "paddb %%mm1, %%mm0           \n\t"

            // add 3rd active group
            "movq %%mm0, %%mm1            \n\t" // mov updated Raws to mm1
            "psllq $16, %%mm1             \n\t" // shift data to pos. correctly
            "pand %%mm6, %%mm1            \n\t" // mask to use 3rd active group
            "paddb %%mm1, %%mm0           \n\t"

            // add 4th active group
            "movq %%mm0, %%mm1            \n\t" // mov updated Raws to mm1
            "psllq $16, %%mm1             \n\t" // shift data to pos. correctly
            "pand %%mm5, %%mm1            \n\t" // mask to use 4th active group
            "addl $8, %%edx               \n\t"
            "paddb %%mm1, %%mm0           \n\t"
            "cmpl %%eax, %%edx            \n\t" // MMXLength
            "movq %%mm0, -8(%1," PDX ",)  \n\t" // write updated Raws to array
            "movq %%mm0, %%mm1            \n\t" // prep 1st add at top of loop
            "jb sub_2lp                   \n\t"

            : "=c" (dummy_value_c),   // 0      // output regs (dummy)
              "=D" (dummy_value_D),   // 1
              "=d" (dummy_value_d),   // 2
              "=a" (dummy_value_a)    // 3

            : "0" (bpp),              // ecx    // input regs
              "1" (row),              // edi
              "2" (diff),             // edx
              "3" (MMXLength)         // eax

#if defined(CLOBBER_MMX_REGS_SUPPORTED)
            : "%mm0", "%mm1", "%mm5", "%mm6"    // clobber list
            , "%mm7"
#endif
         );
      }
      break;  // end 2 bpp

      case 6:   // formerly shared with 4 bpp case (see comments there)
      {
//       _ShiftBpp = bpp << 3;        // 48 (psllq)
//       _ShiftRem = 64 - _ShiftBpp;  // 16 (psrlq)

         __asm__ __volatile__ (
// preload  "mov  row, %1                 \n\t" // edi/rdi
// preload  "movl diff, %%edx             \n\t"
// notused  "mov  %1, " PSI "             \n\t" // lp = row
// preload  "movl bpp, %%ecx              \n\t"
            "add  " PCX ", %1             \n\t" // rp = row + bpp

            // prime the pump:  load the first Raw(x-bpp) data set
            "movq -8(%1," PDX ",), %%mm1  \n\t"

         "sub_6lp:                        \n\t" // shift data for adding first
            "psrlq $16, %%mm1             \n\t" //  bpp bytes (no need for mask;
                                                //  shift clears inactive bytes)
            "movq (%1," PDX ",), %%mm0    \n\t"
            "paddb %%mm1, %%mm0           \n\t"

            // add 2nd active group
            "movq %%mm0, %%mm1            \n\t" // mov updated Raws to mm1
            "psllq $48, %%mm1             \n\t" // shift data to pos. correctly
            "addl $8, %%edx               \n\t"
            "paddb %%mm1, %%mm0           \n\t"

            "cmpl %%eax, %%edx            \n\t" // MMXLength
            "movq %%mm0, -8(%1," PDX ",)  \n\t" // write updated Raws to array
            "movq %%mm0, %%mm1            \n\t" // prep 1st add at top of loop
            "jb sub_6lp                   \n\t"

            : "=c" (dummy_value_c),   // 0      // output regs (dummy)
              "=D" (dummy_value_D),   // 1
              "=d" (dummy_value_d),   // 2
              "=a" (dummy_value_a)    // 3

            : "0" (bpp),              // ecx    // input regs
              "1" (row),              // edi
              "2" (diff),             // edx
              "3" (MMXLength)         // eax

#if defined(CLOBBER_MMX_REGS_SUPPORTED)
            : "%mm0", "%mm1"                    // clobber list
#endif
         );
      }
      break;  // end 6 bpp

      case 8:
      {
         __asm__ __volatile__ (
// preload  "mov  row, %1                 \n\t" // edi/rdi
// preload  "movl diff, %%edx             \n\t"
// notused  "mov  %1, " PSI "             \n\t" // lp = row
// preload  "movl bpp, %%ecx              \n\t"
            "add  " PCX ", %1             \n\t" // rp = row + bpp
// preload  "movl MMXLength, %%eax        \n\t"

            // prime the pump:  load the first Raw(x-bpp) data set
            "movq -8(%1," PDX ",), %%mm7  \n\t"
            "movl %%eax, %%esi            \n\t" // copy of MMXLength -> esi
            "andl $0x0000003f, %%esi      \n\t" // calc bytes over mult of 64

         "sub_8lp:                        \n\t"
            "movq (%1," PDX ",), %%mm0    \n\t" // load Sub(x) for 1st 8 bytes
            "paddb %%mm7, %%mm0           \n\t"
            "movq 8(%1," PDX ",), %%mm1   \n\t" // load Sub(x) for 2nd 8 bytes
            "movq %%mm0, (%1," PDX ",)    \n\t" // write Raw(x) for 1st 8 bytes

            // Now mm0 will be used as Raw(x-bpp) for the 2nd group of 8 bytes.
            // This will be repeated for each group of 8 bytes with the 8th
            // group being used as the Raw(x-bpp) for the 1st group of the
            // next loop.

            "paddb %%mm0, %%mm1           \n\t"
            "movq 16(%1," PDX ",), %%mm2  \n\t" // load Sub(x) for 3rd 8 bytes
            "movq %%mm1, 8(%1," PDX ",)   \n\t" // write Raw(x) for 2nd 8 bytes
            "paddb %%mm1, %%mm2           \n\t"
            "movq 24(%1," PDX ",), %%mm3  \n\t" // load Sub(x) for 4th 8 bytes
            "movq %%mm2, 16(%1," PDX ",)  \n\t" // write Raw(x) for 3rd 8 bytes
            "paddb %%mm2, %%mm3           \n\t"
            "movq 32(%1," PDX ",), %%mm4  \n\t" // load Sub(x) for 5th 8 bytes
            "movq %%mm3, 24(%1," PDX ",)  \n\t" // write Raw(x) for 4th 8 bytes
            "paddb %%mm3, %%mm4           \n\t"
            "movq 40(%1," PDX ",), %%mm5  \n\t" // load Sub(x) for 6th 8 bytes
            "movq %%mm4, 32(%1," PDX ",)  \n\t" // write Raw(x) for 5th 8 bytes
            "paddb %%mm4, %%mm5           \n\t"
            "movq 48(%1," PDX ",), %%mm6  \n\t" // load Sub(x) for 7th 8 bytes
            "movq %%mm5, 40(%1," PDX ",)  \n\t" // write Raw(x) for 6th 8 bytes
            "paddb %%mm5, %%mm6           \n\t"
            "movq 56(%1," PDX ",), %%mm7  \n\t" // load Sub(x) for 8th 8 bytes
            "movq %%mm6, 48(%1," PDX ",)  \n\t" // write Raw(x) for 7th 8 bytes
            "addl $64, %%edx              \n\t"
            "paddb %%mm6, %%mm7           \n\t"
            "cmpl %%esi, %%edx            \n\t" // cmp to bytes over mult of 64
            "movq %%mm7, -8(%1," PDX ",)  \n\t" // write Raw(x) for 8th 8 bytes
            "jb sub_8lp                   \n\t"

            "cmpl %%eax, %%edx            \n\t" // compare to MMXLength
            "jnb sub_8lt8                 \n\t"

         "sub_8lpA:                       \n\t"
            "movq (%1," PDX ",), %%mm0    \n\t"
            "addl $8, %%edx               \n\t"
            "paddb %%mm7, %%mm0           \n\t"
            "cmpl %%eax, %%edx            \n\t" // compare to MMXLength
            "movq %%mm0, -8(%1," PDX ",)  \n\t" // -8 to offset early addl edx
            "movq %%mm0, %%mm7            \n\t" // move calculated Raw(x) data
            "jb sub_8lpA                  \n\t" //  to mm7 to be new Raw(x-bpp)
                                                //  for next loop
         "sub_8lt8:                       \n\t"

            : "=c" (dummy_value_c),   // 0      // output regs (dummy)
              "=D" (dummy_value_D),   // 1
              "=d" (dummy_value_d),   // 2
              "=a" (dummy_value_a)    // 3

            : "0" (bpp),              // ecx    // input regs
              "1" (row),              // edi
              "2" (diff),             // edx
              "3" (MMXLength)         // eax

            : "%esi"                            // clobber list
#if defined(CLOBBER_MMX_REGS_SUPPORTED)
            , "%mm0", "%mm1", "%mm2", "%mm3"
            , "%mm4", "%mm5", "%mm6", "%mm7"
#endif
         );
      }
      break;  // end 8 bpp

      default:                // bpp != 1,2,3,4,6,8:  doesn't exist
      {
         // ERROR:  SHOULD NEVER BE REACHED
#if defined(PNG_DEBUG)
         png_debug(1, "Internal libpng logic error (GCC "
           "png_read_filter_row_mmx_sub())\n");
#endif
      }
      break;

   } // end switch (bpp)

   __asm__ __volatile__ (
//pre "movl MMXLength, %%eax         \n\t"
//pre "mov  row, %1                  \n\t" // edi/rdi
//pre "cmpl FullLength, %%eax        \n\t"
      "cmpl %%edx, %%eax             \n\t"
      "jnb sub_end                   \n\t"

      "mov  %1, " PSI "              \n\t" // lp = row
//pre "movl bpp, %%ecx               \n\t"
      "add  " PCX ", %1              \n\t" // rp = row + bpp
      "xorl %%ecx, %%ecx             \n\t"

   "sub_lp2:                         \n\t"
      "movb (" PSI "," PAX ",), %%cl \n\t"
      "addb %%cl, (%1," PAX ",)      \n\t"
      "incl %%eax                    \n\t"
      "cmpl %%edx, %%eax             \n\t" // FullLength
      "jb sub_lp2                    \n\t"

   "sub_end:                         \n\t"
      "EMMS                          \n\t" // end MMX instructions

      : "=c" (dummy_value_c),   // 0      // output regs (dummy)
        "=D" (dummy_value_D),   // 1
        "=a" (dummy_value_a),   // 2
        "=d" (dummy_value_d)    // 3

      : "0" (bpp),              // ecx    // input regs
        "1" (row),              // edi
        "2" (MMXLength),        // eax
        "3" (FullLength)        // edx

      : "%esi"                            // clobber list
   );

} // end of png_read_filter_row_mmx_sub()

#endif /* PNG_MMX_READ_FILTER_SUB_SUPPORTED */




#if defined(PNG_MMX_READ_FILTER_UP_SUPPORTED)

//===========================================================================//
//                                                                           //
//            P N G _ R E A D _ F I L T E R _ R O W _ M M X _ U P            //
//                                                                           //
//===========================================================================//

// Optimized code for PNG Up filter decoder

static void /* PRIVATE */
png_read_filter_row_mmx_up(png_row_infop row_info, png_bytep row,
                           png_bytep prev_row)
{
   unsigned len;        // png_uint_32 is actually 64-bit on x86-64
   int dummy_value_d;   // fix 'forbidden register 3 (dx) was spilled' error
   png_bytep dummy_value_S;
   png_bytep dummy_value_D;

   len = row_info->rowbytes;              // number of bytes to filter

   __asm__ __volatile__ (
      SAVE_GOT_ebx
//pre "mov  prev_row, %1           \n\t" // esi/rsi
//pre "movl row, %2                \n\t" // edi/rdi

      "xorl %%ebx, %%ebx           \n\t"
      "xorl %%eax, %%eax           \n\t"

      // get # of bytes to alignment (note:  computing _delta_ of two pointers,
      // so hereafter %%ecx is sufficient even on 64-bit)
      "mov  %2, " PCX "            \n\t" // take start of row
      "add  $0x7, " PCX "          \n\t" // add 7 to incr past alignment bdry
//    "andl $0xfffffff8, %%ecx     \n\t" // mask to alignment boundary (32-bit!)
      CLEAR_BOTTOM_3_BITS  PCX    "\n\t" // mask to alignment boundary
      "sub  %2, " PCX "            \n\t" // subtract row ptr again => ebp =
      "jz up_go                    \n\t" //  target value of ecx at alignment

   "up_lp1:                        \n\t" // fix alignment
      "movb (%2," PBX ",), %%al    \n\t"
      "addb (%1," PBX ",), %%al    \n\t"
      "incl %%ebx                  \n\t"
      "cmpl %%ecx, %%ebx           \n\t"
      "movb %%al, -1(%2," PBX ",)  \n\t" // mov does not affect flags; -1 to
      "jb up_lp1                   \n\t" //  offset incl ebx

   "up_go:                         \n\t"
//pre "movl len, %%edx             \n\t"
      "movl %%edx, %%ecx           \n\t"
      "subl %%ebx, %%edx           \n\t" // subtract alignment fix
      "andl $0x0000003f, %%edx     \n\t" // calc bytes over mult of 64
      "subl %%edx, %%ecx           \n\t" // sub over-bytes from original length

      // unrolled loop - use all MMX registers and interleave to reduce
      // number of branch instructions (loops) and reduce partial stalls
   "up_loop:                       \n\t"
      "movq (%1," PBX ",), %%mm1   \n\t"
      "movq (%2," PBX ",), %%mm0   \n\t"
      "movq 8(%1," PBX ",), %%mm3  \n\t"
      "paddb %%mm1, %%mm0          \n\t"
      "movq 8(%2," PBX ",), %%mm2  \n\t"
      "movq %%mm0, (%2," PBX ",)   \n\t"
      "paddb %%mm3, %%mm2          \n\t"
      "movq 16(%1," PBX ",), %%mm5 \n\t"
      "movq %%mm2, 8(%2," PBX ",)  \n\t"
      "movq 16(%2," PBX ",), %%mm4 \n\t"
      "movq 24(%1," PBX ",), %%mm7 \n\t"
      "paddb %%mm5, %%mm4          \n\t"
      "movq 24(%2," PBX ",), %%mm6 \n\t"
      "movq %%mm4, 16(%2," PBX ",) \n\t"
      "paddb %%mm7, %%mm6          \n\t"
      "movq 32(%1," PBX ",), %%mm1 \n\t"
      "movq %%mm6, 24(%2," PBX ",) \n\t"
      "movq 32(%2," PBX ",), %%mm0 \n\t"
      "movq 40(%1," PBX ",), %%mm3 \n\t"
      "paddb %%mm1, %%mm0          \n\t"
      "movq 40(%2," PBX ",), %%mm2 \n\t"
      "movq %%mm0, 32(%2," PBX ",) \n\t"
      "paddb %%mm3, %%mm2          \n\t"
      "movq 48(%1," PBX ",), %%mm5 \n\t"
      "movq %%mm2, 40(%2," PBX ",) \n\t"
      "movq 48(%2," PBX ",), %%mm4 \n\t"
      "movq 56(%1," PBX ",), %%mm7 \n\t"
      "paddb %%mm5, %%mm4          \n\t"
      "movq 56(%2," PBX ",), %%mm6 \n\t"
      "movq %%mm4, 48(%2," PBX ",) \n\t"
      "addl $64, %%ebx             \n\t"
      "paddb %%mm7, %%mm6          \n\t"
      "cmpl %%ecx, %%ebx           \n\t"
      "movq %%mm6, -8(%2," PBX ",) \n\t" // (+56)movq does not affect flags;
      "jb up_loop                  \n\t" //  -8 to offset addl ebx

      "cmpl $0, %%edx              \n\t" // test for bytes over mult of 64
      "jz up_end                   \n\t"

      "cmpl $8, %%edx              \n\t" // test for less than 8 bytes
      "jb up_lt8                   \n\t" //  [added by lcreeve at netins.net]

      "addl %%edx, %%ecx           \n\t"
      "andl $0x00000007, %%edx     \n\t" // calc bytes over mult of 8
      "subl %%edx, %%ecx           \n\t" // drop over-bytes from length
      "jz up_lt8                   \n\t"

   "up_lpA:                        \n\t" // use MMX regs to update 8 bytes sim.
      "movq (%1," PBX ",), %%mm1   \n\t"
      "movq (%2," PBX ",), %%mm0   \n\t"
      "addl $8, %%ebx              \n\t"
      "paddb %%mm1, %%mm0          \n\t"
      "cmpl %%ecx, %%ebx           \n\t"
      "movq %%mm0, -8(%2," PBX ",) \n\t" // movq does not affect flags; -8 to
      "jb up_lpA                   \n\t" //  offset add ebx
      "cmpl $0, %%edx              \n\t" // test for bytes over mult of 8
      "jz up_end                   \n\t"

   "up_lt8:                        \n\t"
      "xorl %%eax, %%eax           \n\t"
      "addl %%edx, %%ecx           \n\t" // move over byte count into counter

   "up_lp2:                        \n\t" // use x86 regs for remaining bytes
      "movb (%2," PBX ",), %%al    \n\t"
      "addb (%1," PBX ",), %%al    \n\t"
      "incl %%ebx                  \n\t"
      "cmpl %%ecx, %%ebx           \n\t"
      "movb %%al, -1(%2," PBX ",)  \n\t" // mov does not affect flags; -1 to
      "jb up_lp2                   \n\t" //  offset inc ebx

   "up_end:                        \n\t"
      "EMMS                        \n\t" // conversion of filtered row complete
      RESTORE_GOT_ebx

      : "=d" (dummy_value_d),   // 0     // output regs (dummy)
        "=S" (dummy_value_S),   // 1
        "=D" (dummy_value_D)    // 2

      : "0" (len),              // edx   // input regs
        "1" (prev_row),         // esi
        "2" (row)               // edi

      : "%eax", "%ecx"                   // clobber list (no input regs!)
        _CLOBBER_GOT_ebx
#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
      , "%mm0", "%mm1", "%mm2", "%mm3"
      , "%mm4", "%mm5", "%mm6", "%mm7"
#endif
   );

} // end of png_read_filter_row_mmx_up()

#endif /* PNG_MMX_READ_FILTER_UP_SUPPORTED */




/*===========================================================================*/
/*                                                                           */
/*                   P N G _ R E A D _ F I L T E R _ R O W                   */
/*                                                                           */
/*===========================================================================*/

/* Optimized png_read_filter_row routines */

void /* PRIVATE */
png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
   row, png_bytep prev_row, int filter)
{
#if defined(PNG_DEBUG)
   char filtname[10];
#endif

   if (_mmx_supported == 2) {
#if !defined(PNG_1_0_X)
       /* this should have happened in png_init_mmx_flags() already */
       png_warning(png_ptr, "asm_flags may not have been initialized");
#endif
       png_mmx_support();
   }

#if defined(PNG_DEBUG)
   png_debug(1, "in png_read_filter_row (pnggccrd.c)\n");
   switch (filter)
   {
      case 0:
         png_snprintf(filtname, 10, "none");
         break;

      case 1:
         png_snprintf(filtname, 10, "sub-%s",
#ifdef PNG_MMX_READ_FILTER_SUB_SUPPORTED
#if !defined(PNG_1_0_X)
           ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_SUB) &&
            (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
            (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
#else
           _mmx_supported
#endif
           ? "MMX" :
#endif
           "C");
         break;

      case 2:
         png_snprintf(filtname, 10, "up-%s",
#ifdef PNG_MMX_READ_FILTER_UP_SUPPORTED
#if !defined(PNG_1_0_X)
           ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_UP) &&
            (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
            (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
#else
           _mmx_supported
#endif
           ? "MMX" :
#endif
           "C");
         break;

      case 3:
         png_snprintf(filtname, 10, "avg-%s",
#ifdef PNG_MMX_READ_FILTER_AVG_SUPPORTED
#if !defined(PNG_1_0_X)
           ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_AVG) &&
            (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
            (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
#else
           _mmx_supported
#endif
           ? "MMX" :
#endif
           "C");
         break;

      case 4:
         png_snprintf(filtname, 10, "paeth-%s",
#ifdef PNG_MMX_READ_FILTER_PAETH_SUPPORTED
#if defined(PNG_x86_64_USE_GOTPCREL) || defined(PNG_THREAD_UNSAFE_OK)
#if !defined(PNG_1_0_X)
           ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH) &&
            (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
            (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
#else
           _mmx_supported
#endif
           ? "MMX" :
#endif /* PNG_x86_64_USE_GOTPCREL || PNG_THREAD_UNSAFE_OK */
#endif
           "C");
         break;

      default:
         png_snprintf(filtname, 10, "unknown");
         break;
   }
   png_debug2(2, "row_number=%ld, %s, ", png_ptr->row_number, filtname);
   //png_debug1(0, "png_ptr=%10p, ", png_ptr);
   //png_debug1(0, "asm_flags=0x%08lx, ", png_ptr->asm_flags);
   png_debug1(0, "row=%10p, ", row);
   png_debug2(0, "pixdepth=%d, bytes=%d, ", (int)row_info->pixel_depth,
      (int)((row_info->pixel_depth + 7) >> 3));
   png_debug1(0, "rowbytes=%ld\n", row_info->rowbytes);
#endif /* PNG_DEBUG */

   switch (filter)
   {
      case PNG_FILTER_VALUE_NONE:
         break;

      case PNG_FILTER_VALUE_SUB:
#ifdef PNG_MMX_READ_FILTER_SUB_SUPPORTED
#if !defined(PNG_1_0_X)
         if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_SUB) &&
             (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
             (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
#else
         if (_mmx_supported)
#endif
         {
            png_read_filter_row_mmx_sub(row_info, row);
         }
         else
#endif
         {
            png_uint_32 i;
            png_uint_32 istop = row_info->rowbytes;
            png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
            png_bytep rp = row + bpp;
            png_bytep lp = row;

            for (i = bpp; i < istop; i++)
            {
               *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
               rp++;
            }
         }  /* end !UseMMX_sub */
         break;

      case PNG_FILTER_VALUE_UP:
#ifdef PNG_MMX_READ_FILTER_UP_SUPPORTED
#if !defined(PNG_1_0_X)
         if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_UP) &&
             (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
             (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
#else
         if (_mmx_supported)
#endif
         {
            png_read_filter_row_mmx_up(row_info, row, prev_row);
         }
          else
#endif
         {
            png_uint_32 i;
            png_uint_32 istop = row_info->rowbytes;
            png_bytep rp = row;
            png_bytep pp = prev_row;

            for (i = 0; i < istop; ++i)
            {
               *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
               rp++;
            }
         }  /* end !UseMMX_up */
         break;

      case PNG_FILTER_VALUE_AVG:
#ifdef PNG_MMX_READ_FILTER_AVG_SUPPORTED
#if !defined(PNG_1_0_X)
         if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_AVG) &&
             (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
             (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
#else
         if (_mmx_supported)
#endif
         {
            png_read_filter_row_mmx_avg(row_info, row, prev_row);
         }
         else
#endif
         {
            png_uint_32 i;
            png_bytep rp = row;
            png_bytep pp = prev_row;
            png_bytep lp = row;
            png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
            png_uint_32 istop = row_info->rowbytes - bpp;

            for (i = 0; i < bpp; i++)
            {
               *rp = (png_byte)(((int)(*rp) +
                  ((int)(*pp++) >> 1)) & 0xff);
               rp++;
            }

            for (i = 0; i < istop; i++)
            {
               *rp = (png_byte)(((int)(*rp) +
                  ((int)(*pp++ + *lp++) >> 1)) & 0xff);
               rp++;
            }
         }  /* end !UseMMX_avg */
         break;

      case PNG_FILTER_VALUE_PAETH:
#ifdef PNG_MMX_READ_FILTER_PAETH_SUPPORTED
#if defined(PNG_x86_64_USE_GOTPCREL) || defined(PNG_THREAD_UNSAFE_OK)
#if !defined(PNG_1_0_X)
         if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH) &&
             (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
             (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
#else
         if (_mmx_supported)
#endif
         {
            png_read_filter_row_mmx_paeth(row_info, row, prev_row);
         }
         else
#endif /* PNG_x86_64_USE_GOTPCREL || PNG_THREAD_UNSAFE_OK */
#endif
         {
            png_uint_32 i;
            png_bytep rp = row;
            png_bytep pp = prev_row;
            png_bytep lp = row;
            png_bytep cp = prev_row;
            png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
            png_uint_32 istop = row_info->rowbytes - bpp;

            for (i = 0; i < bpp; i++)
            {
               *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
               rp++;
            }

            for (i = 0; i < istop; i++)   /* use leftover rp,pp */
            {
               int a, b, c, pa, pb, pc, p;

               a = *lp++;
               b = *pp++;
               c = *cp++;

               p = b - c;
               pc = a - c;

#if defined(PNG_USE_ABS)
               pa = abs(p);
               pb = abs(pc);
               pc = abs(p + pc);
#else
               pa = p < 0 ? -p : p;
               pb = pc < 0 ? -pc : pc;
               pc = (p + pc) < 0 ? -(p + pc) : p + pc;
#endif

               /*
                  if (pa <= pb && pa <= pc)
                     p = a;
                  else if (pb <= pc)
                     p = b;
                  else
                     p = c;
                */

               p = (pa <= pb && pa <= pc) ? a : (pb <= pc) ? b : c;

               *rp = (png_byte)(((int)(*rp) + p) & 0xff);
               rp++;
            }
         }  /* end !UseMMX_paeth */
         break;

      default:
         png_warning(png_ptr, "Ignoring bad row-filter type");
         *row=0;
         break;
   }
}

#endif /* PNG_HAVE_MMX_READ_FILTER_ROW */


#endif /* PNG_ASSEMBLER_CODE_SUPPORTED && PNG_USE_PNGGCCRD */
#endif /* __GNUC__ */