~ubuntu-branches/ubuntu/jaunty/xvidcap/jaunty-proposed

« back to all changes in this revision

Viewing changes to ffmpeg/libavcodec/ppc/dsputil_altivec.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc, Andrew Starr-Bochicchio, Lionel Le Folgoc
  • Date: 2008-12-26 00:10:06 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20081226001006-2040ls9680bd1blt
Tags: 1.1.7-0.2ubuntu1
[ Andrew Starr-Bochicchio ]
* Merge from debian-multimedia (LP: #298547), Ubuntu Changes:
 - For ffmpeg-related build-deps, fix versionized dependencies
   as the ubuntu versioning is different than debian-multimedia's.

[ Lionel Le Folgoc ]
* LP: #311412 is fixed since the 1.1.7~rc1-0.1 revision.
* debian/patches/03_ffmpeg.diff: updated to fix FTBFS due to libswscale API
  change (cherry-pick from Gentoo #234383).

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
21
 */
22
22
 
23
 
#include "../dsputil.h"
 
23
#include "dsputil.h"
24
24
 
25
25
#include "gcc_fixes.h"
26
26
 
27
 
#include "dsputil_altivec.h"
28
 
 
29
 
#ifdef CONFIG_DARWIN
30
 
#include <sys/sysctl.h>
31
 
#else /* CONFIG_DARWIN */
32
 
#ifdef __AMIGAOS4__
33
 
#include <exec/exec.h>
34
 
#include <interfaces/exec.h>
35
 
#include <proto/exec.h>
36
 
#else /* __AMIGAOS4__ */
37
 
#include <signal.h>
38
 
#include <setjmp.h>
39
 
 
40
 
static sigjmp_buf jmpbuf;
41
 
static volatile sig_atomic_t canjump = 0;
42
 
 
43
 
static void sigill_handler (int sig)
44
 
{
45
 
    if (!canjump) {
46
 
        signal (sig, SIG_DFL);
47
 
        raise (sig);
48
 
    }
49
 
 
50
 
    canjump = 0;
51
 
    siglongjmp (jmpbuf, 1);
52
 
}
53
 
#endif /* CONFIG_DARWIN */
54
 
#endif /* __AMIGAOS4__ */
 
27
#include "dsputil_ppc.h"
 
28
#include "util_altivec.h"
55
29
 
56
30
int sad16_x2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
57
31
{
58
32
    int i;
59
 
    int s __attribute__((aligned(16)));
60
 
    const_vector unsigned char zero = (const_vector unsigned char)vec_splat_u8(0);
 
33
    DECLARE_ALIGNED_16(int, s);
 
34
    const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0);
61
35
    vector unsigned char *tv;
62
36
    vector unsigned char pix1v, pix2v, pix2iv, avgv, t5;
63
37
    vector unsigned int sad;
103
77
int sad16_y2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
104
78
{
105
79
    int i;
106
 
    int s __attribute__((aligned(16)));
107
 
    const_vector unsigned char zero = (const_vector unsigned char)vec_splat_u8(0);
 
80
    DECLARE_ALIGNED_16(int, s);
 
81
    const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0);
108
82
    vector unsigned char *tv;
109
83
    vector unsigned char pix1v, pix2v, pix3v, avgv, t5;
110
84
    vector unsigned int sad;
163
137
int sad16_xy2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
164
138
{
165
139
    int i;
166
 
    int s __attribute__((aligned(16)));
 
140
    DECLARE_ALIGNED_16(int, s);
167
141
    uint8_t *pix3 = pix2 + line_size;
168
 
    const_vector unsigned char zero = (const_vector unsigned char)vec_splat_u8(0);
169
 
    const_vector unsigned short two = (const_vector unsigned short)vec_splat_u16(2);
 
142
    const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0);
 
143
    const vector unsigned short two = (const vector unsigned short)vec_splat_u16(2);
170
144
    vector unsigned char *tv, avgv, t5;
171
145
    vector unsigned char pix1v, pix2v, pix3v, pix2iv, pix3iv;
172
146
    vector unsigned short pix2lv, pix2hv, pix2ilv, pix2ihv;
218
192
        pix3iv = vec_perm(tv[0], tv[1], vec_lvsl(0, &pix3[1]));
219
193
 
220
194
        /*
221
 
          Note that Altivec does have vec_avg, but this works on vector pairs
 
195
          Note that AltiVec does have vec_avg, but this works on vector pairs
222
196
          and rounds up. We could do avg(avg(a,b),avg(c,d)), but the rounding
223
197
          would mean that, for example, avg(3,0,0,1) = 2, when it should be 1.
224
198
          Instead, we have to split the pixel vectors into vectors of shorts,
264
238
int sad16_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
265
239
{
266
240
    int i;
267
 
    int s __attribute__((aligned(16)));
268
 
    const_vector unsigned int zero = (const_vector unsigned int)vec_splat_u32(0);
 
241
    DECLARE_ALIGNED_16(int, s);
 
242
    const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
269
243
    vector unsigned char perm1, perm2, *pix1v, *pix2v;
270
244
    vector unsigned char t1, t2, t3,t4, t5;
271
245
    vector unsigned int sad;
306
280
int sad8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
307
281
{
308
282
    int i;
309
 
    int s __attribute__((aligned(16)));
310
 
    const_vector unsigned int zero = (const_vector unsigned int)vec_splat_u32(0);
 
283
    DECLARE_ALIGNED_16(int, s);
 
284
    const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
311
285
    vector unsigned char perm1, perm2, permclear, *pix1v, *pix2v;
312
286
    vector unsigned char t1, t2, t3,t4, t5;
313
287
    vector unsigned int sad;
351
325
int pix_norm1_altivec(uint8_t *pix, int line_size)
352
326
{
353
327
    int i;
354
 
    int s __attribute__((aligned(16)));
355
 
    const_vector unsigned int zero = (const_vector unsigned int)vec_splat_u32(0);
 
328
    DECLARE_ALIGNED_16(int, s);
 
329
    const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
356
330
    vector unsigned char *tv;
357
331
    vector unsigned char pixv;
358
332
    vector unsigned int sv;
387
361
int sse8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
388
362
{
389
363
    int i;
390
 
    int s __attribute__((aligned(16)));
391
 
    const_vector unsigned int zero = (const_vector unsigned int)vec_splat_u32(0);
 
364
    DECLARE_ALIGNED_16(int, s);
 
365
    const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
392
366
    vector unsigned char perm1, perm2, permclear, *pix1v, *pix2v;
393
367
    vector unsigned char t1, t2, t3,t4, t5;
394
368
    vector unsigned int sum;
443
417
int sse16_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
444
418
{
445
419
    int i;
446
 
    int s __attribute__((aligned(16)));
447
 
    const_vector unsigned int zero = (const_vector unsigned int)vec_splat_u32(0);
 
420
    DECLARE_ALIGNED_16(int, s);
 
421
    const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
448
422
    vector unsigned char perm1, perm2, *pix1v, *pix2v;
449
423
    vector unsigned char t1, t2, t3,t4, t5;
450
424
    vector unsigned int sum;
488
462
 
489
463
int pix_sum_altivec(uint8_t * pix, int line_size)
490
464
{
491
 
    const_vector unsigned int zero = (const_vector unsigned int)vec_splat_u32(0);
 
465
    const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
492
466
    vector unsigned char perm, *pixv;
493
467
    vector unsigned char t1;
494
468
    vector unsigned int sad;
495
469
    vector signed int sumdiffs;
496
470
 
497
471
    int i;
498
 
    int s __attribute__((aligned(16)));
 
472
    DECLARE_ALIGNED_16(int, s);
499
473
 
500
474
    sad = (vector unsigned int)vec_splat_u32(0);
501
475
 
523
497
{
524
498
    int i;
525
499
    vector unsigned char perm, bytes, *pixv;
526
 
    const_vector unsigned char zero = (const_vector unsigned char)vec_splat_u8(0);
 
500
    const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0);
527
501
    vector signed short shorts;
528
502
 
529
503
    for(i=0;i<8;i++)
550
524
{
551
525
    int i;
552
526
    vector unsigned char perm, bytes, *pixv;
553
 
    const_vector unsigned char zero = (const_vector unsigned char)vec_splat_u8(0);
 
527
    const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0);
554
528
    vector signed short shorts1, shorts2;
555
529
 
556
530
    for(i=0;i<4;i++)
769
743
     blockv, temp1, temp2;
770
744
   register vector unsigned short
771
745
     pixelssum1, pixelssum2, temp3;
772
 
   register const_vector unsigned char vczero = (const_vector unsigned char)vec_splat_u8(0);
773
 
   register const_vector unsigned short vctwo = (const_vector unsigned short)vec_splat_u16(2);
 
746
   register const vector unsigned char vczero = (const vector unsigned char)vec_splat_u8(0);
 
747
   register const vector unsigned short vctwo = (const vector unsigned short)vec_splat_u16(2);
774
748
 
775
749
   temp1 = vec_ld(0, pixels);
776
750
   temp2 = vec_ld(16, pixels);
845
819
     blockv, temp1, temp2;
846
820
   register vector unsigned short
847
821
     pixelssum1, pixelssum2, temp3;
848
 
   register const_vector unsigned char vczero = (const_vector unsigned char)vec_splat_u8(0);
849
 
   register const_vector unsigned short vcone = (const_vector unsigned short)vec_splat_u16(1);
850
 
   register const_vector unsigned short vctwo = (const_vector unsigned short)vec_splat_u16(2);
 
822
   register const vector unsigned char vczero = (const vector unsigned char)vec_splat_u8(0);
 
823
   register const vector unsigned short vcone = (const vector unsigned short)vec_splat_u16(1);
 
824
   register const vector unsigned short vctwo = (const vector unsigned short)vec_splat_u16(2);
851
825
 
852
826
   temp1 = vec_ld(0, pixels);
853
827
   temp2 = vec_ld(16, pixels);
922
896
   register vector unsigned short
923
897
     pixelssum1, pixelssum2, temp3,
924
898
     pixelssum3, pixelssum4, temp4;
925
 
   register const_vector unsigned char vczero = (const_vector unsigned char)vec_splat_u8(0);
926
 
   register const_vector unsigned short vctwo = (const_vector unsigned short)vec_splat_u16(2);
 
899
   register const vector unsigned char vczero = (const vector unsigned char)vec_splat_u8(0);
 
900
   register const vector unsigned short vctwo = (const vector unsigned short)vec_splat_u16(2);
927
901
 
928
902
POWERPC_PERF_START_COUNT(altivec_put_pixels16_xy2_num, 1);
929
903
 
1004
978
   register vector unsigned short
1005
979
     pixelssum1, pixelssum2, temp3,
1006
980
     pixelssum3, pixelssum4, temp4;
1007
 
   register const_vector unsigned char vczero = (const_vector unsigned char)vec_splat_u8(0);
1008
 
   register const_vector unsigned short vcone = (const_vector unsigned short)vec_splat_u16(1);
1009
 
   register const_vector unsigned short vctwo = (const_vector unsigned short)vec_splat_u16(2);
 
981
   register const vector unsigned char vczero = (const vector unsigned char)vec_splat_u8(0);
 
982
   register const vector unsigned short vcone = (const vector unsigned short)vec_splat_u16(1);
 
983
   register const vector unsigned short vctwo = (const vector unsigned short)vec_splat_u16(2);
1010
984
 
1011
985
POWERPC_PERF_START_COUNT(altivec_put_no_rnd_pixels16_xy2_num, 1);
1012
986
 
1078
1052
int hadamard8_diff8x8_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){
1079
1053
POWERPC_PERF_DECLARE(altivec_hadamard8_diff8x8_num, 1);
1080
1054
    int sum;
1081
 
    register const_vector unsigned char vzero =
1082
 
                            (const_vector unsigned char)vec_splat_u8(0);
 
1055
    register const vector unsigned char vzero =
 
1056
                            (const vector unsigned char)vec_splat_u8(0);
1083
1057
    register vector signed short temp0, temp1, temp2, temp3, temp4,
1084
1058
                                 temp5, temp6, temp7;
1085
1059
POWERPC_PERF_START_COUNT(altivec_hadamard8_diff8x8_num, 1);
1086
1060
  {
1087
 
    register const_vector signed short vprod1 =(const_vector signed short)
 
1061
    register const vector signed short vprod1 =(const vector signed short)
1088
1062
                                        AVV( 1,-1, 1,-1, 1,-1, 1,-1);
1089
 
    register const_vector signed short vprod2 =(const_vector signed short)
 
1063
    register const vector signed short vprod2 =(const vector signed short)
1090
1064
                                        AVV( 1, 1,-1,-1, 1, 1,-1,-1);
1091
 
    register const_vector signed short vprod3 =(const_vector signed short)
 
1065
    register const vector signed short vprod3 =(const vector signed short)
1092
1066
                                        AVV( 1, 1, 1, 1,-1,-1,-1,-1);
1093
 
    register const_vector unsigned char perm1 = (const_vector unsigned char)
 
1067
    register const vector unsigned char perm1 = (const vector unsigned char)
1094
1068
      AVV(0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05,
1095
1069
          0x0A, 0x0B, 0x08, 0x09, 0x0E, 0x0F, 0x0C, 0x0D);
1096
 
    register const_vector unsigned char perm2 = (const_vector unsigned char)
 
1070
    register const vector unsigned char perm2 = (const vector unsigned char)
1097
1071
      AVV(0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03,
1098
1072
          0x0C, 0x0D, 0x0E, 0x0F, 0x08, 0x09, 0x0A, 0x0B);
1099
 
    register const_vector unsigned char perm3 = (const_vector unsigned char)
 
1073
    register const vector unsigned char perm3 = (const vector unsigned char)
1100
1074
      AVV(0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
1101
1075
          0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07);
1102
1076
 
1120
1094
      dstV =                                                            \
1121
1095
        (vector signed short)vec_mergeh((vector signed char)vzero,      \
1122
1096
        (vector signed char)dstO);                                      \
1123
 
      /* substractions inside the first butterfly */                    \
 
1097
      /* subtractions inside the first butterfly */                     \
1124
1098
      but0 = vec_sub(srcV, dstV);                                       \
1125
1099
      op1 = vec_perm(but0, but0, perm1);                                \
1126
1100
      but1 = vec_mladd(but0, vprod1, op1);                              \
1201
1175
  schedule for the 7450, and its code isn't much faster than
1202
1176
  gcc-3.3 on the 7450 (but uses 25% less instructions...)
1203
1177
 
1204
 
  On the 970, the hand-made RA is still a win (arount 690
 
1178
  On the 970, the hand-made RA is still a win (around 690
1205
1179
  vs. around 780), but xlc goes to around 660 on the
1206
1180
  regular C code...
1207
1181
*/
1226
1200
        temp5S REG_v(v13),
1227
1201
        temp6S REG_v(v14),
1228
1202
        temp7S REG_v(v15);
1229
 
    register const_vector unsigned char vzero REG_v(v31)=
1230
 
        (const_vector unsigned char)vec_splat_u8(0);
 
1203
    register const vector unsigned char vzero REG_v(v31)=
 
1204
        (const vector unsigned char)vec_splat_u8(0);
1231
1205
  {
1232
 
    register const_vector signed short vprod1 REG_v(v16)=
1233
 
        (const_vector signed short)AVV( 1,-1, 1,-1, 1,-1, 1,-1);
1234
 
    register const_vector signed short vprod2 REG_v(v17)=
1235
 
        (const_vector signed short)AVV( 1, 1,-1,-1, 1, 1,-1,-1);
1236
 
    register const_vector signed short vprod3 REG_v(v18)=
1237
 
        (const_vector signed short)AVV( 1, 1, 1, 1,-1,-1,-1,-1);
1238
 
    register const_vector unsigned char perm1 REG_v(v19)=
1239
 
        (const_vector unsigned char)
 
1206
    register const vector signed short vprod1 REG_v(v16)=
 
1207
        (const vector signed short)AVV( 1,-1, 1,-1, 1,-1, 1,-1);
 
1208
    register const vector signed short vprod2 REG_v(v17)=
 
1209
        (const vector signed short)AVV( 1, 1,-1,-1, 1, 1,-1,-1);
 
1210
    register const vector signed short vprod3 REG_v(v18)=
 
1211
        (const vector signed short)AVV( 1, 1, 1, 1,-1,-1,-1,-1);
 
1212
    register const vector unsigned char perm1 REG_v(v19)=
 
1213
        (const vector unsigned char)
1240
1214
        AVV(0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05,
1241
1215
            0x0A, 0x0B, 0x08, 0x09, 0x0E, 0x0F, 0x0C, 0x0D);
1242
 
    register const_vector unsigned char perm2 REG_v(v20)=
1243
 
        (const_vector unsigned char)
 
1216
    register const vector unsigned char perm2 REG_v(v20)=
 
1217
        (const vector unsigned char)
1244
1218
        AVV(0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03,
1245
1219
            0x0C, 0x0D, 0x0E, 0x0F, 0x08, 0x09, 0x0A, 0x0B);
1246
 
    register const_vector unsigned char perm3 REG_v(v21)=
1247
 
        (const_vector unsigned char)
 
1220
    register const vector unsigned char perm3 REG_v(v21)=
 
1221
        (const vector unsigned char)
1248
1222
        AVV(0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
1249
1223
            0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07);
1250
1224
 
1293
1267
      dstW =                                                            \
1294
1268
        (vector signed short)vec_mergel((vector signed char)vzero,      \
1295
1269
        (vector signed char)dstO);                                      \
1296
 
      /* substractions inside the first butterfly */                    \
 
1270
      /* subtractions inside the first butterfly */                     \
1297
1271
      but0 = vec_sub(srcV, dstV);                                       \
1298
1272
      but0S = vec_sub(srcW, dstW);                                      \
1299
1273
      op1 = vec_perm(but0, but0, perm1);                                \
1419
1393
    return score;
1420
1394
}
1421
1395
 
1422
 
int has_altivec(void)
1423
 
{
1424
 
#ifdef __AMIGAOS4__
1425
 
    ULONG result = 0;
1426
 
    extern struct ExecIFace *IExec;
1427
 
 
1428
 
    IExec->GetCPUInfoTags(GCIT_VectorUnit, &result, TAG_DONE);
1429
 
    if (result == VECTORTYPE_ALTIVEC) return 1;
1430
 
    return 0;
1431
 
#else /* __AMIGAOS4__ */
1432
 
 
1433
 
#ifdef CONFIG_DARWIN
1434
 
    int sels[2] = {CTL_HW, HW_VECTORUNIT};
1435
 
    int has_vu = 0;
1436
 
    size_t len = sizeof(has_vu);
1437
 
    int err;
1438
 
 
1439
 
    err = sysctl(sels, 2, &has_vu, &len, NULL, 0);
1440
 
 
1441
 
    if (err == 0) return (has_vu != 0);
1442
 
#else /* CONFIG_DARWIN */
1443
 
/* no Darwin, do it the brute-force way */
1444
 
/* this is borrowed from the libmpeg2 library */
1445
 
    {
1446
 
      signal (SIGILL, sigill_handler);
1447
 
      if (sigsetjmp (jmpbuf, 1)) {
1448
 
        signal (SIGILL, SIG_DFL);
1449
 
      } else {
1450
 
        canjump = 1;
1451
 
 
1452
 
        asm volatile ("mtspr 256, %0\n\t"
1453
 
                      "vand %%v0, %%v0, %%v0"
1454
 
                      :
1455
 
                      : "r" (-1));
1456
 
 
1457
 
        signal (SIGILL, SIG_DFL);
1458
 
        return 1;
1459
 
      }
1460
 
    }
1461
 
#endif /* CONFIG_DARWIN */
1462
 
    return 0;
1463
 
#endif /* __AMIGAOS4__ */
1464
 
}
1465
 
 
1466
1396
static void vorbis_inverse_coupling_altivec(float *mag, float *ang,
1467
1397
                                            int blocksize)
1468
1398
{
1495
1425
    register vector unsigned char blockv, temp1, temp2, blocktemp;
1496
1426
    register vector unsigned short pixelssum1, pixelssum2, temp3;
1497
1427
 
1498
 
    register const_vector unsigned char vczero = (const_vector unsigned char)
 
1428
    register const vector unsigned char vczero = (const vector unsigned char)
1499
1429
                                        vec_splat_u8(0);
1500
 
    register const_vector unsigned short vctwo = (const_vector unsigned short)
 
1430
    register const vector unsigned short vctwo = (const vector unsigned short)
1501
1431
                                        vec_splat_u16(2);
1502
1432
 
1503
1433
    temp1 = vec_ld(0, pixels);
1583
1513
 
1584
1514
    c->hadamard8_diff[0] = hadamard8_diff16_altivec;
1585
1515
    c->hadamard8_diff[1] = hadamard8_diff8x8_altivec;
1586
 
#ifdef CONFIG_VORBIS_DECODER
1587
 
    c->vorbis_inverse_coupling = vorbis_inverse_coupling_altivec;
1588
 
#endif
 
1516
    if (ENABLE_VORBIS_DECODER)
 
1517
        c->vorbis_inverse_coupling = vorbis_inverse_coupling_altivec;
1589
1518
}