summaryrefslogtreecommitdiffstats
path: root/main/libdv/libdv-1.0.0-pic.patch
blob: 25cc11dca70d1fa38146e544545a1e645c8e8e07 (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
Patch downloaded from
http://bugs.gentoo.org/show_bug.cgi?id=121871
http://bugs.gentoo.org/attachment.cgi?id=98094

--- libdv-0.104-old/libdv/asm_common.S
+++ libdv-0.104/libdv/asm_common.S
@@ -0,0 +1,29 @@
+/* public domain, do what you want */
+
+#ifdef __PIC__
+# define MUNG(sym)                 sym##@GOTOFF(%ebp)
+# define MUNG_ARR(sym, args...)    sym##@GOTOFF(%ebp,##args)
+#else
+# define MUNG(sym)                 sym
+# define MUNG_ARR(sym, args...)    sym(,##args)
+#endif
+
+#ifdef __PIC__
+# undef __i686 /* gcc define gets in our way */
+# define LOAD_PIC_REG(reg) \
+	.ifndef  __i686.get_pc_thunk.reg; \
+	.section .gnu.linkonce.t.__i686.get_pc_thunk.reg,"ax",@progbits; \
+	.global  __i686.get_pc_thunk.reg; \
+	.hidden  __i686.get_pc_thunk.reg; \
+	.type    __i686.get_pc_thunk.reg,@function; \
+	__i686.get_pc_thunk.reg: \
+	movl (%esp), %e##reg; \
+	ret; \
+	.size __i686.get_pc_thunk.reg,.-__i686.get_pc_thunk.reg; \
+	.previous; \
+	.endif; \
+	call __i686.get_pc_thunk.reg; \
+	addl $_GLOBAL_OFFSET_TABLE_, %e##reg
+#else
+# define LOAD_PIC_REG(reg)
+#endif
--- libdv-0.104-old/libdv/dct_block_mmx.S
+++ libdv-0.104/libdv/dct_block_mmx.S
@@ -53,19 +53,22 @@ scratch2:       .quad 0
 
 .section .note.GNU-stack, "", @progbits
 
+#include "asm_common.S"
+
 .text
 
 .align 8	
 .global _dv_dct_88_block_mmx
 .hidden _dv_dct_88_block_mmx
 .type   _dv_dct_88_block_mmx,@function
 _dv_dct_88_block_mmx:
 
 	pushl   %ebp
-	movl    %esp, %ebp
 	pushl   %esi
 
-	movl    8(%ebp), %esi          # source
+	LOAD_PIC_REG(bp)
+
+	movl    12(%esp), %esi          # source
 
 # column 0
 	movq 16*0(%esi), %mm0          # v0
@@ -86,22 +91,22 @@ _dv_dct_88_block_mmx:
 
 	movq 16*3(%esi), %mm5          # v3
 	movq 16*4(%esi), %mm7          # v4
-	movq  %mm7, scratch1           # scratch1: v4   ; 
+	movq  %mm7, MUNG(scratch1)     # scratch1: v4   ; 
 	movq  %mm5, %mm7               # duplicate v3 
-	paddw scratch1, %mm5           # v03: v3+v4  
-	psubw scratch1, %mm7           # v04: v3-v4  
-	movq  %mm5, scratch2           # scratch2: v03
+	paddw MUNG(scratch1), %mm5     # v03: v3+v4  
+	psubw MUNG(scratch1), %mm7     # v04: v3-v4  
+	movq  %mm5, MUNG(scratch2)     # scratch2: v03
 	movq  %mm0, %mm5               # mm5: v00
 
-	paddw scratch2, %mm0           # v10: v00+v03   
-	psubw scratch2, %mm5           # v13: v00-v03   
-	movq  %mm3, scratch3           # scratch3: v02
+	paddw MUNG(scratch2), %mm0     # v10: v00+v03   
+	psubw MUNG(scratch2), %mm5     # v13: v00-v03   
+	movq  %mm3, MUNG(scratch3)     # scratch3: v02
 	movq  %mm1, %mm3               # duplicate v01
 
-	paddw scratch3, %mm1          # v11: v01+v02
-	psubw scratch3, %mm3          # v12: v01-v02
+	paddw MUNG(scratch3), %mm1    # v11: v01+v02
+	psubw MUNG(scratch3), %mm3    # v12: v01-v02
 
-	movq  %mm6, scratch4           # scratch4: v05
+	movq  %mm6, MUNG(scratch4)     # scratch4: v05
 	movq  %mm0, %mm6               # duplicate v10
 
 	paddw %mm1, %mm0              # v10+v11
@@ -111,10 +116,10 @@ _dv_dct_88_block_mmx:
 	movq  %mm6, 16*4(%esi)         # out4: v10-v11 
 
 	movq  %mm4, %mm0               # mm0: v06
-	paddw scratch4, %mm4          # v15: v05+v06 
+	paddw MUNG(scratch4), %mm4    # v15: v05+v06 
 	paddw  %mm2, %mm0             # v16: v07+v06
 
-	pmulhw WA3, %mm4               # v35~: WA3*v15
+	pmulhw MUNG(WA3), %mm4         # v35~: WA3*v15
 	psllw  $1, %mm4                # v35: compensate the coeefient scale
 
 	movq   %mm4, %mm6              # duplicate v35
@@ -123,7 +128,7 @@ _dv_dct_88_block_mmx:
 
 	paddw  %mm5, %mm3             # v22: v12+v13
 
-	pmulhw WA1, %mm3               # v32~: WA1*v22
+	pmulhw MUNG(WA1), %mm3         # v32~: WA1*v22
 	psllw  $16-NSHIFT, %mm3        # v32: compensate the coeefient scale
 	movq   %mm5, %mm6              # duplicate v13
 
@@ -134,13 +139,13 @@ _dv_dct_88_block_mmx:
 	movq  %mm6, 16*6(%esi)         # out6: v13-v32 
 
 
-	paddw  scratch4, %mm7         # v14n: v04+v05
+	paddw  MUNG(scratch4), %mm7   # v14n: v04+v05
 	movq   %mm0, %mm5              # duplicate v16
 
 	psubw  %mm7, %mm0             # va1: v16-v14n
-	pmulhw WA5, %mm0               # va0~:  va1*WA5
-	pmulhw WA4, %mm5               # v36~~: v16*WA4
-	pmulhw WA2, %mm7               # v34~~: v14n*WA2
+	pmulhw MUNG(WA5), %mm0         # va0~:  va1*WA5
+	pmulhw MUNG(WA4), %mm5         # v36~~: v16*WA4
+	pmulhw MUNG(WA2), %mm7         # v34~~: v14n*WA2
 	psllw  $16-WA4_SHIFT, %mm5     # v36: compensate the coeefient scale 
 	psllw  $16-NSHIFT, %mm7        # v34: compensate the coeefient scale
 
@@ -188,22 +193,22 @@ _dv_dct_88_block_mmx:
 
 	movq 16*3(%esi), %mm5              # v3
 	movq 16*4(%esi), %mm7              # v4
-	movq  %mm7, scratch1                    # scratch1: v4   ; 
+	movq  %mm7, MUNG(scratch1)     # scratch1: v4   ; 
 	movq  %mm5, %mm7               # duplicate v3 
-	paddw scratch1, %mm5           # v03: v3+v4  
-	psubw scratch1, %mm7           # v04: v3-v4  
-	movq  %mm5, scratch2        # scratch2: v03
+	paddw MUNG(scratch1), %mm5     # v03: v3+v4  
+	psubw MUNG(scratch1), %mm7     # v04: v3-v4  
+	movq  %mm5, MUNG(scratch2)     # scratch2: v03
 	movq  %mm0, %mm5               # mm5: v00
 
-	paddw scratch2, %mm0           # v10: v00+v03   
-	psubw scratch2, %mm5           # v13: v00-v03   
-	movq  %mm3, scratch3         # scratc3: v02
+	paddw MUNG(scratch2), %mm0     # v10: v00+v03   
+	psubw MUNG(scratch2), %mm5     # v13: v00-v03   
+	movq  %mm3, MUNG(scratch3)     # scratc3: v02
 	movq  %mm1, %mm3               # duplicate v01
 
-	paddw scratch3, %mm1           # v11: v01+v02
-	psubw scratch3, %mm3           # v12: v01-v02
+	paddw MUNG(scratch3), %mm1     # v11: v01+v02
+	psubw MUNG(scratch3), %mm3     # v12: v01-v02
 
-	movq  %mm6, scratch4         # scratc4: v05
+	movq  %mm6, MUNG(scratch4)     # scratc4: v05
 	movq  %mm0, %mm6               # duplicate v10
 
 	paddw %mm1, %mm0                            # v10+v11
@@ -213,10 +218,10 @@ _dv_dct_88_block_mmx:
 	movq  %mm6, 16*4(%esi)          # out4: v10-v11 
 
 	movq  %mm4, %mm0             # mm0: v06
-	paddw scratch4, %mm4         # v15: v05+v06 
+	paddw MUNG(scratch4), %mm4     # v15: v05+v06 
 	paddw  %mm2, %mm0                       # v16: v07+v06
 
-	pmulhw WA3, %mm4           # v35~: WA3*v15
+	pmulhw MUNG(WA3), %mm4         # v35~: WA3*v15
 	psllw  $16-NSHIFT, %mm4       # v35: compensate the coeefient scale
 
 	movq   %mm4, %mm6            # duplicate v35
@@ -225,7 +230,7 @@ _dv_dct_88_block_mmx:
 
 	paddw  %mm5, %mm3            # v22: v12+v13
 
-	pmulhw WA1, %mm3           # v32~: WA3*v15
+	pmulhw MUNG(WA1), %mm3         # v32~: WA3*v15
 	psllw  $16-NSHIFT, %mm3       # v32: compensate the coeefient scale
 	movq   %mm5, %mm6            # duplicate v13
 
@@ -235,13 +240,13 @@ _dv_dct_88_block_mmx:
 	movq  %mm5, 16*2(%esi)          # out2: v13+v32 
 	movq  %mm6, 16*6(%esi)          # out6: v13-v32 
 
-	paddw  scratch4, %mm7                           # v14n: v04+v05
+	paddw  MUNG(scratch4), %mm7     # v14n: v04+v05
 	movq   %mm0, %mm5                               # duplicate v16
 
 	psubw  %mm7, %mm0                               # va1: v16-v14n
-	pmulhw WA2, %mm7                # v34~~: v14n*WA2
-	pmulhw WA5, %mm0                # va0~:  va1*WA5
-	pmulhw WA4, %mm5                        # v36~~: v16*WA4
+	pmulhw MUNG(WA2), %mm7          # v34~~: v14n*WA2
+	pmulhw MUNG(WA5), %mm0          # va0~:  va1*WA5
+	pmulhw MUNG(WA4), %mm5          # v36~~: v16*WA4
 	psllw  $16-NSHIFT, %mm7
 	psllw  $16-WA4_SHIFT, %mm5      # v36: compensate the coeffient 
 		# scale note that WA4 is shifted 1 bit less than the others
@@ -748,11 +755,12 @@ _dv_dct_block_mmx_postscale_88:
 _dv_dct_248_block_mmx:
 
 	pushl   %ebp
-	movl    %esp, %ebp
 	pushl   %esi
 	pushl   %edi
 
-	movl    8(%ebp), %esi          # source
+	LOAD_PIC_REG(bp)
+
+	movl    16(%esp), %esi          # source
 
 # column 0
 
@@ -779,7 +789,7 @@ _dv_dct_248_block_mmx:
 	paddw %mm1, %mm0	       # v20: v10+v11
 	psubw %mm1, %mm3	       # v21: v10-v11
 
-	pmulhw WA1, %mm5               # v32~: WA1*v22
+	pmulhw MUNG(WA1), %mm5         # v32~: WA1*v22
 	movq  %mm4, %mm2	
 	psllw  $16-NSHIFT, %mm5        # v32: compensate the coeffient scale
 
@@ -818,7 +828,7 @@ _dv_dct_248_block_mmx:
 	paddw %mm1, %mm0	       # v20: v10+v11
 	psubw %mm1, %mm3	       # v21: v10-v11
 
-	pmulhw WA1, %mm5               # v32~: WA1*v22
+	pmulhw MUNG(WA1), %mm5         # v32~: WA1*v22
 	movq  %mm4, %mm2	
 	psllw  $16-NSHIFT, %mm5        # v32: compensate the coeffient scale
 
@@ -855,7 +865,7 @@ _dv_dct_248_block_mmx:
 	paddw %mm1, %mm0	       # v20: v10+v11
 	psubw %mm1, %mm3	       # v21: v10-v11
 
-	pmulhw WA1, %mm5               # v32~: WA1*v22
+	pmulhw MUNG(WA1), %mm5         # v32~: WA1*v22
 	movq  %mm4, %mm2	
 	psllw  $16-NSHIFT, %mm5        # v32: compensate the coeffient scale
 
@@ -892,7 +902,7 @@ _dv_dct_248_block_mmx:
 	paddw %mm1, %mm0	       # v20: v10+v11
 	psubw %mm1, %mm3	       # v21: v10-v11
 
-	pmulhw WA1, %mm5               # v32~: WA1*v22
+	pmulhw MUNG(WA1), %mm5         # v32~: WA1*v22
 	movq  %mm4, %mm2	
 	psllw  $16-NSHIFT, %mm5        # v32: compensate the coeffient scale
 
--- libdv-0.104-old/libdv/dv.c
+++ libdv-0.104/libdv/dv.c
@@ -205,6 +205,9 @@ dv_reconfigure(int clamp_luma, int clamp
 } /* dv_reconfigure */
 
 
+extern uint8_t dv_quant_offset[4];
+extern uint8_t dv_quant_shifts[22][4];
+
 static inline void 
 dv_decode_macroblock(dv_decoder_t *dv, dv_macroblock_t *mb, unsigned int quality) {
   int i;
@@ -218,7 +221,7 @@ dv_decode_macroblock(dv_decoder_t *dv, d
       dv_idct_248 (co248, mb->b[i].coeffs);
     } else {
 #if ARCH_X86
-      _dv_quant_88_inverse_x86(mb->b[i].coeffs,mb->qno,mb->b[i].class_no);
+      _dv_quant_88_inverse_x86(mb->b[i].coeffs,mb->qno,mb->b[i].class_no,dv_quant_offset,dv_quant_shifts);
       _dv_idct_88(mb->b[i].coeffs);
 #elif ARCH_X86_64
       _dv_quant_88_inverse_x86_64(mb->b[i].coeffs,mb->qno,mb->b[i].class_no);
@@ -250,7 +253,7 @@ dv_decode_video_segment(dv_decoder_t *dv
 	dv_idct_248 (co248, mb->b[b].coeffs);
       } else {
 #if ARCH_X86
-	_dv_quant_88_inverse_x86(bl->coeffs,mb->qno,bl->class_no);
+	_dv_quant_88_inverse_x86(bl->coeffs,mb->qno,bl->class_no,dv_quant_offset,dv_quant_shifts);
 	_dv_weight_88_inverse(bl->coeffs);
 	_dv_idct_88(bl->coeffs);
 #elif ARCH_X86_64
--- libdv-0.104-old/libdv/encode.c
+++ libdv-0.104/libdv/encode.c
@@ -521,7 +521,8 @@ static void reorder_block(dv_block_t *bl
 }
 
 extern unsigned long _dv_vlc_encode_block_mmx(dv_coeff_t* coeffs,
-					  dv_vlc_entry_t ** out);
+					  dv_vlc_entry_t ** out,
+					  dv_vlc_entry_t * lookup);
 
 extern unsigned long _dv_vlc_encode_block_mmx_x86_64(dv_coeff_t* coeffs,
 					  dv_vlc_entry_t ** out);
@@ -558,7 +559,7 @@ static unsigned long vlc_encode_block(dv
 #elif ARCH_X86
 	int num_bits;
 
-	num_bits = _dv_vlc_encode_block_mmx(coeffs, &o);
+	num_bits = _dv_vlc_encode_block_mmx(coeffs, &o, vlc_encode_lookup);
 	emms();
 #else
 	int num_bits;
@@ -574,7 +575,7 @@ static unsigned long vlc_encode_block(dv
 	return num_bits;
 }
 
-extern unsigned long _dv_vlc_num_bits_block_x86(dv_coeff_t* coeffs);
+extern unsigned long _dv_vlc_num_bits_block_x86(dv_coeff_t* coeffs, unsigned char* lookup);
 extern unsigned long _dv_vlc_num_bits_block_x86_64(dv_coeff_t* coeffs);
 
 extern unsigned long _dv_vlc_num_bits_block(dv_coeff_t* coeffs)
@@ -600,7 +601,7 @@ extern unsigned long _dv_vlc_num_bits_bl
 #elif ARCH_X86_64
 	return _dv_vlc_num_bits_block_x86_64(coeffs);
 #else
-	return _dv_vlc_num_bits_block_x86(coeffs);
+	return _dv_vlc_num_bits_block_x86(coeffs, vlc_num_bits_lookup);
 #endif
 }
 
--- libdv-0.104-old/libdv/encode_x86.S
+++ libdv-0.104/libdv/encode_x86.S
@@ -23,9 +23,6 @@
  *  The libdv homepage is http://libdv.sourceforge.net/.  
  */
 
-.data
-ALLONE:		.word 1,1,1,1
-VLCADDMASK:	.byte 255,0,0,0,255,0,0,0
 		
 
 .section .note.GNU-stack, "", @progbits
@@ -45,11 +43,14 @@ _dv_vlc_encode_block_mmx:	
 
 	movl	$63, %ecx
 
-	movl	vlc_encode_lookup, %esi
+	movl	4+4*4+8(%esp), %esi              # vlc_encode_lookup
 
 	pxor	%mm0, %mm0
 	pxor	%mm2, %mm2
-	movq	VLCADDMASK, %mm1
+	pushl	$0x000000FF                      # these four lines
+	pushl	$0x000000FF                      # load VLCADDMASK
+	movq	(%esp), %mm1                     # into %mm1 off the stack
+	addl	$8, %esp                         #  --> no TEXTRELs
 	xorl	%ebp, %ebp
 	subl	$8, %edx
 vlc_encode_block_mmx_loop:
@@ -121,7 +124,7 @@ _dv_vlc_num_bits_block_x86:	
 	addl	$2, %edi
 
 	movl	$63, %ecx
-	movl	vlc_num_bits_lookup, %esi
+	movl	4+4*4+4(%esp), %esi              # vlc_num_bits_lookup
 	
 vlc_num_bits_block_x86_loop:
 	movw	(%edi), %ax
@@ -579,8 +590,11 @@ _dv_need_dct_248_mmx_rows:
 	paddw	%mm5, %mm1
 
 	paddw	%mm1, %mm0
-	
-	pmaddwd	ALLONE, %mm0	
+
+	pushl	$0x00010001              # these four lines
+	pushl	$0x00010001              # load ALLONE
+	pmaddwd	(%esp), %mm0             # into %mm0 off the stack
+	addl	$8, %esp                 #  --> no TEXTRELs
 	movq	%mm0, %mm1
 	psrlq	$32, %mm1
 	paddd	%mm1, %mm0
--- libdv-0.104-old/libdv/idct_block_mmx.S
+++ libdv-0.104/libdv/idct_block_mmx.S
@@ -8,17 +8,21 @@
 
 .section .note.GNU-stack, "", @progbits
 
+#include "asm_common.S"
+
 .text
 	.align 4
 .global _dv_idct_block_mmx
 .hidden _dv_idct_block_mmx
 .type   _dv_idct_block_mmx,@function
 _dv_idct_block_mmx:
 	pushl	 %ebp
-	movl	 %esp,%ebp
 	pushl	 %esi
-	leal	 preSC, %ecx
-	movl	 8(%ebp),%esi		/* source matrix */
+
+	LOAD_PIC_REG(bp)
+
+	leal	 MUNG(preSC), %ecx
+	movl	 12(%esp),%esi		/* source matrix */
 
 /* 
  *	column 0: even part
@@ -35,7 +41,7 @@ _dv_idct_block_mmx:
 	movq %mm1, %mm2			/* added 11/1/96 */
 	pmulhw 8*8(%esi),%mm5		/* V8 */
 	psubsw %mm0, %mm1		/* V16 */
-	pmulhw x5a825a825a825a82, %mm1	/* 23170 ->V18 */
+	pmulhw MUNG(x5a825a825a825a82), %mm1	/* 23170 ->V18 */
 	paddsw %mm0, %mm2		/* V17 */
 	movq %mm2, %mm0			/* duplicate V17 */
 	psraw $1, %mm2			/* t75=t82 */
@@ -76,7 +82,7 @@ _dv_idct_block_mmx:
 	paddsw %mm0, %mm3		/* V29 ; free mm0 */
 	movq %mm7, %mm1			/* duplicate V26 */
 	psraw $1, %mm3			/* t91=t94 */
-	pmulhw x539f539f539f539f,%mm7	/* V33 */
+	pmulhw MUNG(x539f539f539f539f),%mm7	/* V33 */
 	psraw $1, %mm1			/* t96 */
 	movq %mm5, %mm0			/* duplicate V2 */
 	psraw $2, %mm4			/* t85=t87 */
@@ -84,15 +90,15 @@ _dv_idct_block_mmx:
 	psubsw %mm4, %mm0		/* V28 ; free mm4 */
 	movq %mm0, %mm2			/* duplicate V28 */
 	psraw $1, %mm5			/* t90=t93 */
-	pmulhw x4546454645464546,%mm0	/* V35 */
+	pmulhw MUNG(x4546454645464546),%mm0	/* V35 */
 	psraw $1, %mm2			/* t97 */
 	movq %mm5, %mm4			/* duplicate t90=t93 */
 	psubsw %mm2, %mm1		/* V32 ; free mm2 */
-	pmulhw x61f861f861f861f8,%mm1	/* V36 */
+	pmulhw MUNG(x61f861f861f861f8),%mm1	/* V36 */
 	psllw $1, %mm7			/* t107 */
 	paddsw %mm3, %mm5		/* V31 */
 	psubsw %mm3, %mm4		/* V30 ; free mm3 */
-	pmulhw x5a825a825a825a82,%mm4	/* V34 */
+	pmulhw MUNG(x5a825a825a825a82),%mm4	/* V34 */
 	nop
 	psubsw %mm1, %mm0		/* V38 */
 	psubsw %mm7, %mm1		/* V37 ; free mm7 */
@@ -159,7 +165,7 @@ _dv_idct_block_mmx:
 	psubsw %mm7, %mm1		/* V50 */
 	pmulhw 8*9(%esi), %mm5		/* V9 */
 	paddsw %mm7, %mm2		/* V51 */
-	pmulhw x5a825a825a825a82, %mm1	/* 23170 ->V52 */
+	pmulhw MUNG(x5a825a825a825a82), %mm1	/* 23170 ->V52 */
 	movq %mm2, %mm6			/* duplicate V51 */
 	psraw $1, %mm2			/* t138=t144 */
 	movq %mm3, %mm4			/* duplicate V1 */
@@ -200,11 +206,11 @@ _dv_idct_block_mmx:
  * even more by doing the correction step in a later stage when the number
  * is actually multiplied by 16
  */
-	paddw x0005000200010001, %mm4
+	paddw MUNG(x0005000200010001), %mm4
 	psubsw %mm6, %mm3		/* V60 ; free mm6 */
 	psraw $1, %mm0			/* t154=t156 */
 	movq %mm3, %mm1			/* duplicate V60 */
-	pmulhw x539f539f539f539f, %mm1	/* V67 */
+	pmulhw MUNG(x539f539f539f539f), %mm1	/* V67 */
 	movq %mm5, %mm6			/* duplicate V3 */
 	psraw $2, %mm4			/* t148=t150 */
 	paddsw %mm4, %mm5		/* V61 */
@@ -213,13 +219,13 @@ _dv_idct_block_mmx:
 	psllw $1, %mm1			/* t169 */
 	paddsw %mm0, %mm5		/* V65 -> result */
 	psubsw %mm0, %mm4		/* V64 ; free mm0 */
-	pmulhw x5a825a825a825a82, %mm4	/* V68 */
+	pmulhw MUNG(x5a825a825a825a82), %mm4	/* V68 */
 	psraw $1, %mm3			/* t158 */
 	psubsw %mm6, %mm3		/* V66 */
 	movq %mm5, %mm2			/* duplicate V65 */
-	pmulhw x61f861f861f861f8, %mm3	/* V70 */
+	pmulhw MUNG(x61f861f861f861f8), %mm3	/* V70 */
 	psllw $1, %mm6			/* t165 */
-	pmulhw x4546454645464546, %mm6	/* V69 */
+	pmulhw MUNG(x4546454645464546), %mm6	/* V69 */
 	psraw $1, %mm2			/* t172 */
 /* moved from next block */
 	movq 8*5(%esi), %mm0		/* V56 */
@@ -344,7 +350,7 @@ _dv_idct_block_mmx:
 *	movq 8*13(%esi), %mm4		tmt13
 */
 	psubsw %mm4, %mm3		/* V134 */
-	pmulhw x5a825a825a825a82, %mm3	/* 23170 ->V136 */
+	pmulhw MUNG(x5a825a825a825a82), %mm3	/* 23170 ->V136 */
 	movq 8*9(%esi), %mm6		/* tmt9 */
 	paddsw %mm4, %mm5		/* V135 ; mm4 free */
 	movq %mm0, %mm4			/* duplicate tmt1 */
@@ -373,17 +379,17 @@ _dv_idct_block_mmx:
 	psubsw %mm7, %mm0		/* V144 */
 	movq %mm0, %mm3			/* duplicate V144 */
 	paddsw %mm7, %mm2		/* V147 ; free mm7 */
-	pmulhw x539f539f539f539f, %mm0	/* 21407-> V151 */
+	pmulhw MUNG(x539f539f539f539f), %mm0	/* 21407-> V151 */
 	movq %mm1, %mm7			/* duplicate tmt3 */
 	paddsw %mm5, %mm7		/* V145 */
 	psubsw %mm5, %mm1		/* V146 ; free mm5 */
 	psubsw %mm1, %mm3		/* V150 */
 	movq %mm7, %mm5			/* duplicate V145 */
-	pmulhw x4546454645464546, %mm1	/* 17734-> V153 */
+	pmulhw MUNG(x4546454645464546), %mm1	/* 17734-> V153 */
 	psubsw %mm2, %mm5		/* V148 */
-	pmulhw x61f861f861f861f8, %mm3	/* 25080-> V154 */
+	pmulhw MUNG(x61f861f861f861f8), %mm3	/* 25080-> V154 */
 	psllw $2, %mm0			/* t311 */
-	pmulhw x5a825a825a825a82, %mm5	/* 23170-> V152 */
+	pmulhw MUNG(x5a825a825a825a82), %mm5	/* 23170-> V152 */
 	paddsw %mm2, %mm7		/* V149 ; free mm2 */
 	psllw $1, %mm1			/* t313 */
 	nop	/* without the nop - freeze here for one clock */
@@ -409,7 +415,7 @@ _dv_idct_block_mmx:
 	paddsw %mm3, %mm6		/* V164 ; free mm3 */
 	movq %mm4, %mm3			/* duplicate V142 */
 	psubsw %mm5, %mm4		/* V165 ; free mm5 */
-	movq %mm2, scratch7		/* out7 */
+	movq %mm2, MUNG(scratch7)		/* out7 */
 	psraw $4, %mm6
 	psraw $4, %mm4
 	paddsw %mm5, %mm3		/* V162 */
@@ -420,11 +426,11 @@ _dv_idct_block_mmx:
  */
 	movq %mm6, 8*9(%esi)		/* out9 */
 	paddsw %mm1, %mm0		/* V161 */
-	movq %mm3, scratch5		/* out5 */
+	movq %mm3, MUNG(scratch5)		/* out5 */
 	psubsw %mm1, %mm5		/* V166 ; free mm1 */
 	movq %mm4, 8*11(%esi)		/* out11 */
 	psraw $4, %mm5
-	movq %mm0, scratch3		/* out3 */
+	movq %mm0, MUNG(scratch3)		/* out3 */
 	movq %mm2, %mm4			/* duplicate V140 */
 	movq %mm5, 8*13(%esi)		/* out13 */
 	paddsw %mm7, %mm2		/* V160 */
@@ -434,7 +440,7 @@ _dv_idct_block_mmx:
 /* moved from the next block */
 	movq 8*3(%esi), %mm7
 	psraw $4, %mm4
-	movq %mm2, scratch1		/* out1 */
+	movq %mm2, MUNG(scratch1)		/* out1 */
 /* moved from the next block */
 	movq %mm0, %mm1
 	movq %mm4, 8*15(%esi)		/* out15 */
@@ -491,15 +497,15 @@ _dv_idct_block_mmx:
 	paddsw %mm4, %mm3		/* V113 ; free mm4 */
 	movq %mm0, %mm4			/* duplicate V110 */
 	paddsw %mm1, %mm2		/* V111 */
-	pmulhw x539f539f539f539f, %mm0	/* 21407-> V117 */
+	pmulhw MUNG(x539f539f539f539f), %mm0	/* 21407-> V117 */
 	psubsw %mm1, %mm5		/* V112 ; free mm1 */
 	psubsw %mm5, %mm4		/* V116 */
 	movq %mm2, %mm1			/* duplicate V111 */
-	pmulhw x4546454645464546, %mm5	/* 17734-> V119 */
+	pmulhw MUNG(x4546454645464546), %mm5	/* 17734-> V119 */
 	psubsw %mm3, %mm2		/* V114 */
-	pmulhw x61f861f861f861f8, %mm4	/* 25080-> V120 */
+	pmulhw MUNG(x61f861f861f861f8), %mm4	/* 25080-> V120 */
 	paddsw %mm3, %mm1		/* V115 ; free mm3 */
-	pmulhw x5a825a825a825a82, %mm2	/* 23170-> V118 */
+	pmulhw MUNG(x5a825a825a825a82), %mm2	/* 23170-> V118 */
 	psllw $2, %mm0			/* t266 */
 	movq %mm1, (%esi)		/* save V115 */
 	psllw $1, %mm5			/* t268 */
@@ -517,7 +523,7 @@ _dv_idct_block_mmx:
 	movq %mm6, %mm3			/* duplicate tmt4 */
 	psubsw %mm0, %mm6		/* V100 */
 	paddsw %mm0, %mm3		/* V101 ; free mm0 */
-	pmulhw x5a825a825a825a82, %mm6	/* 23170 ->V102 */
+	pmulhw MUNG(x5a825a825a825a82), %mm6	/* 23170 ->V102 */
 	movq %mm7, %mm5			/* duplicate tmt0 */
 	movq 8*8(%esi), %mm1		/* tmt8 */
 	paddsw %mm1, %mm7		/* V103 */
@@ -551,10 +557,10 @@ _dv_idct_block_mmx:
 	movq 8*2(%esi), %mm3		/* V123 */
 	paddsw %mm4, %mm7		/* out0 */
 /* moved up from next block */
-	movq scratch3, %mm0
+	movq MUNG(scratch3), %mm0
 	psraw $4, %mm7
 /* moved up from next block */
-	movq scratch5, %mm6 
+	movq MUNG(scratch5), %mm6 
 	psubsw %mm4, %mm1		/* out14 ; free mm4 */
 	paddsw %mm3, %mm5		/* out2 */
 	psraw $4, %mm1
@@ -565,7 +571,7 @@ _dv_idct_block_mmx:
 	movq %mm5, 8*2(%esi)		/* out2 ; free mm5 */
 	psraw $4, %mm2
 /* moved up to the prev block */
-	movq scratch7, %mm4
+	movq MUNG(scratch7), %mm4
 /* moved up to the prev block */
 	psraw $4, %mm0
 	movq %mm2, 8*12(%esi)		/* out12 ; free mm2 */
@@ -579,7 +585,7 @@ _dv_idct_block_mmx:
  *	psraw $4, %mm0
  *	psraw $4, %mm6
 */
-	movq scratch1, %mm1
+	movq MUNG(scratch1), %mm1
 	psraw $4, %mm4
 	movq %mm0, 8*3(%esi)		/* out3 */
 	psraw $4, %mm1
--- libdv-0.104-old/libdv/parse.c
+++ libdv-0.104/libdv/parse.c
@@ -477,6 +477,13 @@ dv_parse_ac_coeffs(dv_videosegment_t *se
   exit(0);
 #endif
 } /* dv_parse_ac_coeffs */
+#if defined __GNUC__ && __ELF__
+# define dv_strong_hidden_alias(name, aliasname) \
+    extern __typeof (name) aliasname __attribute__ ((alias (#name), visibility ("hidden")))
+dv_strong_hidden_alias(dv_parse_ac_coeffs, asm_dv_parse_ac_coeffs);
+#else
+int asm_dv_parse_ac_coeffs(dv_videosegment_t *seg) { return dv_parse_ac_coeffs(seg); }
+#endif
 
 /* ---------------------------------------------------------------------------
  */
--- libdv-0.104-old/libdv/quant.c
+++ libdv-0.104/libdv/quant.c
@@ -144,7 +144,7 @@ uint8_t  dv_quant_offset[4] = { 6,3,0,1 
 uint32_t	dv_quant_248_mul_tab [2] [22] [64];
 uint32_t dv_quant_88_mul_tab [2] [22] [64];
 
-extern void             _dv_quant_x86(dv_coeff_t *block,int qno,int klass);
+extern void             _dv_quant_x86(dv_coeff_t *block,int qno,int klass,uint8_t *dv_quant_offset,uint8_t *dv_quant_shifts);
 extern void             _dv_quant_x86_64(dv_coeff_t *block,int qno,int klass);
 static void quant_248_inverse_std(dv_coeff_t *block,int qno,int klass,dv_248_coeff_t *co);
 static void quant_248_inverse_mmx(dv_coeff_t *block,int qno,int klass,dv_248_coeff_t *co);
@@ -210,7 +210,7 @@ void _dv_quant(dv_coeff_t *block,int qno
 		_dv_quant_x86_64(block, qno, klass);
 		emms();
 #else
-		_dv_quant_x86(block, qno, klass);
+		_dv_quant_x86(block, qno, klass, dv_quant_offset, dv_quant_shifts);
 		emms();
 #endif
 	}
--- libdv-0.104-old/libdv/quant.h
+++ libdv-0.104/libdv/quant.h
@@ -27,7 +27,7 @@ extern void _dv_quant(dv_coeff_t *block,
 extern void _dv_quant_88_inverse(dv_coeff_t *block,int qno,int klass);
 extern void (*_dv_quant_248_inverse) (dv_coeff_t *block,int qno,int klass,
                                   dv_248_coeff_t *co);
-extern void _dv_quant_88_inverse_x86(dv_coeff_t *block,int qno,int klass);
+extern void _dv_quant_88_inverse_x86(dv_coeff_t *block,int qno,int klass, uint8_t *offset, uint8_t *shifts);
 extern void _dv_quant_88_inverse_x86_64(dv_coeff_t *block,int qno,int klass);
 extern void dv_quant_init (void);
 #ifdef __cplusplus
--- libdv-0.104-old/libdv/quant_x86.S
+++ libdv-0.104/libdv/quant_x86.S
@@ -71,10 +73,13 @@ _dv_quant_88_inverse_x86:	
 	
 	/*  pq = dv_quant_shifts[qno + dv_quant_offset[class]]; */
 	movl	ARGn(1),%eax	/* qno */
+	movl	ARGn(3),%ebx	/* dv_quant_offset */
+	addl	ARGn(2),%ebx	/* class */
+	movzbl	(%ebx),%ecx
 	movl	ARGn(2),%ebx	/* class */
-	movzbl	dv_quant_offset(%ebx),%ecx
 	addl	%ecx,%eax
-	leal	dv_quant_shifts(,%eax,4),%edx	/* edx is pq */
+	movl	ARGn(4),%edx	/* dv_quant_shifts */
+	leal	(%edx,%eax,4),%edx	/* edx is pq */
 
 	/* extra = (class == 3); */
 				/*  0   1   2   3 */
@@ -212,11 +219,13 @@ _dv_quant_x86:	
 	
 	/*  pq = dv_quant_shifts[qno + dv_quant_offset[class]]; */
 	movl	ARGn(1),%eax	/* qno */
+	movl	ARGn(3),%ebx	/* offset */
+	addl	ARGn(2),%ebx	/* class */
+	movzbl	(%ebx),%ecx
 	movl	ARGn(2),%ebx	/* class */
-
-	movzbl	dv_quant_offset(%ebx),%ecx
+	movl	ARGn(4),%edx	/* shifts */
 	addl	%ecx,%eax
-	leal	dv_quant_shifts(,%eax,4),%edx	/* edx is pq */
+	leal	(%edx,%eax,4),%edx	/* edx is pq */
 
 	/* extra = (class == 3); */
 				/*  0   1   2   3 */
--- libdv-0.104-old/libdv/rgbtoyuv.S
+++ libdv-0.104/libdv/rgbtoyuv.S
@@ -41,9 +41,6 @@
 #define DV_WIDTH_SHORT_HALF 720
 #define DV_WIDTH_BYTE_HALF  360	
 		
-.global _dv_rgbtoycb_mmx
-# .global yuvtoycb_mmx
-
 .data
 
 .align 8
@@ -110,25 +107,26 @@ VR0GR:  .long   0,0
 VBG0B:  .long   0,0
 	
 #endif	
-	
+
+#include "asm_common.S"
+
 .section .note.GNU-stack, "", @progbits
 
 .text
 
-#define _inPtr     8
-#define _rows      12
-#define _columns   16
-#define _outyPtr   20
-#define _outuPtr   24
-#define _outvPtr   28
+#define _inPtr     24+8
+#define _rows      24+12
+#define _columns   24+16
+#define _outyPtr   24+20
+#define _outuPtr   24+24
+#define _outvPtr   24+28
 
 .global _dv_rgbtoycb_mmx
 .hidden _dv_rgbtoycb_mmx
 .type   _dv_rgbtoycb_mmx,@function
 _dv_rgbtoycb_mmx:
 
 	pushl   %ebp
-	movl    %esp, %ebp
 	pushl   %eax
 	pushl   %ebx
 	pushl   %ecx
@@ -131,46 +132,47 @@ _dv_rgbtoycb_mmx:
 	pushl   %esi
 	pushl   %edi
 
-	leal    ZEROSX, %eax    #This section gets around a bug
+	LOAD_PIC_REG(bp)
+
+	leal    MUNG(ZEROSX), %eax    #This section gets around a bug
 	movq    (%eax), %mm0    #unlikely to persist
-	movq    %mm0, ZEROS
-	leal    OFFSETDX, %eax
+	movq    %mm0, MUNG(ZEROS)
+	leal    MUNG(OFFSETDX), %eax
 	movq    (%eax), %mm0
-	movq    %mm0, OFFSETD
-	leal    OFFSETWX, %eax
+	movq    %mm0, MUNG(OFFSETD)
+	leal    MUNG(OFFSETWX), %eax
 	movq    (%eax), %mm0
-	movq    %mm0, OFFSETW
-	leal    OFFSETBX, %eax
+	movq    %mm0, MUNG(OFFSETW)
+	leal    MUNG(OFFSETBX), %eax
 	movq    (%eax), %mm0
-	movq    %mm0, OFFSETB
-	leal    YR0GRX, %eax
+	movq    %mm0, MUNG(OFFSETB)
+	leal    MUNG(YR0GRX), %eax
 	movq    (%eax), %mm0
-	movq    %mm0, YR0GR
-	leal    YBG0BX, %eax
+	movq    %mm0, MUNG(YR0GR)
+	leal    MUNG(YBG0BX), %eax
 	movq    (%eax), %mm0
-	movq    %mm0, YBG0B
-	leal    UR0GRX, %eax
+	movq    %mm0, MUNG(YBG0B)
+	leal    MUNG(UR0GRX), %eax
 	movq    (%eax), %mm0
-	movq    %mm0, UR0GR
-	leal    UBG0BX, %eax
+	movq    %mm0, MUNG(UR0GR)
+	leal    MUNG(UBG0BX), %eax
 	movq    (%eax), %mm0
-	movq    %mm0, UBG0B
-	leal    VR0GRX, %eax
+	movq    %mm0, MUNG(UBG0B)
+	leal    MUNG(VR0GRX), %eax
 	movq    (%eax), %mm0
-	movq    %mm0, VR0GR
-	leal    VBG0BX, %eax
+	movq    %mm0, MUNG(VR0GR)
+	leal    MUNG(VBG0BX), %eax
 	movq    (%eax), %mm0
-	movq    %mm0, VBG0B
-	
-	movl    _rows(%ebp), %eax
-	movl    _columns(%ebp), %ebx
+	movq    %mm0, MUNG(VBG0B)
+	movl    _rows(%esp), %eax
+	movl    _columns(%esp), %ebx
 	mull    %ebx            #number pixels
 	shrl    $3, %eax        #number of loops
 	movl    %eax, %edi      #loop counter in edi
-	movl    _inPtr(%ebp), %eax
-	movl    _outyPtr(%ebp), %ebx
-	movl    _outuPtr(%ebp), %ecx
-	movl    _outvPtr(%ebp), %edx
+	movl    _inPtr(%esp), %eax
+	movl    _outyPtr(%esp), %ebx
+	movl    _outuPtr(%esp), %ecx
+	movl    _outvPtr(%esp), %edx
 rgbtoycb_mmx_loop: 
 	movq    (%eax), %mm1    #load G2R2B1G1R1B0G0R0
 	pxor    %mm6, %mm6      #0 -> mm6
@@ -184,29 +186,29 @@ rgbtoycb_mmx_loop: 
 	punpcklbw %mm6, %mm1     #B1G1R1B0 -> mm1
 	movq    %mm0, %mm2      #R1B0G0R0 -> mm2
 
-	pmaddwd YR0GR, %mm0     #yrR1,ygG0+yrR0 -> mm0
+	pmaddwd MUNG(YR0GR), %mm0     #yrR1,ygG0+yrR0 -> mm0
 	movq    %mm1, %mm3      #B1G1R1B0 -> mm3
 
-	pmaddwd YBG0B, %mm1     #ybB1+ygG1,ybB0 -> mm1
+	pmaddwd MUNG(YBG0B), %mm1     #ybB1+ygG1,ybB0 -> mm1
 	movq    %mm2, %mm4      #R1B0G0R0 -> mm4
 
-	pmaddwd UR0GR, %mm2     #urR1,ugG0+urR0 -> mm2
+	pmaddwd MUNG(UR0GR), %mm2     #urR1,ugG0+urR0 -> mm2
 	movq    %mm3, %mm5      #B1G1R1B0 -> mm5
 
-	pmaddwd UBG0B, %mm3     #ubB1+ugG1,ubB0 -> mm3
+	pmaddwd MUNG(UBG0B), %mm3     #ubB1+ugG1,ubB0 -> mm3
 	punpckhbw       %mm6, %mm7 #    00G2R2 -> mm7
 
-	pmaddwd VR0GR, %mm4     #vrR1,vgG0+vrR0 -> mm4
+	pmaddwd MUNG(VR0GR), %mm4     #vrR1,vgG0+vrR0 -> mm4
 	paddd   %mm1, %mm0      #Y1Y0 -> mm0
 
-	pmaddwd VBG0B, %mm5     #vbB1+vgG1,vbB0 -> mm5
+	pmaddwd MUNG(VBG0B), %mm5     #vbB1+vgG1,vbB0 -> mm5
 
 	movq    8(%eax), %mm1   #R5B4G4R4B3G3R3B2 -> mm1
 	paddd   %mm3, %mm2      #U1U0 -> mm2
 
 	movq    %mm1, %mm6      #R5B4G4R4B3G3R3B2 -> mm6
 
-	punpcklbw       ZEROS, %mm1     #B3G3R3B2 -> mm1
+	punpcklbw       MUNG(ZEROS), %mm1     #B3G3R3B2 -> mm1
 	paddd   %mm5, %mm4      #V1V0 -> mm4
 
 	movq    %mm1, %mm5      #B3G3R3B2 -> mm5
@@ -214,29 +216,29 @@ rgbtoycb_mmx_loop: 
 
 	paddd   %mm7, %mm1      #R3B200+00G2R2=R3B2G2R2->mm1
 
-	punpckhbw       ZEROS, %mm6     #R5B4G4R3 -> mm6
+	punpckhbw       MUNG(ZEROS), %mm6     #R5B4G4R3 -> mm6
 	movq    %mm1, %mm3      #R3B2G2R2 -> mm3
 
-	pmaddwd YR0GR, %mm1     #yrR3,ygG2+yrR2 -> mm1
+	pmaddwd MUNG(YR0GR), %mm1     #yrR3,ygG2+yrR2 -> mm1
 	movq    %mm5, %mm7      #B3G3R3B2 -> mm7
 
-	pmaddwd YBG0B, %mm5     #ybB3+ygG3,ybB2 -> mm5
+	pmaddwd MUNG(YBG0B), %mm5     #ybB3+ygG3,ybB2 -> mm5
 	psrad   $FIXPSHIFT, %mm0       #32-bit scaled Y1Y0 -> mm0
 
-	movq    %mm6, TEMP0     #R5B4G4R4 -> TEMP0
+	movq    %mm6, MUNG(TEMP0)     #R5B4G4R4 -> TEMP0
 	movq    %mm3, %mm6      #R3B2G2R2 -> mm6
-	pmaddwd UR0GR, %mm6     #urR3,ugG2+urR2 -> mm6
+	pmaddwd MUNG(UR0GR), %mm6     #urR3,ugG2+urR2 -> mm6
 	psrad   $FIXPSHIFT, %mm2       #32-bit scaled U1U0 -> mm2
 
 	paddd   %mm5, %mm1      #Y3Y2 -> mm1
 	movq    %mm7, %mm5      #B3G3R3B2 -> mm5
-	pmaddwd UBG0B, %mm7     #ubB3+ugG3,ubB2
+	pmaddwd MUNG(UBG0B), %mm7     #ubB3+ugG3,ubB2
 	psrad   $FIXPSHIFT, %mm1 #32-bit scaled Y3Y2 -> mm1
 
-	pmaddwd VR0GR, %mm3     #vrR3,vgG2+vgR2
+	pmaddwd MUNG(VR0GR), %mm3     #vrR3,vgG2+vgR2
 	packssdw        %mm1, %mm0      #Y3Y2Y1Y0 -> mm0
 
-	pmaddwd VBG0B, %mm5     #vbB3+vgG3,vbB2 -> mm5
+	pmaddwd MUNG(VBG0B), %mm5     #vbB3+vgG3,vbB2 -> mm5
 	psrad   $FIXPSHIFT, %mm4       #32-bit scaled V1V0 -> mm4
 
 	movq    16(%eax), %mm1  #B7G7R7B6G6R6B5G5 -> mm7
@@ -251,58 +253,58 @@ rgbtoycb_mmx_loop: 
 	movq    %mm7, %mm5      #R7B6G6R6B5G500 -> mm5
 	psrad   $FIXPSHIFT, %mm3       #32-bit scaled V3V2 -> mm3
 
-	paddw	OFFSETY, %mm0
+	paddw	MUNG(OFFSETY), %mm0
 	movq    %mm0, (%ebx)     #store Y3Y2Y1Y0 
 	packssdw %mm6, %mm2      #32-bit scaled U3U2U1U0 -> mm2
 
-	movq    TEMP0, %mm0     #R5B4G4R4 -> mm0
+	movq    MUNG(TEMP0), %mm0     #R5B4G4R4 -> mm0
 	addl	$8, %ebx
-	
-	punpcklbw       ZEROS, %mm7     #B5G500 -> mm7
+
+	punpcklbw       MUNG(ZEROS), %mm7     #B5G500 -> mm7
 	movq    %mm0, %mm6      #R5B4G4R4 -> mm6
 
-	movq    %mm2, TEMPU     #32-bit scaled U3U2U1U0 -> TEMPU
+	movq    %mm2, MUNG(TEMPU)     #32-bit scaled U3U2U1U0 -> TEMPU
 	psrlq   $32, %mm0       #00R5B4 -> mm0
 
 	paddw   %mm0, %mm7      #B5G5R5B4 -> mm7
 	movq    %mm6, %mm2      #B5B4G4R4 -> mm2
 
-	pmaddwd YR0GR, %mm2     #yrR5,ygG4+yrR4 -> mm2
+	pmaddwd MUNG(YR0GR), %mm2     #yrR5,ygG4+yrR4 -> mm2
 	movq    %mm7, %mm0      #B5G5R5B4 -> mm0
 
-	pmaddwd YBG0B, %mm7     #ybB5+ygG5,ybB4 -> mm7
+	pmaddwd MUNG(YBG0B), %mm7     #ybB5+ygG5,ybB4 -> mm7
 	packssdw        %mm3, %mm4      #32-bit scaled V3V2V1V0 -> mm4
 
 	addl    $24, %eax       #increment RGB count
 
-	movq    %mm4, TEMPV     #(V3V2V1V0)/256 -> mm4
+	movq    %mm4, MUNG(TEMPV)     #(V3V2V1V0)/256 -> mm4
 	movq    %mm6, %mm4      #B5B4G4R4 -> mm4
 
-	pmaddwd UR0GR, %mm6     #urR5,ugG4+urR4
+	pmaddwd MUNG(UR0GR), %mm6     #urR5,ugG4+urR4
 	movq    %mm0, %mm3      #B5G5R5B4 -> mm0
 
-	pmaddwd UBG0B, %mm0     #ubB5+ugG5,ubB4
+	pmaddwd MUNG(UBG0B), %mm0     #ubB5+ugG5,ubB4
 	paddd   %mm7, %mm2      #Y5Y4 -> mm2
 
-	pmaddwd         VR0GR, %mm4     #vrR5,vgG4+vrR4 -> mm4
+	pmaddwd         MUNG(VR0GR), %mm4     #vrR5,vgG4+vrR4 -> mm4
 	pxor    %mm7, %mm7      #0 -> mm7
 
-	pmaddwd VBG0B, %mm3     #vbB5+vgG5,vbB4 -> mm3
+	pmaddwd MUNG(VBG0B), %mm3     #vbB5+vgG5,vbB4 -> mm3
 	punpckhbw       %mm7, %mm1      #B7G7R7B6 -> mm1
 
 	paddd   %mm6, %mm0      #U5U4 -> mm0
 	movq    %mm1, %mm6      #B7G7R7B6 -> mm6
 
-	pmaddwd YBG0B, %mm6     #ybB7+ygG7,ybB6 -> mm6
+	pmaddwd MUNG(YBG0B), %mm6     #ybB7+ygG7,ybB6 -> mm6
 	punpckhbw       %mm7, %mm5      #R7B6G6R6 -> mm5
 
 	movq    %mm5, %mm7      #R7B6G6R6 -> mm7
 	paddd   %mm4, %mm3      #V5V4 -> mm3
 
-	pmaddwd YR0GR, %mm5     #yrR7,ygG6+yrR6 -> mm5
+	pmaddwd MUNG(YR0GR), %mm5     #yrR7,ygG6+yrR6 -> mm5
 	movq    %mm1, %mm4      #B7G7R7B6 -> mm4
 
-	pmaddwd UBG0B, %mm4     #ubB7+ugG7,ubB6 -> mm4
+	pmaddwd MUNG(UBG0B), %mm4     #ubB7+ugG7,ubB6 -> mm4
 	psrad   $FIXPSHIFT, %mm0       #32-bit scaled U5U4 -> mm0
 
 	psrad   $FIXPSHIFT, %mm2       #32-bit scaled Y5Y4 -> mm2
@@ -310,25 +312,25 @@ rgbtoycb_mmx_loop: 
 	paddd   %mm5, %mm6      #Y7Y6 -> mm6
 	movq    %mm7, %mm5      #R7B6G6R6 -> mm5
 
-	pmaddwd UR0GR, %mm7     #urR7,ugG6+ugR6 -> mm7
+	pmaddwd MUNG(UR0GR), %mm7     #urR7,ugG6+ugR6 -> mm7
 	psrad   $FIXPSHIFT, %mm3       #32-bit scaled V5V4 -> mm3
 
-	pmaddwd VBG0B, %mm1     #vbB7+vgG7,vbB6 -> mm1
+	pmaddwd MUNG(VBG0B), %mm1     #vbB7+vgG7,vbB6 -> mm1
 	psrad   $FIXPSHIFT, %mm6 #32-bit scaled Y7Y6 -> mm6
 
 	packssdw %mm6, %mm2     #Y7Y6Y5Y4 -> mm2
 
-	pmaddwd VR0GR, %mm5     #vrR7,vgG6+vrR6 -> mm5
+	pmaddwd MUNG(VR0GR), %mm5     #vrR7,vgG6+vrR6 -> mm5
 	paddd   %mm4, %mm7      #U7U6 -> mm7    
 
 	psrad   $FIXPSHIFT, %mm7       #32-bit scaled U7U6 -> mm7
-	paddw	OFFSETY, %mm2
+	paddw	MUNG(OFFSETY), %mm2
 	movq	%mm2, (%ebx)    #store Y7Y6Y5Y4 
 
-	movq	ALLONE, %mm6
+	movq	MUNG(ALLONE), %mm6
 	packssdw %mm7, %mm0     #32-bit scaled U7U6U5U4 -> mm0
 
-	movq    TEMPU, %mm4     #32-bit scaled U3U2U1U0 -> mm4
+	movq    MUNG(TEMPU), %mm4     #32-bit scaled U3U2U1U0 -> mm4
 	pmaddwd	%mm6, %mm0      #U7U6U5U4 averaged -> (U7U6)(U5U4)=UU3 UU2->mm0
 	
 	pmaddwd	%mm6, %mm4      #U3U2U1U0 averaged -> (U3U2)(U1U0)=UU1 UU0->mm4
@@ -338,8 +340,8 @@ rgbtoycb_mmx_loop: 
 
 	psrad   $FIXPSHIFT, %mm1       #32-bit scaled V7V6 -> mm1
 	psraw	$1, %mm4 	#divide UU3 UU2 UU1 UU0 by 2 -> mm4
-		
-	movq    TEMPV, %mm5     #32-bit scaled V3V2V1V0 -> mm5
+
+	movq    MUNG(TEMPV), %mm5     #32-bit scaled V3V2V1V0 -> mm5
 
 	movq	%mm4, (%ecx)    # store U	
 
@@ -422,14 +426,15 @@ _dv_ppm_copy_y_block_mmx:
 _dv_pgm_copy_y_block_mmx:
 
 	pushl   %ebp
-	movl    %esp, %ebp
 	pushl   %esi
 	pushl	%edi
-	
-	movl    8(%ebp), %edi          # dest
-	movl    12(%ebp), %esi         # src
 
-	movq	OFFSETY, %mm7
+	LOAD_PIC_REG(bp)
+
+	movl    16(%esp), %edi          # dest
+	movl    20(%esp), %esi         # src
+
+	movq	MUNG(OFFSETY), %mm7
 	pxor	%mm6, %mm6
 	
 	movq	(%esi), %mm0
@@ -564,14 +571,15 @@ _dv_pgm_copy_y_block_mmx:
 _dv_video_copy_y_block_mmx:
 
 	pushl   %ebp
-	movl    %esp, %ebp
 	pushl   %esi
 	pushl	%edi
-	
-	movl    8(%ebp), %edi          # dest
-	movl    12(%ebp), %esi         # src
 
-	movq	OFFSETBX, %mm7
+	LOAD_PIC_REG(bp)
+
+	movl    16(%esp), %edi          # dest
+	movl    20(%esp), %esi         # src
+
+	movq	MUNG(OFFSETBX), %mm7
 	pxor	%mm6, %mm6
 	
 	movq	(%esi), %mm0
@@ -852,16 +864,16 @@ _dv_ppm_copy_pal_c_block_mmx:
 _dv_pgm_copy_pal_c_block_mmx:
 				
 	pushl   %ebp
-	movl    %esp, %ebp
 	pushl   %esi
 	pushl	%edi
 	pushl	%ebx
-	
-	movl    8(%ebp), %edi          # dest
-	movl    12(%ebp), %esi         # src
 
+	LOAD_PIC_REG(bp)
+
+	movl    20(%esp), %edi          # dest
+	movl    24(%esp), %esi         # src
 
-	movq	OFFSETBX, %mm7
+	movq	MUNG(OFFSETBX), %mm7
 	pxor	%mm6, %mm6
 
 	
@@ -1000,15 +1014,16 @@ _dv_pgm_copy_pal_c_block_mmx:
 _dv_video_copy_pal_c_block_mmx:
 				
 	pushl   %ebp
-	movl    %esp, %ebp
 	pushl   %esi
 	pushl	%edi
 	pushl	%ebx
-	
-	movl    8(%ebp), %edi          # dest
-	movl    12(%ebp), %esi         # src
 
-	movq	OFFSETBX, %mm7
+	LOAD_PIC_REG(bp)
+
+	movl    20(%esp), %edi          # dest
+	movl    24(%esp), %esi         # src
+
+	movq	MUNG(OFFSETBX), %mm7
 	paddw	%mm7, %mm7
 	pxor	%mm6, %mm6
 
@@ -1095,18 +1112,18 @@ video_copy_pal_c_block_mmx_loop:	
 _dv_ppm_copy_ntsc_c_block_mmx:
 				
 	pushl   %ebp
-	movl    %esp, %ebp
 	pushl   %esi
 	pushl	%edi
 	pushl	%ebx
-	
-	movl    8(%ebp), %edi          # dest
-	movl    12(%ebp), %esi         # src
+
+	LOAD_PIC_REG(bp)
+
+	movl    20(%esp), %edi          # dest
+	movl    24(%esp), %esi         # src
 
 	movl	$4, %ebx	
 
-	movq	ALLONE, %mm6
-	
+	movq	MUNG(ALLONE), %mm6
 ppm_copy_ntsc_c_block_mmx_loop:	
 	
 	movq	(%esi), %mm0
@@ -1168,14 +1187,15 @@ ppm_copy_ntsc_c_block_mmx_loop:	
 _dv_pgm_copy_ntsc_c_block_mmx:
 				
 	pushl   %ebp
-	movl    %esp, %ebp
 	pushl   %esi
 	pushl	%edi
-	
-	movl    8(%ebp), %edi          # dest
-	movl    12(%ebp), %esi         # src
 
-	movq	OFFSETBX, %mm7
+	LOAD_PIC_REG(bp)
+
+	movl    16(%esp), %edi          # dest
+	movl    20(%esp), %esi         # src
+
+	movq	MUNG(OFFSETBX), %mm7
 	paddw	%mm7, %mm7
 	pxor	%mm6, %mm6
 
@@ -1325,15 +1347,16 @@ _dv_pgm_copy_ntsc_c_block_mmx:
 _dv_video_copy_ntsc_c_block_mmx:
 				
 	pushl   %ebp
-	movl    %esp, %ebp
 	pushl   %esi
 	pushl	%edi
 	pushl	%ebx
-	
-	movl    8(%ebp), %edi          # dest
-	movl    12(%ebp), %esi         # src
 
-	movq	OFFSETBX, %mm7
+	LOAD_PIC_REG(bp)
+
+	movl    20(%esp), %edi          # dest
+	movl    24(%esp), %esi         # src
+
+	movq	MUNG(OFFSETBX), %mm7
 	paddw	%mm7, %mm7
 	pxor	%mm6, %mm6
 
--- libdv-0.104-old/libdv/rgbtoyuv_x86_64.S
+++ libdv-0.104/libdv/rgbtoyuv_x86_64.S
@@ -41,9 +41,6 @@
 #define DV_WIDTH_SHORT_HALF 720
 #define DV_WIDTH_BYTE_HALF  360	
 		
-.global _dv_rgbtoycb_mmx_x86_64
-# .global yuvtoycb_mmx_x86_64
-
 .data
 
 .align 8
--- libdv-0.104-old/libdv/vlc_x86.S
+++ libdv-0.104/libdv/vlc_x86.S
@@ -1,31 +1,39 @@
 	#include "asmoff.h"
 .section .note.GNU-stack, "", @progbits
+	#include "asm_common.S"
 
 .text
 	.align 4
 .globl dv_decode_vlc 
+.globl asm_dv_decode_vlc 
+.hidden asm_dv_decode_vlc
+asm_dv_decode_vlc = dv_decode_vlc
+
 	.type	 dv_decode_vlc,@function
 dv_decode_vlc:
 	pushl %ebx
+	pushl %ebp
+
+	LOAD_PIC_REG(bp)
 
-	/* Args are at 8(%esp). */
-	movl  8(%esp),%eax		/* %eax is bits */
-	movl  12(%esp),%ebx		/* %ebx is maxbits */
+	/* Args are at 12(%esp). */
+	movl  12(%esp),%eax		/* %eax is bits */
+	movl  16(%esp),%ebx		/* %ebx is maxbits */
 	andl  $0x3f,%ebx		/* limit index range STL*/
 
-	movl  dv_vlc_class_index_mask(,%ebx,4),%edx
+	movl  MUNG_ARR(dv_vlc_class_index_mask,%ebx,4),%edx
 	andl  %eax,%edx
-	movl  dv_vlc_class_index_rshift(,%ebx,4),%ecx
+	movl  MUNG_ARR(dv_vlc_class_index_rshift,%ebx,4),%ecx
 	sarl  %cl,%edx
-	movl  dv_vlc_classes(,%ebx,4),%ecx
+	movl  MUNG_ARR(dv_vlc_classes,%ebx,4),%ecx
 	movsbl  (%ecx,%edx,1),%edx	/* %edx is class */
 			
-	movl  dv_vlc_index_mask(,%edx,4),%ebx
-	movl  dv_vlc_index_rshift(,%edx,4),%ecx
+	movl  MUNG_ARR(dv_vlc_index_mask,%edx,4),%ebx
+	movl  MUNG_ARR(dv_vlc_index_rshift,%edx,4),%ecx
 	andl  %eax,%ebx
 	sarl  %cl,%ebx
 
-	movl  dv_vlc_lookups(,%edx,4),%edx
+	movl  MUNG_ARR(dv_vlc_lookups,%edx,4),%edx
 	movl  (%edx,%ebx,4),%edx
 
 	/* Now %edx holds result, like this:
@@ -42,7 +51,7 @@ dv_decode_vlc:
 	movl  %edx,%ecx
 	sarl  $8,%ecx
 	andl  $0xff,%ecx
-	movl  sign_mask(,%ecx,4),%ebx
+	movl  MUNG_ARR(sign_mask,%ecx,4),%ebx
 	andl  %ebx,%eax
 	negl  %eax
 	sarl  $31,%eax
@@ -63,14 +72,14 @@ dv_decode_vlc:
 	    *result = broken;
 	Note that the 'broken' pattern is all ones (i.e. 0xffffffff)
 	*/
-	movl  12(%esp),%ebx		/* %ebx is maxbits */
+	movl  16(%esp),%ebx		/* %ebx is maxbits */
 	subl  %ecx,%ebx
 	sbbl  %ebx,%ebx
 	orl   %ebx,%edx
 
-	movl  16(%esp),%eax
+	movl  20(%esp),%eax
 	movl  %edx,(%eax)
-	
+	popl  %ebp
 	popl  %ebx
 	ret
 	
@@ -80,21 +89,28 @@ dv_decode_vlc:
 	.type	 __dv_decode_vlc,@function
 __dv_decode_vlc:
 	pushl %ebx
+	pushl %ebp
+
+	LOAD_PIC_REG(bp)
 
-	/* Args are at 8(%esp). */
-	movl  8(%esp),%eax		/* %eax is bits */
+	/* Args are at 12(%esp). */
+	movl  12(%esp),%eax		/* %eax is bits */
 	
 	movl  %eax,%edx			/* %edx is class */
 	andl  $0xfe00,%edx
 	sarl  $9,%edx
+#ifdef __PIC__
+	movsbl dv_vlc_class_lookup5@GOTOFF(%ebp,%edx),%edx
+#else
 	movsbl dv_vlc_class_lookup5(%edx),%edx
-	
-	movl  dv_vlc_index_mask(,%edx,4),%ebx
-	movl  dv_vlc_index_rshift(,%edx,4),%ecx
+#endif
+
+	movl  MUNG_ARR(dv_vlc_index_mask,%edx,4),%ebx
+	movl  MUNG_ARR(dv_vlc_index_rshift,%edx,4),%ecx
 	andl  %eax,%ebx
 	sarl  %cl,%ebx
 
-	movl  dv_vlc_lookups(,%edx,4),%edx
+	movl  MUNG_ARR(dv_vlc_lookups,%edx,4),%edx
 	movl  (%edx,%ebx,4),%edx
 
 	/* Now %edx holds result, like this:
@@ -112,7 +128,7 @@ __dv_decode_vlc:
 	movl  %edx,%ecx
 	sarl  $8,%ecx
 	andl  $0xff,%ecx
-	movl  sign_mask(,%ecx,4),%ecx
+	movl  MUNG_ARR(sign_mask,%ecx,4),%ecx
 	andl  %ecx,%eax
 	negl  %eax
 	sarl  $31,%eax
@@ -127,9 +143,9 @@ __dv_decode_vlc:
 	xorl  %eax,%edx
 	subl  %eax,%edx
 
-	movl  12(%esp),%eax
+	movl  16(%esp),%eax
 	movl  %edx,(%eax)
-	
+	popl  %ebp
 	popl  %ebx
 	ret
 
@@ -140,14 +156,20 @@ void dv_parse_ac_coeffs_pass0(bitstream_
 */
 .text
 	.align	4
+.globl asm_dv_parse_ac_coeffs_pass0
+.hidden asm_dv_parse_ac_coeffs_pass0
+	asm_dv_parse_ac_coeffs_pass0 = dv_parse_ac_coeffs_pass0
+
 .globl	dv_parse_ac_coeffs_pass0
 .type	dv_parse_ac_coeffs_pass0,@function
 dv_parse_ac_coeffs_pass0:
 	pushl	%ebx
 	pushl	%edi
 	pushl	%esi
 	pushl	%ebp
 
+	LOAD_PIC_REG(si)
+
 #define ARGn(N)  (20+(4*(N)))(%esp)
 
 	/*
@@ -159,8 +182,10 @@ dv_parse_ac_coeffs_pass0:
 	ebp	bl
 	*/
 	movl    ARGn(2),%ebp
+#ifndef __PIC__
 	movl	ARGn(0),%esi
 	movl	bitstream_t_buf(%esi),%esi
+#endif
 	movl	dv_block_t_offset(%ebp),%edi
 	movl	dv_block_t_reorder(%ebp),%ebx
 
@@ -170,7 +195,11 @@ dv_parse_ac_coeffs_pass0:
 	
 	movq    dv_block_t_coeffs(%ebp),%mm1
 	pxor    %mm0,%mm0
+#ifdef __PIC__
+	pand    const_f_0_0_0@GOTOFF(%esi),%mm1
+#else
 	pand    const_f_0_0_0,%mm1
+#endif
 	movq    %mm1,dv_block_t_coeffs(%ebp)
 	movq    %mm0,(dv_block_t_coeffs + 8)(%ebp)
 	movq    %mm0,(dv_block_t_coeffs + 16)(%ebp)
@@ -191,9 +220,17 @@ dv_parse_ac_coeffs_pass0:
 readloop:
 	movl	%edi,%ecx
 	shrl	$3,%ecx
+#ifdef __PIC__
+	movl    ARGn(0),%eax
+	addl    bitstream_t_buf(%eax),%ecx
+	movzbl  (%ecx),%eax
+	movzbl  1(%ecx),%edx
+	movzbl  2(%ecx),%ecx
+#else
 	movzbl  (%esi,%ecx,1),%eax
 	movzbl  1(%esi,%ecx,1),%edx
 	movzbl  2(%esi,%ecx,1),%ecx
+#endif
 	shll	$16,%eax
 	shll	$8,%edx
 	orl	%ecx,%eax
@@ -217,7 +254,11 @@ readloop:
 
 	/* Attempt to use the shortcut first.  If it hits, then
 	   this vlc term has been decoded. */
+#ifdef __PIC__
+	movl	dv_vlc_class1_shortcut@GOTOFF(%esi,%ecx,4),%edx
+#else
 	movl	dv_vlc_class1_shortcut(,%ecx,4),%edx
+#endif
 	test	$0x80,%edx
 	je	done_decode
 
@@ -228,12 +269,19 @@ readloop:
 	movl	%ebx,dv_block_t_reorder(%ebp)
 
 	/* %eax is bits */
-	
+#ifdef __PIC__
+	movsbl dv_vlc_class_lookup5@GOTOFF(%esi,%ecx),%ecx
+
+	movl  dv_vlc_index_mask@GOTOFF(%esi,%ecx,4),%ebx
+	movl  dv_vlc_lookups@GOTOFF(%esi,%ecx,4),%edx
+	movl  dv_vlc_index_rshift@GOTOFF(%esi,%ecx,4),%ecx
+#else
 	movsbl dv_vlc_class_lookup5(%ecx),%ecx
 
 	movl  dv_vlc_index_mask(,%ecx,4),%ebx
 	movl  dv_vlc_lookups(,%ecx,4),%edx
 	movl  dv_vlc_index_rshift(,%ecx,4),%ecx
+#endif
 	andl  %eax,%ebx
 	sarl  %cl,%ebx
 
@@ -256,7 +304,11 @@ readloop:
 	movl  %edx,%ecx
 	sarl  $8,%ecx
 	andl  $0xff,%ecx
+#ifdef __PIC__
+	movl  sign_mask@GOTOFF(%esi,%ecx,4),%ecx
+#else
 	movl  sign_mask(,%ecx,4),%ecx
+#endif
 	andl  %ecx,%eax
 	negl  %eax
 	sarl  $31,%eax
@@ -326,10 +378,16 @@ alldone:
 
 slowpath:
 	/* slow path:	 use dv_decode_vlc */;
+#ifdef __PIC__
+	pushl	%esi
+	leal	vlc@GOTOFF(%esi),%esi
+	xchgl	%esi,(%esp)	/* last parameter is &vlc */
+#else
 	pushl	$vlc		/* last parameter is &vlc */
+#endif
 	pushl	%edx		/* bits_left */
 	pushl	%eax		/* bits */
-	call	dv_decode_vlc
+	call	asm_dv_decode_vlc
 	addl	$12,%esp
 	test	$0x80,%edx	/* If (vlc.run < 0) break */
 	jne	escape
@@ -359,6 +417,8 @@ show16:
 	pushl	%esi
 	pushl	%ebp
 
+	LOAD_PIC_REG(si)
+
 #define ARGn(N)  (20+(4*(N)))(%esp)
 
 	movl	ARGn(1),%eax			/* quality */
@@ -373,7 +434,11 @@ dv_parse_video_segment:
 	jz	its_mono
 	movl	$6,%ebx
 its_mono:
+#ifdef __PIC__
+	movl	%ebx,n_blocks@GOTOFF(%esi)
+#else
 	movl	%ebx,n_blocks
+#endif
 	
 	/*
 	 *	ebx	seg/b
@@ -384,15 +449,22 @@ its_mono:
 	 *	ebp	bl
 	 */
 	movl	ARGn(0),%ebx
+#ifndef __PIC__
 	movl	dv_videosegment_t_bs(%ebx),%esi
 	movl	bitstream_t_buf(%esi),%esi
+#endif
 	leal	dv_videosegment_t_mb(%ebx),%edi
 
 	movl	$0,%eax
 	movl	$0,%ecx
 macloop:
+#ifdef __PIC__
+	movl	%eax,m@GOTOFF(%esi)
+	movl	%ecx,mb_start@GOTOFF(%esi)
+#else
 	movl	%eax,m
 	movl	%ecx,mb_start
+#endif
 
 	movl	ARGn(0),%ebx
 	
@@ -400,7 +472,13 @@ macloop:
 	/* mb->qno = bitstream_get(bs,4); */
 	movl	%ecx,%edx
 	shr	$3,%edx
+#ifdef __PIC__
+	movl	dv_videosegment_t_bs(%ebx),%ecx
+	movl	bitstream_t_buf(%ecx),%ecx
+	movzbl	3(%ecx,%edx,1),%edx
+#else
 	movzbl	3(%esi,%edx,1),%edx
+#endif
 	andl	$0xf,%edx
 	movl	%edx,dv_macroblock_t_qno(%edi)
 
@@ -411,7 +489,11 @@ macloop:
 	movl	%edx,dv_macroblock_t_eob_count(%edi)
 
 	/* mb->i = (seg->i + dv_super_map_vertical[m]) % (seg->isPAL?12:10); */
+#ifdef __PIC__
+	movl	dv_super_map_vertical@GOTOFF(%esi,%eax,4),%edx
+#else
 	movl	dv_super_map_vertical(,%eax,4),%edx
+#endif
 	movl	dv_videosegment_t_i(%ebx),%ecx
 	addl	%ecx,%edx
 
@@ -422,11 +504,20 @@ skarly:	
 	andl	$1,%ecx
 	shll	$5,%ecx		/* ecx = (isPAL ? 32 : 0) */
 
+#ifdef __PIC__
+	leal	mod_10@GOTOFF(%esi),%edx
+	movzbl	(%edx,%ecx,1),%edx	/* uses mod_12 for PAL */
+#else
 	movzbl	mod_10(%edx,%ecx,1),%edx	/* uses mod_12 for PAL */
+#endif
 	movl	%edx,dv_macroblock_t_i(%edi)
 
 	/*  mb->j = dv_super_map_horizontal[m]; */	
+#ifdef __PIC__
+	movl	dv_super_map_horizontal@GOTOFF(%esi,%eax,4),%edx
+#else
 	movl	dv_super_map_horizontal(,%eax,4),%edx
+#endif
 	movl	%edx,dv_macroblock_t_j(%edi)
 
 	/* mb->k = seg->k; */
@@ -445,12 +536,28 @@ blkloop:
 	        +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
 	*/
 	/* dc = bitstream_get(bs,9); */
+#ifdef __PIC__
+	movl	mb_start@GOTOFF(%esi),%ecx
+#else
 	movl	mb_start,%ecx
+#endif
 	shr	$3,%ecx
+#ifdef __PIC__
+	movzbl	blk_start@GOTOFF(%esi,%ebx),%edx
+#else
 	movzbl	blk_start(%ebx),%edx
+#endif
 	addl	%ecx,%edx
+#ifdef __PIC__
+	movl	ARGn(0),%ecx
+	movl	dv_videosegment_t_bs(%ecx),%ecx
+	movl	bitstream_t_buf(%ecx),%ecx
+	movzbl	(%ecx,%edx,1),%eax	/* hi byte */
+	movzbl	1(%ecx,%edx,1),%ecx	/* lo byte */
+#else
 	movzbl	(%esi,%edx,1),%eax	/* hi byte */
 	movzbl	1(%esi,%edx,1),%ecx	/* lo byte */
+#endif
 	shll	$8,%eax
 	orl	%ecx,%eax
 
@@ -477,7 +584,11 @@ blkloop:
 
 	/* bl->reorder = &dv_reorder[bl->dct_mode][1]; */
 	shll	$6,%eax
+#ifdef __PIC__
+	leal	dv_reorder@GOTOFF+1(%esi,%eax),%eax
+#else
 	addl	$(dv_reorder+1),%eax
+#endif
 	movl	%eax,dv_block_t_reorder(%ebp)
 
 	/* bl->reorder_sentinel = bl->reorder + 63; */
@@ -485,13 +596,22 @@ blkloop:
 	movl	%eax,dv_block_t_reorder_sentinel(%ebp)
 
 	/* bl->offset= mb_start + dv_parse_bit_start[b]; */
+#ifdef __PIC__
+	movl	mb_start@GOTOFF(%esi),%ecx
+	movl	dv_parse_bit_start@GOTOFF(%esi,%ebx,4),%eax
+#else
 	movl	mb_start,%ecx
 	movl	dv_parse_bit_start(,%ebx,4),%eax
+#endif
 	addl	%ecx,%eax
 	movl	%eax,dv_block_t_offset(%ebp)
 
 	/* bl->end= mb_start + dv_parse_bit_end[b]; */
+#ifdef __PIC__
+	movl	dv_parse_bit_end@GOTOFF(%esi,%ebx,4),%eax
+#else
 	movl	dv_parse_bit_end(,%ebx,4),%eax
+#endif
 	addl	%ecx,%eax
 	movl	%eax,dv_block_t_end(%ebp)
 
@@ -503,7 +623,11 @@ blkloop:
 	/* no AC pass.  Just zero out the remaining coeffs */
 	movq    dv_block_t_coeffs(%ebp),%mm1
 	pxor    %mm0,%mm0
+#ifdef __PIC__
+	pand    const_f_0_0_0@GOTOFF(%esi),%mm1
+#else
 	pand    const_f_0_0_0,%mm1
+#endif
 	movq    %mm1,dv_block_t_coeffs(%ebp)
 	movq    %mm0,(dv_block_t_coeffs + 8)(%ebp)
 	movq    %mm0,(dv_block_t_coeffs + 16)(%ebp)
@@ -528,18 +652,27 @@ do_ac_pass:
 	pushl	%ebp
 	pushl	%edi
 	pushl	%eax
-	call	dv_parse_ac_coeffs_pass0
+	call	asm_dv_parse_ac_coeffs_pass0
 	addl	$12,%esp
 done_ac:
 
+#ifdef __PIC__
+	movl	n_blocks@GOTOFF(%esi),%eax
+#else
 	movl	n_blocks,%eax
+#endif
 	addl	$dv_block_t_size,%ebp
 	incl	%ebx
 	cmpl	%eax,%ebx
 	jnz	blkloop
 
+#ifdef __PIC__
+	movl	m@GOTOFF(%esi),%eax
+	movl	mb_start@GOTOFF(%esi),%ecx
+#else
 	movl	m,%eax
 	movl	mb_start,%ecx
+#endif
 	addl	$(8 * 80),%ecx
 	addl	$dv_macroblock_t_size,%edi
 	incl	%eax
@@ -557,7 +690,7 @@ done_ac:
 
 	andl	$DV_QUALITY_AC_MASK,%eax
 	cmpl	$DV_QUALITY_AC_2,%eax
-	jz	dv_parse_ac_coeffs
+	jz	asm_dv_parse_ac_coeffs
 	movl	$0,%eax
 	ret