summaryrefslogtreecommitdiff
path: root/src/libffmpeg/libavcodec/ppc
diff options
context:
space:
mode:
authorMiguel Freitas <miguelfreitas@users.sourceforge.net>2004-04-25 18:57:04 +0000
committerMiguel Freitas <miguelfreitas@users.sourceforge.net>2004-04-25 18:57:04 +0000
commita2a44876712f079610f0396fb9a682ea47e05b6e (patch)
tree1f3e328dfe6a5f9fa7c79e7a23bf6310be2827fd /src/libffmpeg/libavcodec/ppc
parentacb7dc0f256afc24e875a168da989ef25d86b7b7 (diff)
downloadxine-lib-a2a44876712f079610f0396fb9a682ea47e05b6e.tar.gz
xine-lib-a2a44876712f079610f0396fb9a682ea47e05b6e.tar.bz2
ffmpeg sync
CVS patchset: 6437 CVS date: 2004/04/25 18:57:04
Diffstat (limited to 'src/libffmpeg/libavcodec/ppc')
-rw-r--r--src/libffmpeg/libavcodec/ppc/Makefile.am1
-rw-r--r--src/libffmpeg/libavcodec/ppc/dsputil_altivec.c353
-rw-r--r--src/libffmpeg/libavcodec/ppc/dsputil_altivec.h3
-rw-r--r--src/libffmpeg/libavcodec/ppc/dsputil_ppc.c8
-rw-r--r--src/libffmpeg/libavcodec/ppc/dsputil_ppc.h37
-rw-r--r--src/libffmpeg/libavcodec/ppc/fdct_altivec.c498
-rw-r--r--src/libffmpeg/libavcodec/ppc/mpegvideo_altivec.c3
-rw-r--r--src/libffmpeg/libavcodec/ppc/mpegvideo_ppc.c152
8 files changed, 973 insertions, 82 deletions
diff --git a/src/libffmpeg/libavcodec/ppc/Makefile.am b/src/libffmpeg/libavcodec/ppc/Makefile.am
index fbd734c29..50b9d802e 100644
--- a/src/libffmpeg/libavcodec/ppc/Makefile.am
+++ b/src/libffmpeg/libavcodec/ppc/Makefile.am
@@ -11,6 +11,7 @@ noinst_LTLIBRARIES = libavcodec_ppc.la
libavcodec_ppc_src = dsputil_altivec.c \
dsputil_ppc.c \
+ fdct_altivec.c \
fft_altivec.c \
idct_altivec.c \
gmc_altivec.c \
diff --git a/src/libffmpeg/libavcodec/ppc/dsputil_altivec.c b/src/libffmpeg/libavcodec/ppc/dsputil_altivec.c
index 633cae68b..1bc6fb009 100644
--- a/src/libffmpeg/libavcodec/ppc/dsputil_altivec.c
+++ b/src/libffmpeg/libavcodec/ppc/dsputil_altivec.c
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2002 Brian Foley
* Copyright (c) 2002 Dieter Shirley
- * Copyright (c) 2003 Romain Dolbeau <romain@dolbeau.org>
+ * Copyright (c) 2003-2004 Romain Dolbeau <romain@dolbeau.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1302,6 +1302,357 @@ POWERPC_PERF_STOP_COUNT(altivec_put_no_rnd_pixels16_xy2_num, 1);
#endif /* ALTIVEC_USE_REFERENCE_C_CODE */
}
+int hadamard8_diff8x8_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){
+POWERPC_PERF_DECLARE(altivec_hadamard8_diff8x8_num, 1);
+ int sum;
+POWERPC_PERF_START_COUNT(altivec_hadamard8_diff8x8_num, 1);
+ register const_vector unsigned char vzero = (const_vector unsigned char)vec_splat_u8(0);
+ register vector signed short temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7;
+#ifdef CONFIG_DARWIN
+ {
+ register const_vector signed short vprod1 = (const_vector signed short)( 1,-1, 1,-1, 1,-1, 1,-1);
+ register const_vector signed short vprod2 = (const_vector signed short)( 1, 1,-1,-1, 1, 1,-1,-1);
+ register const_vector signed short vprod3 = (const_vector signed short)( 1, 1, 1, 1,-1,-1,-1,-1);
+ register const_vector unsigned char perm1 = (const_vector unsigned char)
+ (0x02, 0x03, 0x00, 0x01,
+ 0x06, 0x07, 0x04, 0x05,
+ 0x0A, 0x0B, 0x08, 0x09,
+ 0x0E, 0x0F, 0x0C, 0x0D);
+ register const_vector unsigned char perm2 = (const_vector unsigned char)
+ (0x04, 0x05, 0x06, 0x07,
+ 0x00, 0x01, 0x02, 0x03,
+ 0x0C, 0x0D, 0x0E, 0x0F,
+ 0x08, 0x09, 0x0A, 0x0B);
+ register const_vector unsigned char perm3 = (const_vector unsigned char)
+ (0x08, 0x09, 0x0A, 0x0B,
+ 0x0C, 0x0D, 0x0E, 0x0F,
+ 0x00, 0x01, 0x02, 0x03,
+ 0x04, 0x05, 0x06, 0x07);
+#else
+ register const_vector signed short vprod1 = (const_vector signed short){ 1,-1, 1,-1, 1,-1, 1,-1};
+ register const_vector signed short vprod2 = (const_vector signed short){ 1, 1,-1,-1, 1, 1,-1,-1};
+ register const_vector signed short vprod3 = (const_vector signed short){ 1, 1, 1, 1,-1,-1,-1,-1};
+ register const_vector unsigned char perm1 = (const_vector unsigned char)
+ {0x02, 0x03, 0x00, 0x01,
+ 0x06, 0x07, 0x04, 0x05,
+ 0x0A, 0x0B, 0x08, 0x09,
+ 0x0E, 0x0F, 0x0C, 0x0D};
+ register const_vector unsigned char perm2 = (const_vector unsigned char)
+ {0x04, 0x05, 0x06, 0x07,
+ 0x00, 0x01, 0x02, 0x03,
+ 0x0C, 0x0D, 0x0E, 0x0F,
+ 0x08, 0x09, 0x0A, 0x0B};
+ register const_vector unsigned char perm3 = (const_vector unsigned char)
+ {0x08, 0x09, 0x0A, 0x0B,
+ 0x0C, 0x0D, 0x0E, 0x0F,
+ 0x00, 0x01, 0x02, 0x03,
+ 0x04, 0x05, 0x06, 0x07};
+#endif
+
+#define ONEITERBUTTERFLY(i, res) \
+ { \
+ register vector unsigned char src1, src2, srcO; \
+ register vector unsigned char dst1, dst2, dstO; \
+ src1 = vec_ld(stride * i, src); \
+ if ((((stride * i) + (unsigned long)src) & 0x0000000F) > 8) \
+ src2 = vec_ld((stride * i) + 16, src); \
+ srcO = vec_perm(src1, src2, vec_lvsl(stride * i, src)); \
+ dst1 = vec_ld(stride * i, dst); \
+ if ((((stride * i) + (unsigned long)dst) & 0x0000000F) > 8) \
+ dst2 = vec_ld((stride * i) + 16, dst); \
+ dstO = vec_perm(dst1, dst2, vec_lvsl(stride * i, dst)); \
+ /* promote the unsigned chars to signed shorts */ \
+ /* we're in the 8x8 function, we only care for the first 8 */ \
+ register vector signed short srcV = \
+ (vector signed short)vec_mergeh((vector signed char)vzero, (vector signed char)srcO); \
+ register vector signed short dstV = \
+ (vector signed short)vec_mergeh((vector signed char)vzero, (vector signed char)dstO); \
+ /* substractions inside the first butterfly */ \
+ register vector signed short but0 = vec_sub(srcV, dstV); \
+ register vector signed short op1 = vec_perm(but0, but0, perm1); \
+ register vector signed short but1 = vec_mladd(but0, vprod1, op1); \
+ register vector signed short op2 = vec_perm(but1, but1, perm2); \
+ register vector signed short but2 = vec_mladd(but1, vprod2, op2); \
+ register vector signed short op3 = vec_perm(but2, but2, perm3); \
+ res = vec_mladd(but2, vprod3, op3); \
+ }
+ ONEITERBUTTERFLY(0, temp0);
+ ONEITERBUTTERFLY(1, temp1);
+ ONEITERBUTTERFLY(2, temp2);
+ ONEITERBUTTERFLY(3, temp3);
+ ONEITERBUTTERFLY(4, temp4);
+ ONEITERBUTTERFLY(5, temp5);
+ ONEITERBUTTERFLY(6, temp6);
+ ONEITERBUTTERFLY(7, temp7);
+ }
+#undef ONEITERBUTTERFLY
+ {
+ register vector signed int vsum;
+ register vector signed short line0 = vec_add(temp0, temp1);
+ register vector signed short line1 = vec_sub(temp0, temp1);
+ register vector signed short line2 = vec_add(temp2, temp3);
+ register vector signed short line3 = vec_sub(temp2, temp3);
+ register vector signed short line4 = vec_add(temp4, temp5);
+ register vector signed short line5 = vec_sub(temp4, temp5);
+ register vector signed short line6 = vec_add(temp6, temp7);
+ register vector signed short line7 = vec_sub(temp6, temp7);
+
+ register vector signed short line0B = vec_add(line0, line2);
+ register vector signed short line2B = vec_sub(line0, line2);
+ register vector signed short line1B = vec_add(line1, line3);
+ register vector signed short line3B = vec_sub(line1, line3);
+ register vector signed short line4B = vec_add(line4, line6);
+ register vector signed short line6B = vec_sub(line4, line6);
+ register vector signed short line5B = vec_add(line5, line7);
+ register vector signed short line7B = vec_sub(line5, line7);
+
+ register vector signed short line0C = vec_add(line0B, line4B);
+ register vector signed short line4C = vec_sub(line0B, line4B);
+ register vector signed short line1C = vec_add(line1B, line5B);
+ register vector signed short line5C = vec_sub(line1B, line5B);
+ register vector signed short line2C = vec_add(line2B, line6B);
+ register vector signed short line6C = vec_sub(line2B, line6B);
+ register vector signed short line3C = vec_add(line3B, line7B);
+ register vector signed short line7C = vec_sub(line3B, line7B);
+
+ vsum = vec_sum4s(vec_abs(line0C), vec_splat_s32(0));
+ vsum = vec_sum4s(vec_abs(line1C), vsum);
+ vsum = vec_sum4s(vec_abs(line2C), vsum);
+ vsum = vec_sum4s(vec_abs(line3C), vsum);
+ vsum = vec_sum4s(vec_abs(line4C), vsum);
+ vsum = vec_sum4s(vec_abs(line5C), vsum);
+ vsum = vec_sum4s(vec_abs(line6C), vsum);
+ vsum = vec_sum4s(vec_abs(line7C), vsum);
+ vsum = vec_sums(vsum, (vector signed int)vzero);
+ vsum = vec_splat(vsum, 3);
+ vec_ste(vsum, 0, &sum);
+ }
+POWERPC_PERF_STOP_COUNT(altivec_hadamard8_diff8x8_num, 1);
+ return sum;
+}
+
+/*
+ 16x8 works with 16 elements ; it allows to avoid replicating
+ loads, and give the compiler more rooms for scheduling.
+ It's only used from inside hadamard8_diff16_altivec.
+
+ Unfortunately, it seems gcc-3.3 is a bit dumb, and
+ the compiled code has a LOT of spill code, it seems
+ gcc (unlike xlc) cannot keep everything in registers
+ by itself. The following code include hand-made
+ registers allocation. It's not clean, but on
+ a 7450 the resulting code is much faster (best case
+ fall from 700+ cycles to 550).
+
+ xlc doesn't add spill code, but it doesn't know how to
+ schedule for the 7450, and its code isn't much faster than
+ gcc-3.3 on the 7450 (but uses 25% less instructions...)
+
+ On the 970, the hand-made RA is still a win (arount 690
+ vs. around 780), but xlc goes to around 660 on the
+ regular C code...
+*/
+
+static int hadamard8_diff16x8_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h) {
+ int sum;
+ register vector signed short
+ temp0 asm ("v0"),
+ temp1 asm ("v1"),
+ temp2 asm ("v2"),
+ temp3 asm ("v3"),
+ temp4 asm ("v4"),
+ temp5 asm ("v5"),
+ temp6 asm ("v6"),
+ temp7 asm ("v7");
+ register vector signed short
+ temp0S asm ("v8"),
+ temp1S asm ("v9"),
+ temp2S asm ("v10"),
+ temp3S asm ("v11"),
+ temp4S asm ("v12"),
+ temp5S asm ("v13"),
+ temp6S asm ("v14"),
+ temp7S asm ("v15");
+ register const_vector unsigned char vzero asm ("v31")= (const_vector unsigned char)vec_splat_u8(0);
+ {
+#ifdef CONFIG_DARWIN
+ register const_vector signed short vprod1 asm ("v16")= (const_vector signed short)( 1,-1, 1,-1, 1,-1, 1,-1);
+ register const_vector signed short vprod2 asm ("v17")= (const_vector signed short)( 1, 1,-1,-1, 1, 1,-1,-1);
+ register const_vector signed short vprod3 asm ("v18")= (const_vector signed short)( 1, 1, 1, 1,-1,-1,-1,-1);
+ register const_vector unsigned char perm1 asm ("v19")= (const_vector unsigned char)
+ (0x02, 0x03, 0x00, 0x01,
+ 0x06, 0x07, 0x04, 0x05,
+ 0x0A, 0x0B, 0x08, 0x09,
+ 0x0E, 0x0F, 0x0C, 0x0D);
+ register const_vector unsigned char perm2 asm ("v20")= (const_vector unsigned char)
+ (0x04, 0x05, 0x06, 0x07,
+ 0x00, 0x01, 0x02, 0x03,
+ 0x0C, 0x0D, 0x0E, 0x0F,
+ 0x08, 0x09, 0x0A, 0x0B);
+ register const_vector unsigned char perm3 asm ("v21")= (const_vector unsigned char)
+ (0x08, 0x09, 0x0A, 0x0B,
+ 0x0C, 0x0D, 0x0E, 0x0F,
+ 0x00, 0x01, 0x02, 0x03,
+ 0x04, 0x05, 0x06, 0x07);
+#else
+ register const_vector signed short vprod1 = (const_vector signed short){ 1,-1, 1,-1, 1,-1, 1,-1};
+ register const_vector signed short vprod2 = (const_vector signed short){ 1, 1,-1,-1, 1, 1,-1,-1};
+ register const_vector signed short vprod3 = (const_vector signed short){ 1, 1, 1, 1,-1,-1,-1,-1};
+ register const_vector unsigned char perm1 = (const_vector unsigned char)
+ {0x02, 0x03, 0x00, 0x01,
+ 0x06, 0x07, 0x04, 0x05,
+ 0x0A, 0x0B, 0x08, 0x09,
+ 0x0E, 0x0F, 0x0C, 0x0D};
+ register const_vector unsigned char perm2 = (const_vector unsigned char)
+ {0x04, 0x05, 0x06, 0x07,
+ 0x00, 0x01, 0x02, 0x03,
+ 0x0C, 0x0D, 0x0E, 0x0F,
+ 0x08, 0x09, 0x0A, 0x0B};
+ register const_vector unsigned char perm3 = (const_vector unsigned char)
+ {0x08, 0x09, 0x0A, 0x0B,
+ 0x0C, 0x0D, 0x0E, 0x0F,
+ 0x00, 0x01, 0x02, 0x03,
+ 0x04, 0x05, 0x06, 0x07};
+#endif
+#define ONEITERBUTTERFLY(i, res1, res2) \
+ { \
+ register vector unsigned char src1 asm ("v22"), src2 asm ("v23"); \
+ register vector unsigned char dst1 asm ("v24"), dst2 asm ("v25"); \
+ src1 = vec_ld(stride * i, src); \
+ src2 = vec_ld((stride * i) + 16, src); \
+ register vector unsigned char srcO asm ("v22") = vec_perm(src1, src2, vec_lvsl(stride * i, src)); \
+ dst1 = vec_ld(stride * i, dst); \
+ dst2 = vec_ld((stride * i) + 16, dst); \
+ register vector unsigned char dstO asm ("v23") = vec_perm(dst1, dst2, vec_lvsl(stride * i, dst)); \
+ /* promote the unsigned chars to signed shorts */ \
+ register vector signed short srcV asm ("v24") = \
+ (vector signed short)vec_mergeh((vector signed char)vzero, (vector signed char)srcO); \
+ register vector signed short dstV asm ("v25") = \
+ (vector signed short)vec_mergeh((vector signed char)vzero, (vector signed char)dstO); \
+ register vector signed short srcW asm ("v26") = \
+ (vector signed short)vec_mergel((vector signed char)vzero, (vector signed char)srcO); \
+ register vector signed short dstW asm ("v27") = \
+ (vector signed short)vec_mergel((vector signed char)vzero, (vector signed char)dstO); \
+ /* substractions inside the first butterfly */ \
+ register vector signed short but0 asm ("v28") = vec_sub(srcV, dstV); \
+ register vector signed short but0S asm ("v29") = vec_sub(srcW, dstW); \
+ register vector signed short op1 asm ("v30") = vec_perm(but0, but0, perm1); \
+ register vector signed short but1 asm ("v22") = vec_mladd(but0, vprod1, op1); \
+ register vector signed short op1S asm ("v23") = vec_perm(but0S, but0S, perm1); \
+ register vector signed short but1S asm ("v24") = vec_mladd(but0S, vprod1, op1S); \
+ register vector signed short op2 asm ("v25") = vec_perm(but1, but1, perm2); \
+ register vector signed short but2 asm ("v26") = vec_mladd(but1, vprod2, op2); \
+ register vector signed short op2S asm ("v27") = vec_perm(but1S, but1S, perm2); \
+ register vector signed short but2S asm ("v28") = vec_mladd(but1S, vprod2, op2S); \
+ register vector signed short op3 asm ("v29") = vec_perm(but2, but2, perm3); \
+ res1 = vec_mladd(but2, vprod3, op3); \
+ register vector signed short op3S asm ("v30") = vec_perm(but2S, but2S, perm3); \
+ res2 = vec_mladd(but2S, vprod3, op3S); \
+ }
+ ONEITERBUTTERFLY(0, temp0, temp0S);
+ ONEITERBUTTERFLY(1, temp1, temp1S);
+ ONEITERBUTTERFLY(2, temp2, temp2S);
+ ONEITERBUTTERFLY(3, temp3, temp3S);
+ ONEITERBUTTERFLY(4, temp4, temp4S);
+ ONEITERBUTTERFLY(5, temp5, temp5S);
+ ONEITERBUTTERFLY(6, temp6, temp6S);
+ ONEITERBUTTERFLY(7, temp7, temp7S);
+ }
+#undef ONEITERBUTTERFLY
+ {
+ register vector signed int vsum;
+ register vector signed short line0 = vec_add(temp0, temp1);
+ register vector signed short line1 = vec_sub(temp0, temp1);
+ register vector signed short line2 = vec_add(temp2, temp3);
+ register vector signed short line3 = vec_sub(temp2, temp3);
+ register vector signed short line4 = vec_add(temp4, temp5);
+ register vector signed short line5 = vec_sub(temp4, temp5);
+ register vector signed short line6 = vec_add(temp6, temp7);
+ register vector signed short line7 = vec_sub(temp6, temp7);
+
+ register vector signed short line0B = vec_add(line0, line2);
+ register vector signed short line2B = vec_sub(line0, line2);
+ register vector signed short line1B = vec_add(line1, line3);
+ register vector signed short line3B = vec_sub(line1, line3);
+ register vector signed short line4B = vec_add(line4, line6);
+ register vector signed short line6B = vec_sub(line4, line6);
+ register vector signed short line5B = vec_add(line5, line7);
+ register vector signed short line7B = vec_sub(line5, line7);
+
+ register vector signed short line0C = vec_add(line0B, line4B);
+ register vector signed short line4C = vec_sub(line0B, line4B);
+ register vector signed short line1C = vec_add(line1B, line5B);
+ register vector signed short line5C = vec_sub(line1B, line5B);
+ register vector signed short line2C = vec_add(line2B, line6B);
+ register vector signed short line6C = vec_sub(line2B, line6B);
+ register vector signed short line3C = vec_add(line3B, line7B);
+ register vector signed short line7C = vec_sub(line3B, line7B);
+
+ vsum = vec_sum4s(vec_abs(line0C), vec_splat_s32(0));
+ vsum = vec_sum4s(vec_abs(line1C), vsum);
+ vsum = vec_sum4s(vec_abs(line2C), vsum);
+ vsum = vec_sum4s(vec_abs(line3C), vsum);
+ vsum = vec_sum4s(vec_abs(line4C), vsum);
+ vsum = vec_sum4s(vec_abs(line5C), vsum);
+ vsum = vec_sum4s(vec_abs(line6C), vsum);
+ vsum = vec_sum4s(vec_abs(line7C), vsum);
+
+ register vector signed short line0S = vec_add(temp0S, temp1S);
+ register vector signed short line1S = vec_sub(temp0S, temp1S);
+ register vector signed short line2S = vec_add(temp2S, temp3S);
+ register vector signed short line3S = vec_sub(temp2S, temp3S);
+ register vector signed short line4S = vec_add(temp4S, temp5S);
+ register vector signed short line5S = vec_sub(temp4S, temp5S);
+ register vector signed short line6S = vec_add(temp6S, temp7S);
+ register vector signed short line7S = vec_sub(temp6S, temp7S);
+
+ register vector signed short line0BS = vec_add(line0S, line2S);
+ register vector signed short line2BS = vec_sub(line0S, line2S);
+ register vector signed short line1BS = vec_add(line1S, line3S);
+ register vector signed short line3BS = vec_sub(line1S, line3S);
+ register vector signed short line4BS = vec_add(line4S, line6S);
+ register vector signed short line6BS = vec_sub(line4S, line6S);
+ register vector signed short line5BS = vec_add(line5S, line7S);
+ register vector signed short line7BS = vec_sub(line5S, line7S);
+
+ register vector signed short line0CS = vec_add(line0BS, line4BS);
+ register vector signed short line4CS = vec_sub(line0BS, line4BS);
+ register vector signed short line1CS = vec_add(line1BS, line5BS);
+ register vector signed short line5CS = vec_sub(line1BS, line5BS);
+ register vector signed short line2CS = vec_add(line2BS, line6BS);
+ register vector signed short line6CS = vec_sub(line2BS, line6BS);
+ register vector signed short line3CS = vec_add(line3BS, line7BS);
+ register vector signed short line7CS = vec_sub(line3BS, line7BS);
+
+ vsum = vec_sum4s(vec_abs(line0CS), vsum);
+ vsum = vec_sum4s(vec_abs(line1CS), vsum);
+ vsum = vec_sum4s(vec_abs(line2CS), vsum);
+ vsum = vec_sum4s(vec_abs(line3CS), vsum);
+ vsum = vec_sum4s(vec_abs(line4CS), vsum);
+ vsum = vec_sum4s(vec_abs(line5CS), vsum);
+ vsum = vec_sum4s(vec_abs(line6CS), vsum);
+ vsum = vec_sum4s(vec_abs(line7CS), vsum);
+ vsum = vec_sums(vsum, (vector signed int)vzero);
+ vsum = vec_splat(vsum, 3);
+ vec_ste(vsum, 0, &sum);
+ }
+ return sum;
+}
+
+int hadamard8_diff16_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){
+POWERPC_PERF_DECLARE(altivec_hadamard8_diff16_num, 1);
+ int score;
+POWERPC_PERF_START_COUNT(altivec_hadamard8_diff16_num, 1);
+ score = hadamard8_diff16x8_altivec(s, dst, src, stride, 8);
+ if (h==16) {
+ dst += 8*stride;
+ src += 8*stride;
+ score += hadamard8_diff16x8_altivec(s, dst, src, stride, 8);
+ }
+POWERPC_PERF_STOP_COUNT(altivec_hadamard8_diff16_num, 1);
+ return score;
+}
+
int has_altivec(void)
{
#ifdef CONFIG_DARWIN
diff --git a/src/libffmpeg/libavcodec/ppc/dsputil_altivec.h b/src/libffmpeg/libavcodec/ppc/dsputil_altivec.h
index 93448a1ad..e2729ab22 100644
--- a/src/libffmpeg/libavcodec/ppc/dsputil_altivec.h
+++ b/src/libffmpeg/libavcodec/ppc/dsputil_altivec.h
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2002 Brian Foley
* Copyright (c) 2002 Dieter Shirley
+ * Copyright (c) 2003-2004 Romain Dolbeau <romain@dolbeau.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -45,6 +46,8 @@ extern void put_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int l
extern void put_no_rnd_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h);
extern void put_pixels16_xy2_altivec(uint8_t * block, const uint8_t * pixels, int line_size, int h);
extern void put_no_rnd_pixels16_xy2_altivec(uint8_t * block, const uint8_t * pixels, int line_size, int h);
+extern int hadamard8_diff8x8_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h);
+extern int hadamard8_diff16_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h);
extern void gmc1_altivec(uint8_t *dst, uint8_t *src, int stride, int h, int x16, int y16, int rounder);
diff --git a/src/libffmpeg/libavcodec/ppc/dsputil_ppc.c b/src/libffmpeg/libavcodec/ppc/dsputil_ppc.c
index b8372e51e..b70de7328 100644
--- a/src/libffmpeg/libavcodec/ppc/dsputil_ppc.c
+++ b/src/libffmpeg/libavcodec/ppc/dsputil_ppc.c
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2002 Brian Foley
* Copyright (c) 2002 Dieter Shirley
+ * Copyright (c) 2003-2004 Romain Dolbeau <romain@dolbeau.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -59,6 +60,8 @@ static unsigned char* perfname[] = {
"put_no_rnd_pixels8_xy2_altivec",
"put_pixels16_xy2_altivec",
"put_no_rnd_pixels16_xy2_altivec",
+ "hadamard8_diff8x8_altivec",
+ "hadamard8_diff16_altivec",
"clear_blocks_dcbz32_ppc",
"clear_blocks_dcbz128_ppc"
};
@@ -262,7 +265,7 @@ void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx)
c->add_bytes= add_bytes_altivec;
#endif /* 0 */
c->put_pixels_tab[0][0] = put_pixels16_altivec;
- /* the tow functions do the same thing, so use the same code */
+ /* the two functions do the same thing, so use the same code */
c->put_no_rnd_pixels_tab[0][0] = put_pixels16_altivec;
c->avg_pixels_tab[0][0] = avg_pixels16_altivec;
// next one disabled as it's untested.
@@ -276,6 +279,9 @@ void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx)
c->gmc1 = gmc1_altivec;
+ c->hadamard8_diff[0] = hadamard8_diff16_altivec;
+ c->hadamard8_diff[1] = hadamard8_diff8x8_altivec;
+
#ifdef CONFIG_ENCODERS
if (avctx->dct_algo == FF_DCT_AUTO ||
avctx->dct_algo == FF_DCT_ALTIVEC)
diff --git a/src/libffmpeg/libavcodec/ppc/dsputil_ppc.h b/src/libffmpeg/libavcodec/ppc/dsputil_ppc.h
index d672edfcb..8b34c6b45 100644
--- a/src/libffmpeg/libavcodec/ppc/dsputil_ppc.h
+++ b/src/libffmpeg/libavcodec/ppc/dsputil_ppc.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003 Romain Dolbeau <romain@dolbeau.org>
+ * Copyright (c) 2003-2004 Romain Dolbeau <romain@dolbeau.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -50,6 +50,8 @@ enum powerpc_perf_index {
altivec_put_no_rnd_pixels8_xy2_num,
altivec_put_pixels16_xy2_num,
altivec_put_no_rnd_pixels16_xy2_num,
+ altivec_hadamard8_diff8x8_num,
+ altivec_hadamard8_diff16_num,
powerpc_clear_blocks_dcbz32,
powerpc_clear_blocks_dcbz128,
powerpc_perf_total
@@ -63,6 +65,8 @@ enum powerpc_data_index {
};
extern unsigned long long perfdata[POWERPC_NUM_PMC_ENABLED][powerpc_perf_total][powerpc_data_total];
+#ifndef POWERPC_MODE_64BITS
+#define POWERP_PMC_DATATYPE unsigned long
#define POWERPC_GET_PMC1(a) asm volatile("mfspr %0, 937" : "=r" (a))
#define POWERPC_GET_PMC2(a) asm volatile("mfspr %0, 938" : "=r" (a))
#if (POWERPC_NUM_PMC_ENABLED > 2)
@@ -79,7 +83,30 @@ extern unsigned long long perfdata[POWERPC_NUM_PMC_ENABLED][powerpc_perf_total][
#define POWERPC_GET_PMC5(a) do {} while (0)
#define POWERPC_GET_PMC6(a) do {} while (0)
#endif
-#define POWERPC_PERF_DECLARE(a, cond) unsigned long pmc_start[POWERPC_NUM_PMC_ENABLED], pmc_stop[POWERPC_NUM_PMC_ENABLED], pmc_loop_index;
+#else /* POWERPC_MODE_64BITS */
+#define POWERP_PMC_DATATYPE unsigned long long
+#define POWERPC_GET_PMC1(a) asm volatile("mfspr %0, 771" : "=r" (a))
+#define POWERPC_GET_PMC2(a) asm volatile("mfspr %0, 772" : "=r" (a))
+#if (POWERPC_NUM_PMC_ENABLED > 2)
+#define POWERPC_GET_PMC3(a) asm volatile("mfspr %0, 773" : "=r" (a))
+#define POWERPC_GET_PMC4(a) asm volatile("mfspr %0, 774" : "=r" (a))
+#else
+#define POWERPC_GET_PMC3(a) do {} while (0)
+#define POWERPC_GET_PMC4(a) do {} while (0)
+#endif
+#if (POWERPC_NUM_PMC_ENABLED > 4)
+#define POWERPC_GET_PMC5(a) asm volatile("mfspr %0, 775" : "=r" (a))
+#define POWERPC_GET_PMC6(a) asm volatile("mfspr %0, 776" : "=r" (a))
+#else
+#define POWERPC_GET_PMC5(a) do {} while (0)
+#define POWERPC_GET_PMC6(a) do {} while (0)
+#endif
+#endif /* POWERPC_MODE_64BITS */
+#define POWERPC_PERF_DECLARE(a, cond) \
+ POWERP_PMC_DATATYPE \
+ pmc_start[POWERPC_NUM_PMC_ENABLED], \
+ pmc_stop[POWERPC_NUM_PMC_ENABLED], \
+ pmc_loop_index;
#define POWERPC_PERF_START_COUNT(a, cond) do { \
POWERPC_GET_PMC6(pmc_start[5]); \
POWERPC_GET_PMC5(pmc_start[4]); \
@@ -101,9 +128,9 @@ extern unsigned long long perfdata[POWERPC_NUM_PMC_ENABLED][powerpc_perf_total][
pmc_loop_index < POWERPC_NUM_PMC_ENABLED; \
pmc_loop_index++) \
{ \
- if (pmc_stop[pmc_loop_index] >= pmc_start[pmc_loop_index]) \
- { \
- unsigned long diff = \
+ if (pmc_stop[pmc_loop_index] >= pmc_start[pmc_loop_index]) \
+ { \
+ POWERP_PMC_DATATYPE diff = \
pmc_stop[pmc_loop_index] - pmc_start[pmc_loop_index]; \
if (diff < perfdata[pmc_loop_index][a][powerpc_data_min]) \
perfdata[pmc_loop_index][a][powerpc_data_min] = diff; \
diff --git a/src/libffmpeg/libavcodec/ppc/fdct_altivec.c b/src/libffmpeg/libavcodec/ppc/fdct_altivec.c
new file mode 100644
index 000000000..99df5ced3
--- /dev/null
+++ b/src/libffmpeg/libavcodec/ppc/fdct_altivec.c
@@ -0,0 +1,498 @@
+/* ffmpeg/libavcodec/ppc/fdct_altivec.c, this file is part of the
+ * AltiVec optimized library for the FFMPEG Multimedia System
+ * Copyright (C) 2003 James Klicman <james@klicman.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "../common.h"
+#include "../dsputil.h"
+#include "dsputil_altivec.h"
+#include "gcc_fixes.h"
+
+
+#define vs16(v) ((vector signed short)(v))
+#define vs32(v) ((vector signed int)(v))
+#define vu8(v) ((vector unsigned char)(v))
+#define vu16(v) ((vector unsigned short)(v))
+#define vu32(v) ((vector unsigned int)(v))
+
+
+#define C1 0.98078525066375732421875000 /* cos(1*PI/16) */
+#define C2 0.92387950420379638671875000 /* cos(2*PI/16) */
+#define C3 0.83146959543228149414062500 /* cos(3*PI/16) */
+#define C4 0.70710676908493041992187500 /* cos(4*PI/16) */
+#define C5 0.55557024478912353515625000 /* cos(5*PI/16) */
+#define C6 0.38268342614173889160156250 /* cos(6*PI/16) */
+#define C7 0.19509032368659973144531250 /* cos(7*PI/16) */
+#define SQRT_2 1.41421353816986083984375000 /* sqrt(2) */
+
+
+#define W0 -(2 * C2)
+#define W1 (2 * C6)
+#define W2 (SQRT_2 * C6)
+#define W3 (SQRT_2 * C3)
+#define W4 (SQRT_2 * (-C1 + C3 + C5 - C7))
+#define W5 (SQRT_2 * ( C1 + C3 - C5 + C7))
+#define W6 (SQRT_2 * ( C1 + C3 + C5 - C7))
+#define W7 (SQRT_2 * ( C1 + C3 - C5 - C7))
+#define W8 (SQRT_2 * ( C7 - C3))
+#define W9 (SQRT_2 * (-C1 - C3))
+#define WA (SQRT_2 * (-C3 - C5))
+#define WB (SQRT_2 * ( C5 - C3))
+
+
+static vector float fdctconsts[3] = {
+ (vector float)AVV( W0, W1, W2, W3 ),
+ (vector float)AVV( W4, W5, W6, W7 ),
+ (vector float)AVV( W8, W9, WA, WB )
+};
+
+#define LD_W0 vec_splat(cnsts0, 0)
+#define LD_W1 vec_splat(cnsts0, 1)
+#define LD_W2 vec_splat(cnsts0, 2)
+#define LD_W3 vec_splat(cnsts0, 3)
+#define LD_W4 vec_splat(cnsts1, 0)
+#define LD_W5 vec_splat(cnsts1, 1)
+#define LD_W6 vec_splat(cnsts1, 2)
+#define LD_W7 vec_splat(cnsts1, 3)
+#define LD_W8 vec_splat(cnsts2, 0)
+#define LD_W9 vec_splat(cnsts2, 1)
+#define LD_WA vec_splat(cnsts2, 2)
+#define LD_WB vec_splat(cnsts2, 3)
+
+
+#define FDCTROW(b0,b1,b2,b3,b4,b5,b6,b7) /* {{{ */ \
+ x0 = vec_add(b0, b7); /* x0 = b0 + b7; */ \
+ x7 = vec_sub(b0, b7); /* x7 = b0 - b7; */ \
+ x1 = vec_add(b1, b6); /* x1 = b1 + b6; */ \
+ x6 = vec_sub(b1, b6); /* x6 = b1 - b6; */ \
+ x2 = vec_add(b2, b5); /* x2 = b2 + b5; */ \
+ x5 = vec_sub(b2, b5); /* x5 = b2 - b5; */ \
+ x3 = vec_add(b3, b4); /* x3 = b3 + b4; */ \
+ x4 = vec_sub(b3, b4); /* x4 = b3 - b4; */ \
+ \
+ b7 = vec_add(x0, x3); /* b7 = x0 + x3; */ \
+ b1 = vec_add(x1, x2); /* b1 = x1 + x2; */ \
+ b0 = vec_add(b7, b1); /* b0 = b7 + b1; */ \
+ b4 = vec_sub(b7, b1); /* b4 = b7 - b1; */ \
+ \
+ b2 = vec_sub(x0, x3); /* b2 = x0 - x3; */ \
+ b6 = vec_sub(x1, x2); /* b6 = x1 - x2; */ \
+ b5 = vec_add(b6, b2); /* b5 = b6 + b2; */ \
+ cnst = LD_W2; \
+ b5 = vec_madd(cnst, b5, mzero); /* b5 = b5 * W2; */ \
+ cnst = LD_W1; \
+ b2 = vec_madd(cnst, b2, b5); /* b2 = b5 + b2 * W1; */ \
+ cnst = LD_W0; \
+ b6 = vec_madd(cnst, b6, b5); /* b6 = b5 + b6 * W0; */ \
+ \
+ x0 = vec_add(x4, x7); /* x0 = x4 + x7; */ \
+ x1 = vec_add(x5, x6); /* x1 = x5 + x6; */ \
+ x2 = vec_add(x4, x6); /* x2 = x4 + x6; */ \
+ x3 = vec_add(x5, x7); /* x3 = x5 + x7; */ \
+ x8 = vec_add(x2, x3); /* x8 = x2 + x3; */ \
+ cnst = LD_W3; \
+ x8 = vec_madd(cnst, x8, mzero); /* x8 = x8 * W3; */ \
+ \
+ cnst = LD_W8; \
+ x0 = vec_madd(cnst, x0, mzero); /* x0 *= W8; */ \
+ cnst = LD_W9; \
+ x1 = vec_madd(cnst, x1, mzero); /* x1 *= W9; */ \
+ cnst = LD_WA; \
+ x2 = vec_madd(cnst, x2, x8); /* x2 = x2 * WA + x8; */ \
+ cnst = LD_WB; \
+ x3 = vec_madd(cnst, x3, x8); /* x3 = x3 * WB + x8; */ \
+ \
+ cnst = LD_W4; \
+ b7 = vec_madd(cnst, x4, x0); /* b7 = x4 * W4 + x0; */ \
+ cnst = LD_W5; \
+ b5 = vec_madd(cnst, x5, x1); /* b5 = x5 * W5 + x1; */ \
+ cnst = LD_W6; \
+ b3 = vec_madd(cnst, x6, x1); /* b3 = x6 * W6 + x1; */ \
+ cnst = LD_W7; \
+ b1 = vec_madd(cnst, x7, x0); /* b1 = x7 * W7 + x0; */ \
+ \
+ b7 = vec_add(b7, x2); /* b7 = b7 + x2; */ \
+ b5 = vec_add(b5, x3); /* b5 = b5 + x3; */ \
+ b3 = vec_add(b3, x2); /* b3 = b3 + x2; */ \
+ b1 = vec_add(b1, x3); /* b1 = b1 + x3; */ \
+ /* }}} */
+
+#define FDCTCOL(b0,b1,b2,b3,b4,b5,b6,b7) /* {{{ */ \
+ x0 = vec_add(b0, b7); /* x0 = b0 + b7; */ \
+ x7 = vec_sub(b0, b7); /* x7 = b0 - b7; */ \
+ x1 = vec_add(b1, b6); /* x1 = b1 + b6; */ \
+ x6 = vec_sub(b1, b6); /* x6 = b1 - b6; */ \
+ x2 = vec_add(b2, b5); /* x2 = b2 + b5; */ \
+ x5 = vec_sub(b2, b5); /* x5 = b2 - b5; */ \
+ x3 = vec_add(b3, b4); /* x3 = b3 + b4; */ \
+ x4 = vec_sub(b3, b4); /* x4 = b3 - b4; */ \
+ \
+ b7 = vec_add(x0, x3); /* b7 = x0 + x3; */ \
+ b1 = vec_add(x1, x2); /* b1 = x1 + x2; */ \
+ b0 = vec_add(b7, b1); /* b0 = b7 + b1; */ \
+ b4 = vec_sub(b7, b1); /* b4 = b7 - b1; */ \
+ \
+ b2 = vec_sub(x0, x3); /* b2 = x0 - x3; */ \
+ b6 = vec_sub(x1, x2); /* b6 = x1 - x2; */ \
+ b5 = vec_add(b6, b2); /* b5 = b6 + b2; */ \
+ cnst = LD_W2; \
+ b5 = vec_madd(cnst, b5, mzero); /* b5 = b5 * W2; */ \
+ cnst = LD_W1; \
+ b2 = vec_madd(cnst, b2, b5); /* b2 = b5 + b2 * W1; */ \
+ cnst = LD_W0; \
+ b6 = vec_madd(cnst, b6, b5); /* b6 = b5 + b6 * W0; */ \
+ \
+ x0 = vec_add(x4, x7); /* x0 = x4 + x7; */ \
+ x1 = vec_add(x5, x6); /* x1 = x5 + x6; */ \
+ x2 = vec_add(x4, x6); /* x2 = x4 + x6; */ \
+ x3 = vec_add(x5, x7); /* x3 = x5 + x7; */ \
+ x8 = vec_add(x2, x3); /* x8 = x2 + x3; */ \
+ cnst = LD_W3; \
+ x8 = vec_madd(cnst, x8, mzero); /* x8 = x8 * W3; */ \
+ \
+ cnst = LD_W8; \
+ x0 = vec_madd(cnst, x0, mzero); /* x0 *= W8; */ \
+ cnst = LD_W9; \
+ x1 = vec_madd(cnst, x1, mzero); /* x1 *= W9; */ \
+ cnst = LD_WA; \
+ x2 = vec_madd(cnst, x2, x8); /* x2 = x2 * WA + x8; */ \
+ cnst = LD_WB; \
+ x3 = vec_madd(cnst, x3, x8); /* x3 = x3 * WB + x8; */ \
+ \
+ cnst = LD_W4; \
+ b7 = vec_madd(cnst, x4, x0); /* b7 = x4 * W4 + x0; */ \
+ cnst = LD_W5; \
+ b5 = vec_madd(cnst, x5, x1); /* b5 = x5 * W5 + x1; */ \
+ cnst = LD_W6; \
+ b3 = vec_madd(cnst, x6, x1); /* b3 = x6 * W6 + x1; */ \
+ cnst = LD_W7; \
+ b1 = vec_madd(cnst, x7, x0); /* b1 = x7 * W7 + x0; */ \
+ \
+ b7 = vec_add(b7, x2); /* b7 += x2; */ \
+ b5 = vec_add(b5, x3); /* b5 += x3; */ \
+ b3 = vec_add(b3, x2); /* b3 += x2; */ \
+ b1 = vec_add(b1, x3); /* b1 += x3; */ \
+ /* }}} */
+
+
+
+/* two dimensional discrete cosine transform */
+
+void fdct_altivec(int16_t *block)
+{
+POWERPC_PERF_DECLARE(altivec_fdct, 1);
+#ifdef ALTIVEC_USE_REFERENCE_C_CODE
+POWERPC_PERF_START_COUNT(altivec_fdct, 1);
+ void ff_jpeg_fdct_islow(int16_t *block);
+ ff_jpeg_fdct_islow(block);
+POWERPC_PERF_STOP_COUNT(altivec_fdct, 1);
+#else /* ALTIVEC_USE_REFERENCE_C_CODE */
+ vector signed short *bp;
+ vector float *cp;
+ vector float b00, b10, b20, b30, b40, b50, b60, b70;
+ vector float b01, b11, b21, b31, b41, b51, b61, b71;
+ vector float mzero, cnst, cnsts0, cnsts1, cnsts2;
+ vector float x0, x1, x2, x3, x4, x5, x6, x7, x8;
+
+ POWERPC_PERF_START_COUNT(altivec_fdct, 1);
+
+
+ /* setup constants {{{ */
+ /* mzero = -0.0 */
+ vu32(mzero) = vec_splat_u32(-1);
+ vu32(mzero) = vec_sl(vu32(mzero), vu32(mzero));
+ cp = fdctconsts;
+ cnsts0 = vec_ld(0, cp); cp++;
+ cnsts1 = vec_ld(0, cp); cp++;
+ cnsts2 = vec_ld(0, cp);
+ /* }}} */
+
+
+ /* 8x8 matrix transpose (vector short[8]) {{{ */
+#define MERGE_S16(hl,a,b) vec_merge##hl(vs16(a), vs16(b))
+
+ bp = (vector signed short*)block;
+ vs16(b00) = vec_ld(0, bp);
+ vs16(b40) = vec_ld(16*4, bp);
+ vs16(b01) = MERGE_S16(h, b00, b40);
+ vs16(b11) = MERGE_S16(l, b00, b40);
+ bp++;
+ vs16(b10) = vec_ld(0, bp);
+ vs16(b50) = vec_ld(16*4, bp);
+ vs16(b21) = MERGE_S16(h, b10, b50);
+ vs16(b31) = MERGE_S16(l, b10, b50);
+ bp++;
+ vs16(b20) = vec_ld(0, bp);
+ vs16(b60) = vec_ld(16*4, bp);
+ vs16(b41) = MERGE_S16(h, b20, b60);
+ vs16(b51) = MERGE_S16(l, b20, b60);
+ bp++;
+ vs16(b30) = vec_ld(0, bp);
+ vs16(b70) = vec_ld(16*4, bp);
+ vs16(b61) = MERGE_S16(h, b30, b70);
+ vs16(b71) = MERGE_S16(l, b30, b70);
+
+ vs16(x0) = MERGE_S16(h, b01, b41);
+ vs16(x1) = MERGE_S16(l, b01, b41);
+ vs16(x2) = MERGE_S16(h, b11, b51);
+ vs16(x3) = MERGE_S16(l, b11, b51);
+ vs16(x4) = MERGE_S16(h, b21, b61);
+ vs16(x5) = MERGE_S16(l, b21, b61);
+ vs16(x6) = MERGE_S16(h, b31, b71);
+ vs16(x7) = MERGE_S16(l, b31, b71);
+
+ vs16(b00) = MERGE_S16(h, x0, x4);
+ vs16(b10) = MERGE_S16(l, x0, x4);
+ vs16(b20) = MERGE_S16(h, x1, x5);
+ vs16(b30) = MERGE_S16(l, x1, x5);
+ vs16(b40) = MERGE_S16(h, x2, x6);
+ vs16(b50) = MERGE_S16(l, x2, x6);
+ vs16(b60) = MERGE_S16(h, x3, x7);
+ vs16(b70) = MERGE_S16(l, x3, x7);
+
+#undef MERGE_S16
+ /* }}} */
+
+
+/* Some of the initial calculations can be done as vector short before
+ * conversion to vector float. The following code section takes advantage
+ * of this.
+ */
+#if 1
+ /* fdct rows {{{ */
+ vs16(x0) = vec_add(vs16(b00), vs16(b70));
+ vs16(x7) = vec_sub(vs16(b00), vs16(b70));
+ vs16(x1) = vec_add(vs16(b10), vs16(b60));
+ vs16(x6) = vec_sub(vs16(b10), vs16(b60));
+ vs16(x2) = vec_add(vs16(b20), vs16(b50));
+ vs16(x5) = vec_sub(vs16(b20), vs16(b50));
+ vs16(x3) = vec_add(vs16(b30), vs16(b40));
+ vs16(x4) = vec_sub(vs16(b30), vs16(b40));
+
+ vs16(b70) = vec_add(vs16(x0), vs16(x3));
+ vs16(b10) = vec_add(vs16(x1), vs16(x2));
+
+ vs16(b00) = vec_add(vs16(b70), vs16(b10));
+ vs16(b40) = vec_sub(vs16(b70), vs16(b10));
+
+#define CTF0(n) \
+ vs32(b##n##1) = vec_unpackl(vs16(b##n##0)); \
+ vs32(b##n##0) = vec_unpackh(vs16(b##n##0)); \
+ b##n##1 = vec_ctf(vs32(b##n##1), 0); \
+ b##n##0 = vec_ctf(vs32(b##n##0), 0);
+
+ CTF0(0);
+ CTF0(4);
+
+ vs16(b20) = vec_sub(vs16(x0), vs16(x3));
+ vs16(b60) = vec_sub(vs16(x1), vs16(x2));
+
+ CTF0(2);
+ CTF0(6);
+
+#undef CTF0
+
+ x0 = vec_add(b60, b20);
+ x1 = vec_add(b61, b21);
+
+ cnst = LD_W2;
+ x0 = vec_madd(cnst, x0, mzero);
+ x1 = vec_madd(cnst, x1, mzero);
+ cnst = LD_W1;
+ b20 = vec_madd(cnst, b20, x0);
+ b21 = vec_madd(cnst, b21, x1);
+ cnst = LD_W0;
+ b60 = vec_madd(cnst, b60, x0);
+ b61 = vec_madd(cnst, b61, x1);
+
+#define CTFX(x,b) \
+ vs32(b##0) = vec_unpackh(vs16(x)); \
+ vs32(b##1) = vec_unpackl(vs16(x)); \
+ b##0 = vec_ctf(vs32(b##0), 0); \
+ b##1 = vec_ctf(vs32(b##1), 0); \
+
+ CTFX(x4, b7);
+ CTFX(x5, b5);
+ CTFX(x6, b3);
+ CTFX(x7, b1);
+
+#undef CTFX
+
+
+ x0 = vec_add(b70, b10);
+ x1 = vec_add(b50, b30);
+ x2 = vec_add(b70, b30);
+ x3 = vec_add(b50, b10);
+ x8 = vec_add(x2, x3);
+ cnst = LD_W3;
+ x8 = vec_madd(cnst, x8, mzero);
+
+ cnst = LD_W8;
+ x0 = vec_madd(cnst, x0, mzero);
+ cnst = LD_W9;
+ x1 = vec_madd(cnst, x1, mzero);
+ cnst = LD_WA;
+ x2 = vec_madd(cnst, x2, x8);
+ cnst = LD_WB;
+ x3 = vec_madd(cnst, x3, x8);
+
+ cnst = LD_W4;
+ b70 = vec_madd(cnst, b70, x0);
+ cnst = LD_W5;
+ b50 = vec_madd(cnst, b50, x1);
+ cnst = LD_W6;
+ b30 = vec_madd(cnst, b30, x1);
+ cnst = LD_W7;
+ b10 = vec_madd(cnst, b10, x0);
+
+ b70 = vec_add(b70, x2);
+ b50 = vec_add(b50, x3);
+ b30 = vec_add(b30, x2);
+ b10 = vec_add(b10, x3);
+
+
+ x0 = vec_add(b71, b11);
+ x1 = vec_add(b51, b31);
+ x2 = vec_add(b71, b31);
+ x3 = vec_add(b51, b11);
+ x8 = vec_add(x2, x3);
+ cnst = LD_W3;
+ x8 = vec_madd(cnst, x8, mzero);
+
+ cnst = LD_W8;
+ x0 = vec_madd(cnst, x0, mzero);
+ cnst = LD_W9;
+ x1 = vec_madd(cnst, x1, mzero);
+ cnst = LD_WA;
+ x2 = vec_madd(cnst, x2, x8);
+ cnst = LD_WB;
+ x3 = vec_madd(cnst, x3, x8);
+
+ cnst = LD_W4;
+ b71 = vec_madd(cnst, b71, x0);
+ cnst = LD_W5;
+ b51 = vec_madd(cnst, b51, x1);
+ cnst = LD_W6;
+ b31 = vec_madd(cnst, b31, x1);
+ cnst = LD_W7;
+ b11 = vec_madd(cnst, b11, x0);
+
+ b71 = vec_add(b71, x2);
+ b51 = vec_add(b51, x3);
+ b31 = vec_add(b31, x2);
+ b11 = vec_add(b11, x3);
+ /* }}} */
+#else
+ /* convert to float {{{ */
+#define CTF(n) \
+ vs32(b##n##1) = vec_unpackl(vs16(b##n##0)); \
+ vs32(b##n##0) = vec_unpackh(vs16(b##n##0)); \
+ b##n##1 = vec_ctf(vs32(b##n##1), 0); \
+ b##n##0 = vec_ctf(vs32(b##n##0), 0); \
+
+ CTF(0);
+ CTF(1);
+ CTF(2);
+ CTF(3);
+ CTF(4);
+ CTF(5);
+ CTF(6);
+ CTF(7);
+
+#undef CTF
+ /* }}} */
+
+ FDCTROW(b00, b10, b20, b30, b40, b50, b60, b70);
+ FDCTROW(b01, b11, b21, b31, b41, b51, b61, b71);
+#endif
+
+
+ /* 8x8 matrix transpose (vector float[8][2]) {{{ */
+ x0 = vec_mergel(b00, b20);
+ x1 = vec_mergeh(b00, b20);
+ x2 = vec_mergel(b10, b30);
+ x3 = vec_mergeh(b10, b30);
+
+ b00 = vec_mergeh(x1, x3);
+ b10 = vec_mergel(x1, x3);
+ b20 = vec_mergeh(x0, x2);
+ b30 = vec_mergel(x0, x2);
+
+ x4 = vec_mergel(b41, b61);
+ x5 = vec_mergeh(b41, b61);
+ x6 = vec_mergel(b51, b71);
+ x7 = vec_mergeh(b51, b71);
+
+ b41 = vec_mergeh(x5, x7);
+ b51 = vec_mergel(x5, x7);
+ b61 = vec_mergeh(x4, x6);
+ b71 = vec_mergel(x4, x6);
+
+ x0 = vec_mergel(b01, b21);
+ x1 = vec_mergeh(b01, b21);
+ x2 = vec_mergel(b11, b31);
+ x3 = vec_mergeh(b11, b31);
+
+ x4 = vec_mergel(b40, b60);
+ x5 = vec_mergeh(b40, b60);
+ x6 = vec_mergel(b50, b70);
+ x7 = vec_mergeh(b50, b70);
+
+ b40 = vec_mergeh(x1, x3);
+ b50 = vec_mergel(x1, x3);
+ b60 = vec_mergeh(x0, x2);
+ b70 = vec_mergel(x0, x2);
+
+ b01 = vec_mergeh(x5, x7);
+ b11 = vec_mergel(x5, x7);
+ b21 = vec_mergeh(x4, x6);
+ b31 = vec_mergel(x4, x6);
+ /* }}} */
+
+
+ FDCTCOL(b00, b10, b20, b30, b40, b50, b60, b70);
+ FDCTCOL(b01, b11, b21, b31, b41, b51, b61, b71);
+
+
+ /* round, convert back to short {{{ */
+#define CTS(n) \
+ b##n##0 = vec_round(b##n##0); \
+ b##n##1 = vec_round(b##n##1); \
+ vs32(b##n##0) = vec_cts(b##n##0, 0); \
+ vs32(b##n##1) = vec_cts(b##n##1, 0); \
+ vs16(b##n##0) = vec_pack(vs32(b##n##0), vs32(b##n##1)); \
+ vec_st(vs16(b##n##0), 0, bp);
+
+ bp = (vector signed short*)block;
+ CTS(0); bp++;
+ CTS(1); bp++;
+ CTS(2); bp++;
+ CTS(3); bp++;
+ CTS(4); bp++;
+ CTS(5); bp++;
+ CTS(6); bp++;
+ CTS(7);
+
+#undef CTS
+ /* }}} */
+
+POWERPC_PERF_STOP_COUNT(altivec_fdct, 1);
+#endif /* ALTIVEC_USE_REFERENCE_C_CODE */
+}
+
+/* vim:set foldmethod=marker foldlevel=0: */
diff --git a/src/libffmpeg/libavcodec/ppc/mpegvideo_altivec.c b/src/libffmpeg/libavcodec/ppc/mpegvideo_altivec.c
index 51b387792..91e744af9 100644
--- a/src/libffmpeg/libavcodec/ppc/mpegvideo_altivec.c
+++ b/src/libffmpeg/libavcodec/ppc/mpegvideo_altivec.c
@@ -1,6 +1,9 @@
/*
* Copyright (c) 2002 Dieter Shirley
*
+ * dct_unquantize_h263_altivec:
+ * Copyright (c) 2003 Romain Dolbeau <romain@dolbeau.org>
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
diff --git a/src/libffmpeg/libavcodec/ppc/mpegvideo_ppc.c b/src/libffmpeg/libavcodec/ppc/mpegvideo_ppc.c
index ce4bf8a47..c8269eb9a 100644
--- a/src/libffmpeg/libavcodec/ppc/mpegvideo_ppc.c
+++ b/src/libffmpeg/libavcodec/ppc/mpegvideo_ppc.c
@@ -1,84 +1,86 @@
-/*
- * Copyright (c) 2002 Dieter Shirley
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "../dsputil.h"
-#include "../mpegvideo.h"
-#include <time.h>
-
-#ifdef HAVE_ALTIVEC
-#include "dsputil_altivec.h"
-#endif
-
-extern int dct_quantize_altivec(MpegEncContext *s,
- DCTELEM *block, int n,
- int qscale, int *overflow);
+/*
+ * Copyright (c) 2002 Dieter Shirley
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "../dsputil.h"
+#include "../mpegvideo.h"
+#include <time.h>
+
+#ifdef HAVE_ALTIVEC
+#include "dsputil_altivec.h"
+#endif
+
+extern int dct_quantize_altivec(MpegEncContext *s,
+ DCTELEM *block, int n,
+ int qscale, int *overflow);
extern void dct_unquantize_h263_altivec(MpegEncContext *s,
DCTELEM *block, int n, int qscale);
-
-extern void idct_put_altivec(uint8_t *dest, int line_size, int16_t *block);
-extern void idct_add_altivec(uint8_t *dest, int line_size, int16_t *block);
-
-
-void MPV_common_init_ppc(MpegEncContext *s)
-{
+
+extern void idct_put_altivec(uint8_t *dest, int line_size, int16_t *block);
+extern void idct_add_altivec(uint8_t *dest, int line_size, int16_t *block);
+
+
+void MPV_common_init_ppc(MpegEncContext *s)
+{
#ifdef HAVE_ALTIVEC
- if (has_altivec())
- {
- if ((s->avctx->idct_algo == FF_IDCT_AUTO) ||
- (s->avctx->idct_algo == FF_IDCT_ALTIVEC))
- {
- s->dsp.idct_put = idct_put_altivec;
- s->dsp.idct_add = idct_add_altivec;
+ if (has_altivec())
+ {
+ if ((s->avctx->idct_algo == FF_IDCT_AUTO) ||
+ (s->avctx->idct_algo == FF_IDCT_ALTIVEC))
+ {
+ s->dsp.idct_put = idct_put_altivec;
+ s->dsp.idct_add = idct_add_altivec;
#ifndef ALTIVEC_USE_REFERENCE_C_CODE
- s->dsp.idct_permutation_type = FF_TRANSPOSE_IDCT_PERM;
+ s->dsp.idct_permutation_type = FF_TRANSPOSE_IDCT_PERM;
#else /* ALTIVEC_USE_REFERENCE_C_CODE */
s->dsp.idct_permutation_type = FF_NO_IDCT_PERM;
#endif /* ALTIVEC_USE_REFERENCE_C_CODE */
- }
-
- // Test to make sure that the dct required alignments are met.
- if ((((long)(s->q_intra_matrix) & 0x0f) != 0) ||
- (((long)(s->q_inter_matrix) & 0x0f) != 0))
- {
- av_log(s->avctx, AV_LOG_INFO, "Internal Error: q-matrix blocks must be 16-byte aligned "
- "to use Altivec DCT. Reverting to non-altivec version.\n");
- return;
- }
-
- if (((long)(s->intra_scantable.inverse) & 0x0f) != 0)
- {
- av_log(s->avctx, AV_LOG_INFO, "Internal Error: scan table blocks must be 16-byte aligned "
- "to use Altivec DCT. Reverting to non-altivec version.\n");
- return;
- }
-
-
- if ((s->avctx->dct_algo == FF_DCT_AUTO) ||
- (s->avctx->dct_algo == FF_DCT_ALTIVEC))
- {
- s->dct_quantize = dct_quantize_altivec;
+ }
+
+ // Test to make sure that the dct required alignments are met.
+ if ((((long)(s->q_intra_matrix) & 0x0f) != 0) ||
+ (((long)(s->q_inter_matrix) & 0x0f) != 0))
+ {
+ av_log(s->avctx, AV_LOG_INFO, "Internal Error: q-matrix blocks must be 16-byte aligned "
+ "to use Altivec DCT. Reverting to non-altivec version.\n");
+ return;
+ }
+
+ if (((long)(s->intra_scantable.inverse) & 0x0f) != 0)
+ {
+ av_log(s->avctx, AV_LOG_INFO, "Internal Error: scan table blocks must be 16-byte aligned "
+ "to use Altivec DCT. Reverting to non-altivec version.\n");
+ return;
+ }
+
+
+ if ((s->avctx->dct_algo == FF_DCT_AUTO) ||
+ (s->avctx->dct_algo == FF_DCT_ALTIVEC))
+ {
+#if 0 /* seems to cause trouble under some circumstances */
+ s->dct_quantize = dct_quantize_altivec;
+#endif
s->dct_unquantize_h263_intra = dct_unquantize_h263_altivec;
s->dct_unquantize_h263_inter = dct_unquantize_h263_altivec;
- }
- } else
-#endif
- {
- /* Non-AltiVec PPC optimisations here */
- }
-}
-
+ }
+ } else
+#endif
+ {
+ /* Non-AltiVec PPC optimisations here */
+ }
+}
+