提交 35e5fb06 编写于 作者: R Romain Dolbeau 提交者: Michael Niedermayer

PPC perf, PPC clear_block, AltiVec put_pixels8_xy2 patch by (Romain Dolbeau...

PPC perf, PPC clear_block, AltiVec put_pixels8_xy2 patch by (Romain Dolbeau <dolbeau at irisa dot fr>)

Originally committed as revision 1476 to svn://svn.ffmpeg.org/ffmpeg/trunk
上级 8c55915b
......@@ -621,6 +621,10 @@ elif test "$cpu" = "sparc64" ; then
elif test "$cpu" = "powerpc" ; then
echo "TARGET_ARCH_POWERPC=yes" >> config.mak
echo "#define ARCH_POWERPC 1" >> $TMPH
echo "// Enable the next line to get PowerPC performance report" >> $TMPH
echo "// #define POWERPC_TBL_PERFORMANCE_REPORT 1" >> $TMPH
echo "// Enable the next line to use PMC registers instead of TBL" >> $TMPH
echo "// #define POWERPC_PERF_USE_PMC 1" >> $TMPH
elif test "$cpu" = "mips" ; then
echo "TARGET_ARCH_MIPS=yes" >> config.mak
echo "#define ARCH_MIPS 1" >> $TMPH
......@@ -644,8 +648,6 @@ fi
if test "$altivec" = "yes" ; then
echo "TARGET_ALTIVEC=yes" >> config.mak
echo "#define HAVE_ALTIVEC 1" >> $TMPH
echo "// Enable the next line to get AltiVec performance report" >> $TMPH
echo "// #define ALTIVEC_TBL_PERFORMANCE_REPORT 1" >> $TMPH
echo "// Enable the next line to use the reference C code instead of AltiVec" >> $TMPH
echo "// #define ALTIVEC_USE_REFERENCE_C_CODE 1" >> $TMPH
fi
......
......@@ -2833,10 +2833,10 @@ int main(int argc, char **argv)
av_free_static();
#ifdef ALTIVEC_TBL_PERFORMANCE_REPORT
extern void altivec_display_perf_report(void);
altivec_display_perf_report();
#endif /* ALTIVEC_TBL_PERFORMANCE_REPORT */
#ifdef POWERPC_TBL_PERFORMANCE_REPORT
extern void powerpc_display_perf_report(void);
powerpc_display_perf_report();
#endif /* POWERPC_TBL_PERFORMANCE_REPORT */
return 0;
}
......@@ -24,22 +24,6 @@
#include <sys/sysctl.h>
#endif
#ifdef ALTIVEC_TBL_PERFORMANCE_REPORT
unsigned long long perfdata[altivec_perf_total][altivec_data_total];
/* list below must match enum in dsputil_altivec.h */
static unsigned char* perfname[] = {
"fft_calc",
"gmc1",
"dct_unquantize_h263",
"idct_add",
"idct_put",
"put_pixels_clamped",
"put_pixels16",
"avg_pixels16"
};
#include <stdio.h>
#endif
int pix_abs16x16_x2_altivec(uint8_t *pix1, uint8_t *pix2, int line_size)
{
int i;
......@@ -648,12 +632,12 @@ extern UINT8 cropTbl[];
void put_pixels_clamped_altivec(const DCTELEM *block, UINT8 *restrict pixels,
int line_size)
{
ALTIVEC_TBL_DECLARE(altivec_put_pixels_clamped_num, 1);
POWERPC_TBL_DECLARE(altivec_put_pixels_clamped_num, 1);
#ifdef ALTIVEC_USE_REFERENCE_C_CODE
int i;
UINT8 *cm = cropTbl + MAX_NEG_CROP;
ALTIVEC_TBL_START_COUNT(altivec_put_pixels_clamped_num, 1);
POWERPC_TBL_START_COUNT(altivec_put_pixels_clamped_num, 1);
/* read the pixels */
for(i=0;i<8;i++) {
......@@ -670,7 +654,7 @@ ALTIVEC_TBL_START_COUNT(altivec_put_pixels_clamped_num, 1);
block += 8;
}
ALTIVEC_TBL_STOP_COUNT(altivec_put_pixels_clamped_num, 1);
POWERPC_TBL_STOP_COUNT(altivec_put_pixels_clamped_num, 1);
#else /* ALTIVEC_USE_REFERENCE_C_CODE */
register const vector short vczero = (const vector short)(0);
......@@ -681,7 +665,7 @@ ALTIVEC_TBL_STOP_COUNT(altivec_put_pixels_clamped_num, 1);
pixelsv0, pixelsv1, pixelsv2, pixelsv3, pixelsv4,
pixelsv0old, pixelsv4old;
ALTIVEC_TBL_START_COUNT(altivec_put_pixels_clamped_num, 1);
POWERPC_TBL_START_COUNT(altivec_put_pixels_clamped_num, 1);
blockv0 = vec_ld(0, block);
blockv1 = vec_ld(16, block);
......@@ -720,17 +704,17 @@ ALTIVEC_TBL_START_COUNT(altivec_put_pixels_clamped_num, 1);
vec_st(pixelsv3, 48, pixels);
}
ALTIVEC_TBL_STOP_COUNT(altivec_put_pixels_clamped_num, 1);
POWERPC_TBL_STOP_COUNT(altivec_put_pixels_clamped_num, 1);
#endif /* ALTIVEC_USE_REFERENCE_C_CODE */
}
void put_pixels16_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h)
{
ALTIVEC_TBL_DECLARE(altivec_put_pixels16_num, 1);
POWERPC_TBL_DECLARE(altivec_put_pixels16_num, 1);
#ifdef ALTIVEC_USE_REFERENCE_C_CODE
int i;
ALTIVEC_TBL_START_COUNT(altivec_put_pixels16_num, 1);
POWERPC_TBL_START_COUNT(altivec_put_pixels16_num, 1);
for(i=0; i<h; i++) {
*((uint32_t*)(block )) = (((const struct unaligned_32 *) (pixels))->l);
......@@ -741,25 +725,24 @@ ALTIVEC_TBL_START_COUNT(altivec_put_pixels16_num, 1);
block +=line_size;
}
ALTIVEC_TBL_STOP_COUNT(altivec_put_pixels16_num, 1);
POWERPC_TBL_STOP_COUNT(altivec_put_pixels16_num, 1);
#else /* ALTIVEC_USE_REFERENCE_C_CODE */
register vector unsigned char perm = vec_lvsl(0, pixels);
register vector unsigned char pixelsv1, pixelsv2;
int i;
ALTIVEC_TBL_START_COUNT(altivec_put_pixels16_num, 1);
POWERPC_TBL_START_COUNT(altivec_put_pixels16_num, 1);
for(i=0; i<h; i++) {
pixelsv1 = vec_ld(0, (unsigned char*)pixels);
pixelsv2 = vec_ld(16, (unsigned char*)pixels);
vec_st(vec_perm(pixelsv1, pixelsv2, perm), 0, (unsigned char*)block);
vec_st(vec_perm(pixelsv1, pixelsv2, vec_lvsl(0, pixels)),
0, (unsigned char*)block);
pixels+=line_size;
block +=line_size;
}
ALTIVEC_TBL_STOP_COUNT(altivec_put_pixels16_num, 1);
POWERPC_TBL_STOP_COUNT(altivec_put_pixels16_num, 1);
#endif /* ALTIVEC_USE_REFERENCE_C_CODE */
}
......@@ -767,11 +750,11 @@ ALTIVEC_TBL_STOP_COUNT(altivec_put_pixels16_num, 1);
#define op_avg(a,b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEUL)>>1) )
void avg_pixels16_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h)
{
ALTIVEC_TBL_DECLARE(altivec_avg_pixels16_num, 1);
POWERPC_TBL_DECLARE(altivec_avg_pixels16_num, 1);
#ifdef ALTIVEC_USE_REFERENCE_C_CODE
int i;
ALTIVEC_TBL_START_COUNT(altivec_avg_pixels16_num, 1);
POWERPC_TBL_START_COUNT(altivec_avg_pixels16_num, 1);
for(i=0; i<h; i++) {
op_avg(*((uint32_t*)(block)),(((const struct unaligned_32 *)(pixels))->l));
......@@ -782,32 +765,210 @@ ALTIVEC_TBL_START_COUNT(altivec_avg_pixels16_num, 1);
block +=line_size;
}
ALTIVEC_TBL_STOP_COUNT(altivec_avg_pixels16_num, 1);
POWERPC_TBL_STOP_COUNT(altivec_avg_pixels16_num, 1);
#else /* ALTIVEC_USE_REFERENCE_C_CODE */
register vector unsigned char perm = vec_lvsl(0, pixels);
register vector unsigned char pixelsv1, pixelsv2, pixelsv, blockv;
int i;
ALTIVEC_TBL_START_COUNT(altivec_avg_pixels16_num, 1);
POWERPC_TBL_START_COUNT(altivec_avg_pixels16_num, 1);
for(i=0; i<h; i++) {
pixelsv1 = vec_ld(0, (unsigned char*)pixels);
pixelsv2 = vec_ld(16, (unsigned char*)pixels);
blockv = vec_ld(0, block);
pixelsv = vec_perm(pixelsv1, pixelsv2, perm);
pixelsv = vec_perm(pixelsv1, pixelsv2, vec_lvsl(0, pixels));
blockv = vec_avg(blockv,pixelsv);
vec_st(blockv, 0, (unsigned char*)block);
pixels+=line_size;
block +=line_size;
}
ALTIVEC_TBL_STOP_COUNT(altivec_avg_pixels16_num, 1);
POWERPC_TBL_STOP_COUNT(altivec_avg_pixels16_num, 1);
#endif /* ALTIVEC_USE_REFERENCE_C_CODE */
}
void avg_pixels8_altivec(uint8_t * block, const uint8_t * pixels,
int line_size, int h)
{
POWERPC_TBL_DECLARE(altivec_avg_pixels8_num, 1);
#ifdef ALTIVEC_USE_REFERENCE_C_CODE
int i;
POWERPC_TBL_START_COUNT(altivec_avg_pixels8_num, 1);
for (i = 0; i < h; i++) {
*((uint32_t *) (block)) =
(((*((uint32_t *) (block))) |
((((const struct unaligned_32 *) (pixels))->l))) -
((((*((uint32_t *) (block))) ^
((((const struct unaligned_32 *) (pixels))->
l))) & 0xFEFEFEFEUL) >> 1));
*((uint32_t *) (block + 4)) =
(((*((uint32_t *) (block + 4))) |
((((const struct unaligned_32 *) (pixels + 4))->l))) -
((((*((uint32_t *) (block + 4))) ^
((((const struct unaligned_32 *) (pixels +
4))->
l))) & 0xFEFEFEFEUL) >> 1));
pixels += line_size;
block += line_size;
}
POWERPC_TBL_STOP_COUNT(altivec_avg_pixels8_num, 1);
#else /* ALTIVEC_USE_REFERENCE_C_CODE */
register vector unsigned char pixelsv1, pixelsv2, pixelsv, blockv;
int i;
POWERPC_TBL_START_COUNT(altivec_avg_pixels8_num, 1);
for (i = 0; i < h; i++) {
/*
block is 8 bytes-aligned, so we're either in the
left block (16 bytes-aligned) or in the right block (not)
*/
int rightside = ((unsigned long)block & 0x0000000F);
blockv = vec_ld(0, block);
pixelsv1 = vec_ld(0, (unsigned char*)pixels);
pixelsv2 = vec_ld(16, (unsigned char*)pixels);
pixelsv = vec_perm(pixelsv1, pixelsv2, vec_lvsl(0, pixels));
if (rightside)
{
pixelsv = vec_perm(blockv, pixelsv, vcprm(0,1,s0,s1));
}
else
{
pixelsv = vec_perm(blockv, pixelsv, vcprm(s0,s1,2,3));
}
blockv = vec_avg(blockv, pixelsv);
vec_st(blockv, 0, block);
pixels += line_size;
block += line_size;
}
POWERPC_TBL_STOP_COUNT(altivec_avg_pixels8_num, 1);
#endif /* ALTIVEC_USE_REFERENCE_C_CODE */
}
void put_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h)
{
POWERPC_TBL_DECLARE(altivec_put_pixels8_xy2_num, 1);
#ifdef ALTIVEC_USE_REFERENCE_C_CODE
int j;
POWERPC_TBL_START_COUNT(altivec_put_pixels8_xy2_num, 1);
for (j = 0; j < 2; j++) {
int i;
const uint32_t a = (((const struct unaligned_32 *) (pixels))->l);
const uint32_t b =
(((const struct unaligned_32 *) (pixels + 1))->l);
uint32_t l0 =
(a & 0x03030303UL) + (b & 0x03030303UL) + 0x02020202UL;
uint32_t h0 =
((a & 0xFCFCFCFCUL) >> 2) + ((b & 0xFCFCFCFCUL) >> 2);
uint32_t l1, h1;
pixels += line_size;
for (i = 0; i < h; i += 2) {
uint32_t a = (((const struct unaligned_32 *) (pixels))->l);
uint32_t b = (((const struct unaligned_32 *) (pixels + 1))->l);
l1 = (a & 0x03030303UL) + (b & 0x03030303UL);
h1 = ((a & 0xFCFCFCFCUL) >> 2) + ((b & 0xFCFCFCFCUL) >> 2);
*((uint32_t *) block) =
h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL);
pixels += line_size;
block += line_size;
a = (((const struct unaligned_32 *) (pixels))->l);
b = (((const struct unaligned_32 *) (pixels + 1))->l);
l0 = (a & 0x03030303UL) + (b & 0x03030303UL) + 0x02020202UL;
h0 = ((a & 0xFCFCFCFCUL) >> 2) + ((b & 0xFCFCFCFCUL) >> 2);
*((uint32_t *) block) =
h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL);
pixels += line_size;
block += line_size;
} pixels += 4 - line_size * (h + 1);
block += 4 - line_size * h;
}
POWERPC_TBL_STOP_COUNT(altivec_put_pixels8_xy2_num, 1);
#else /* ALTIVEC_USE_REFERENCE_C_CODE */
register int i;
register vector unsigned char
pixelsv1, pixelsv2,
pixelsavg;
register vector unsigned char
blockv, temp1, temp2;
register vector unsigned short
pixelssum1, pixelssum2, temp3;
register const vector unsigned char vczero = (const vector unsigned char)(0);
register const vector unsigned short vctwo = (const vector unsigned short)(2);
temp1 = vec_ld(0, pixels);
temp2 = vec_ld(16, pixels);
pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(0, pixels));
if ((((unsigned long)pixels) & 0x0000000F) == 0x0000000F)
{
pixelsv2 = temp2;
}
else
{
pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(1, pixels));
}
pixelsv1 = vec_mergeh(vczero, pixelsv1);
pixelsv2 = vec_mergeh(vczero, pixelsv2);
pixelssum1 = vec_add((vector unsigned short)pixelsv1,
(vector unsigned short)pixelsv2);
pixelssum1 = vec_add(pixelssum1, vctwo);
POWERPC_TBL_START_COUNT(altivec_put_pixels8_xy2_num, 1);
for (i = 0; i < h ; i++) {
int rightside = ((unsigned long)block & 0x0000000F);
blockv = vec_ld(0, block);
temp1 = vec_ld(line_size, pixels);
temp2 = vec_ld(line_size + 16, pixels);
pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(line_size, pixels));
if (((((unsigned long)pixels) + line_size) & 0x0000000F) == 0x0000000F)
{
pixelsv2 = temp2;
}
else
{
pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(line_size + 1, pixels));
}
pixelsv1 = vec_mergeh(vczero, pixelsv1);
pixelsv2 = vec_mergeh(vczero, pixelsv2);
pixelssum2 = vec_add((vector unsigned short)pixelsv1,
(vector unsigned short)pixelsv2);
temp3 = vec_add(pixelssum1, pixelssum2);
temp3 = vec_sra(temp3, vctwo);
pixelssum1 = vec_add(pixelssum2, vctwo);
pixelsavg = vec_packsu(temp3, (vector unsigned short) vczero);
if (rightside)
{
blockv = vec_perm(blockv, pixelsavg, vcprm(0, 1, s0, s1));
}
else
{
blockv = vec_perm(blockv, pixelsavg, vcprm(s0, s1, 2, 3));
}
vec_st(blockv, 0, block);
block += line_size;
pixels += line_size;
}
POWERPC_TBL_STOP_COUNT(altivec_put_pixels8_xy2_num, 1);
#endif /* ALTIVEC_USE_REFERENCE_C_CODE */
}
int has_altivec(void)
{
#if CONFIG_DARWIN
......@@ -822,22 +983,3 @@ int has_altivec(void)
#endif
return 0;
}
#ifdef ALTIVEC_TBL_PERFORMANCE_REPORT
void altivec_display_perf_report(void)
{
int i;
fprintf(stderr, "AltiVec performance report\n Values are from the Time Base register, and represent 4 bus cycles.\n");
for(i = 0 ; i < altivec_perf_total ; i++)
{
if (perfdata[i][altivec_data_num] != (unsigned long long)0)
fprintf(stderr, " Function \"%s\":\n\tmin: %llu\n\tmax: %llu\n\tavg: %1.2lf (%llu)\n",
perfname[i],
perfdata[i][altivec_data_min],
perfdata[i][altivec_data_max],
(double)perfdata[i][altivec_data_sum] /
(double)perfdata[i][altivec_data_num],
perfdata[i][altivec_data_num]);
}
}
#endif /* ALTIVEC_TBL_PERFORMANCE_REPORT */
......@@ -17,6 +17,13 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _DSPUTIL_ALTIVEC_
#define _DSPUTIL_ALTIVEC_
#include "dsputil_ppc.h"
#ifdef HAVE_ALTIVEC
extern int pix_abs16x16_x2_altivec(uint8_t *pix1, uint8_t *pix2, int line_size);
extern int pix_abs16x16_y2_altivec(uint8_t *pix1, uint8_t *pix2, int line_size);
extern int pix_abs16x16_xy2_altivec(uint8_t *pix1, uint8_t *pix2, int line_size);
......@@ -33,15 +40,15 @@ extern void get_pixels_altivec(DCTELEM* block, const UINT8 * pixels, int line_si
extern void add_bytes_altivec(uint8_t *dst, uint8_t *src, int w);
extern void put_pixels_clamped_altivec(const DCTELEM *block, UINT8 *restrict pixels, int line_size);
void put_pixels16_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h);
void avg_pixels16_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h);
extern void put_pixels16_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h);
extern void avg_pixels16_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h);
extern void avg_pixels8_altivec(uint8_t * block, const uint8_t * pixels, int line_size, int h);
extern void put_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h);
extern void gmc1_altivec(UINT8 *dst, UINT8 *src, int stride, int h, int x16, int y16, int rounder);
extern int has_altivec(void);
#ifdef HAVE_ALTIVEC
// used to build registers permutation vectors (vcprm)
// the 's' are for words in the _s_econd vector
#define WORD_0 0x00,0x01,0x02,0x03
......@@ -67,58 +74,10 @@ extern int has_altivec(void);
#define vcii(a,b,c,d) (const vector float)(FLOAT_ ## a, FLOAT_ ## b, FLOAT_ ## c, FLOAT_ ## d)
#ifdef ALTIVEC_TBL_PERFORMANCE_REPORT
void altivec_display_perf_report(void);
/* if you add to the enum below, also add to the perfname array
in dsputil_altivec.c */
enum altivec_perf_index {
altivec_fft_num = 0,
altivec_gmc1_num,
altivec_dct_unquantize_h263_num,
altivec_idct_add_num,
altivec_idct_put_num,
altivec_put_pixels_clamped_num,
altivec_put_pixels16_num,
altivec_avg_pixels16_num,
altivec_perf_total
};
enum altivec_data_index {
altivec_data_min = 0,
altivec_data_max,
altivec_data_sum,
altivec_data_num,
altivec_data_total
};
extern unsigned long long perfdata[altivec_perf_total][altivec_data_total];
#define ALTIVEC_TBL_DECLARE(a, cond) register unsigned long tbl_start, tbl_stop
#define ALTIVEC_TBL_START_COUNT(a, cond) do { asm("mftb %0" : "=r" (tbl_start)); } while (0)
#define ALTIVEC_TBL_STOP_COUNT(a, cond) do { \
asm volatile("mftb %0" : "=r" (tbl_stop)); \
if (tbl_stop > tbl_start) \
{ \
unsigned long diff = tbl_stop - tbl_start; \
if (cond) \
{ \
if (diff < perfdata[a][altivec_data_min]) \
perfdata[a][altivec_data_min] = diff; \
if (diff > perfdata[a][altivec_data_max]) \
perfdata[a][altivec_data_max] = diff; \
perfdata[a][altivec_data_sum] += diff; \
perfdata[a][altivec_data_num] ++; \
} \
} \
} while (0)
#else /* ALTIVEC_TBL_PERFORMANCE_REPORT */
#define ALTIVEC_TBL_DECLARE(a, cond)
#define ALTIVEC_TBL_START_COUNT(a, cond)
#define ALTIVEC_TBL_STOP_COUNT(a, cond)
#endif /* ALTIVEC_TBL_PERFORMANCE_REPORT */
#else /* HAVE_ALTIVEC */
#ifdef ALTIVEC_USE_REFERENCE_C_CODE
#error "I can't use ALTIVEC_USE_REFERENCE_C_CODE if I don't use HAVE_ALTIVEC"
#endif /* ALTIVEC_USE_REFERENCE_C_CODE */
#ifdef ALTIVEC_TBL_PERFORMANCE_REPORT
#error "I can't use ALTIVEC_TBL_PERFORMANCE_REPORT if I don't use HAVE_ALTIVEC"
#endif /* ALTIVEC_TBL_PERFORMANCE_REPORT */
#endif /* HAVE_ALTIVEC */
#endif /* _DSPUTIL_ALTIVEC_ */
......@@ -19,6 +19,8 @@
#include "../dsputil.h"
#include "dsputil_ppc.h"
#ifdef HAVE_ALTIVEC
#include "dsputil_altivec.h"
#endif
......@@ -36,12 +38,149 @@ int mm_support(void)
return result;
}
#ifdef POWERPC_TBL_PERFORMANCE_REPORT
unsigned long long perfdata[powerpc_perf_total][powerpc_data_total];
/* list below must match enum in dsputil_altivec.h */
static unsigned char* perfname[] = {
"fft_calc_altivec",
"gmc1_altivec",
"dct_unquantize_h263_altivec",
"idct_add_altivec",
"idct_put_altivec",
"put_pixels_clamped_altivec",
"put_pixels16_altivec",
"avg_pixels16_altivec",
"avg_pixels8_altivec",
"put_pixels8_xy2_altivec",
"clear_blocks_dcbz32_ppc"
};
#ifdef POWERPC_PERF_USE_PMC
unsigned long long perfdata_miss[powerpc_perf_total][powerpc_data_total];
#endif
#include <stdio.h>
#endif
#ifdef POWERPC_TBL_PERFORMANCE_REPORT
void powerpc_display_perf_report(void)
{
int i;
#ifndef POWERPC_PERF_USE_PMC
fprintf(stderr, "AltiVec performance report\n Values are from the Time Base register, and represent 4 bus cycles.\n");
#else /* POWERPC_PERF_USE_PMC */
fprintf(stderr, "AltiVec performance report\n Values are from the PMC registers, and represent whatever the registers are set to record.\n");
#endif /* POWERPC_PERF_USE_PMC */
for(i = 0 ; i < powerpc_perf_total ; i++)
{
if (perfdata[i][powerpc_data_num] != (unsigned long long)0)
fprintf(stderr, " Function \"%s\" (pmc1):\n\tmin: %llu\n\tmax: %llu\n\tavg: %1.2lf (%llu)\n",
perfname[i],
perfdata[i][powerpc_data_min],
perfdata[i][powerpc_data_max],
(double)perfdata[i][powerpc_data_sum] /
(double)perfdata[i][powerpc_data_num],
perfdata[i][powerpc_data_num]);
#ifdef POWERPC_PERF_USE_PMC
if (perfdata_miss[i][powerpc_data_num] != (unsigned long long)0)
fprintf(stderr, " Function \"%s\" (pmc2):\n\tmin: %llu\n\tmax: %llu\n\tavg: %1.2lf (%llu)\n",
perfname[i],
perfdata_miss[i][powerpc_data_min],
perfdata_miss[i][powerpc_data_max],
(double)perfdata_miss[i][powerpc_data_sum] /
(double)perfdata_miss[i][powerpc_data_num],
perfdata_miss[i][powerpc_data_num]);
#endif
}
}
#endif /* POWERPC_TBL_PERFORMANCE_REPORT */
/* ***** WARNING ***** WARNING ***** WARNING ***** */
/*
clear_blocks_dcbz32_ppc will not work properly
on PowerPC processors with a cache line size
not equal to 32 bytes.
Fortunately all processor used by Apple up to
at least the 7450 (aka second generation G4)
use 32 bytes cache line.
This is due to the use of the 'dcbz' instruction.
It simply clear to zero a single cache line,
so you need to know the cache line size to use it !
It's absurd, but it's fast...
*/
void clear_blocks_dcbz32_ppc(DCTELEM *blocks)
{
POWERPC_TBL_DECLARE(powerpc_clear_blocks_dcbz32, 1);
register int misal = ((unsigned long)blocks & 0x00000010);
register int i = 0;
POWERPC_TBL_START_COUNT(powerpc_clear_blocks_dcbz32, 1);
#if 1
if (misal) {
((unsigned long*)blocks)[0] = 0L;
((unsigned long*)blocks)[1] = 0L;
((unsigned long*)blocks)[2] = 0L;
((unsigned long*)blocks)[3] = 0L;
vec_st((vector short)(0), 0, blocks);
i += 16;
}
for ( ; i < sizeof(DCTELEM)*6*64 ; i += 32) {
asm volatile("dcbz %0,%1" : : "r" (blocks), "r" (i) : "memory");
}
if (misal) {
((unsigned long*)blocks)[188] = 0L;
((unsigned long*)blocks)[189] = 0L;
((unsigned long*)blocks)[190] = 0L;
((unsigned long*)blocks)[191] = 0L;
i += 16;
}
#else
memset(blocks, 0, sizeof(DCTELEM)*6*64);
#endif
POWERPC_TBL_STOP_COUNT(powerpc_clear_blocks_dcbz32, 1);
}
/* check dcbz report how many bytes are set to 0 by dcbz */
long check_dcbz_effect(void)
{
register char *fakedata = (char*)malloc(1024);
register char *fakedata_middle;
register long zero = 0;
register long i = 0;
long count = 0;
if (fakedata == NULL)
{
return 0L;
}
fakedata_middle = (fakedata + 512);
memset(fakedata, 0xFF, 1024);
asm volatile("dcbz %0, %1" : : "r" (fakedata_middle), "r" (zero));
for (i = 0; i < 1024 ; i ++)
{
if (fakedata[i] == (char)0)
count++;
}
free(fakedata);
return count;
}
void dsputil_init_ppc(DSPContext* c, unsigned mask)
{
// Common optimisations whether Altivec or not
// ... pending ...
switch (check_dcbz_effect()) {
case 32:
c->clear_blocks = clear_blocks_dcbz32_ppc;
break;
default:
break;
}
#if HAVE_ALTIVEC
if (has_altivec()) {
mm_flags |= MM_ALTIVEC;
......@@ -67,17 +206,29 @@ void dsputil_init_ppc(DSPContext* c, unsigned mask)
#endif
c->put_pixels_tab[0][0] = put_pixels16_altivec;
c->avg_pixels_tab[0][0] = avg_pixels16_altivec;
// next one disabled as it's untested.
#if 0
c->avg_pixels_tab[1][0] = avg_pixels8_altivec;
#endif
c->put_pixels_tab[1][3] = put_pixels8_xy2_altivec;
c->gmc1 = gmc1_altivec;
#ifdef ALTIVEC_TBL_PERFORMANCE_REPORT
#ifdef POWERPC_TBL_PERFORMANCE_REPORT
{
int i;
for (i = 0 ; i < altivec_perf_total ; i++)
for (i = 0 ; i < powerpc_perf_total ; i++)
{
perfdata[i][altivec_data_min] = 0xFFFFFFFFFFFFFFFF;
perfdata[i][altivec_data_max] = 0x0000000000000000;
perfdata[i][altivec_data_sum] = 0x0000000000000000;
perfdata[i][altivec_data_num] = 0x0000000000000000;
perfdata[i][powerpc_data_min] = 0xFFFFFFFFFFFFFFFF;
perfdata[i][powerpc_data_max] = 0x0000000000000000;
perfdata[i][powerpc_data_sum] = 0x0000000000000000;
perfdata[i][powerpc_data_num] = 0x0000000000000000;
#ifdef POWERPC_PERF_USE_PMC
perfdata_miss[i][powerpc_data_min] = 0xFFFFFFFFFFFFFFFF;
perfdata_miss[i][powerpc_data_max] = 0x0000000000000000;
perfdata_miss[i][powerpc_data_sum] = 0x0000000000000000;
perfdata_miss[i][powerpc_data_num] = 0x0000000000000000;
#endif
}
}
#endif
......
/*
* 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
* 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
*/
#ifndef _DSPUTIL_PPC_
#define _DSPUTIL_PPC_
#ifdef POWERPC_TBL_PERFORMANCE_REPORT
void powerpc_display_perf_report(void);
/* if you add to the enum below, also add to the perfname array
in dsputil_ppc.c */
enum powerpc_perf_index {
altivec_fft_num = 0,
altivec_gmc1_num,
altivec_dct_unquantize_h263_num,
altivec_idct_add_num,
altivec_idct_put_num,
altivec_put_pixels_clamped_num,
altivec_put_pixels16_num,
altivec_avg_pixels16_num,
altivec_avg_pixels8_num,
altivec_put_pixels8_xy2_num,
powerpc_clear_blocks_dcbz32,
powerpc_perf_total
};
enum powerpc_data_index {
powerpc_data_min = 0,
powerpc_data_max,
powerpc_data_sum,
powerpc_data_num,
powerpc_data_total
};
extern unsigned long long perfdata[powerpc_perf_total][powerpc_data_total];
#ifdef POWERPC_PERF_USE_PMC
extern unsigned long long perfdata_miss[powerpc_perf_total][powerpc_data_total];
#endif
#ifndef POWERPC_PERF_USE_PMC
#define POWERPC_GET_CYCLES(a) asm volatile("mftb %0" : "=r" (a))
#define POWERPC_TBL_DECLARE(a, cond) register unsigned long tbl_start, tbl_stop
#define POWERPC_TBL_START_COUNT(a, cond) do { POWERPC_GET_CYCLES(tbl_start); } while (0)
#define POWERPC_TBL_STOP_COUNT(a, cond) do { \
POWERPC_GET_CYCLES(tbl_stop); \
if (tbl_stop > tbl_start) \
{ \
unsigned long diff = tbl_stop - tbl_start; \
if (cond) \
{ \
if (diff < perfdata[a][powerpc_data_min]) \
perfdata[a][powerpc_data_min] = diff; \
if (diff > perfdata[a][powerpc_data_max]) \
perfdata[a][powerpc_data_max] = diff; \
perfdata[a][powerpc_data_sum] += diff; \
perfdata[a][powerpc_data_num] ++; \
} \
} \
} while (0)
#else /* POWERPC_PERF_USE_PMC */
#define POWERPC_GET_CYCLES(a) asm volatile("mfspr %0, 937" : "=r" (a))
#define POWERPC_GET_MISS(a) asm volatile("mfspr %0, 938" : "=r" (a))
#define POWERPC_TBL_DECLARE(a, cond) register unsigned long cycles_start, cycles_stop, miss_start, miss_stop;
#define POWERPC_TBL_START_COUNT(a, cond) do { POWERPC_GET_MISS(miss_start); POWERPC_GET_CYCLES(cycles_start); } while (0)
#define POWERPC_TBL_STOP_COUNT(a, cond) do { \
POWERPC_GET_CYCLES(cycles_stop); \
POWERPC_GET_MISS(miss_stop); \
if (cycles_stop >= cycles_start) \
{ \
unsigned long diff = \
cycles_stop - cycles_start; \
if (cond) \
{ \
if (diff < perfdata[a][powerpc_data_min]) \
perfdata[a][powerpc_data_min] = diff; \
if (diff > perfdata[a][powerpc_data_max]) \
perfdata[a][powerpc_data_max] = diff; \
perfdata[a][powerpc_data_sum] += diff; \
perfdata[a][powerpc_data_num] ++; \
} \
} \
if (miss_stop >= miss_start) \
{ \
unsigned long diff = \
miss_stop - miss_start; \
if (cond) \
{ \
if (diff < perfdata_miss[a][powerpc_data_min]) \
perfdata_miss[a][powerpc_data_min] = diff; \
if (diff > perfdata_miss[a][powerpc_data_max]) \
perfdata_miss[a][powerpc_data_max] = diff; \
perfdata_miss[a][powerpc_data_sum] += diff; \
perfdata_miss[a][powerpc_data_num] ++; \
} \
} \
} while (0)
#endif /* POWERPC_PERF_USE_PMC */
#else /* POWERPC_TBL_PERFORMANCE_REPORT */
#define POWERPC_TBL_DECLARE(a, cond)
#define POWERPC_TBL_START_COUNT(a, cond)
#define POWERPC_TBL_STOP_COUNT(a, cond)
#endif /* POWERPC_TBL_PERFORMANCE_REPORT */
#endif /* _DSPUTIL_PPC_ */
......@@ -60,7 +60,7 @@
*/
void fft_calc_altivec(FFTContext *s, FFTComplex *z)
{
ALTIVEC_TBL_DECLARE(altivec_fft_num, s->nbits >= 6);
POWERPC_TBL_DECLARE(altivec_fft_num, s->nbits >= 6);
#ifdef ALTIVEC_USE_REFERENCE_C_CODE
int ln = s->nbits;
int j, np, np2;
......@@ -70,7 +70,7 @@ ALTIVEC_TBL_DECLARE(altivec_fft_num, s->nbits >= 6);
int l;
FFTSample tmp_re, tmp_im;
ALTIVEC_TBL_START_COUNT(altivec_fft_num, s->nbits >= 6);
POWERPC_TBL_START_COUNT(altivec_fft_num, s->nbits >= 6);
np = 1 << ln;
......@@ -135,7 +135,7 @@ ALTIVEC_TBL_START_COUNT(altivec_fft_num, s->nbits >= 6);
nloops = nloops << 1;
} while (nblocks != 0);
ALTIVEC_TBL_STOP_COUNT(altivec_fft_num, s->nbits >= 6);
POWERPC_TBL_STOP_COUNT(altivec_fft_num, s->nbits >= 6);
#else /* ALTIVEC_USE_REFERENCE_C_CODE */
register const vector float vczero = (const vector float)(0.);
......@@ -147,7 +147,7 @@ ALTIVEC_TBL_STOP_COUNT(altivec_fft_num, s->nbits >= 6);
FFTComplex *cptr, *cptr1;
int k;
ALTIVEC_TBL_START_COUNT(altivec_fft_num, s->nbits >= 6);
POWERPC_TBL_START_COUNT(altivec_fft_num, s->nbits >= 6);
np = 1 << ln;
......@@ -235,7 +235,7 @@ ALTIVEC_TBL_START_COUNT(altivec_fft_num, s->nbits >= 6);
nloops = nloops << 1;
} while (nblocks != 0);
ALTIVEC_TBL_STOP_COUNT(altivec_fft_num, s->nbits >= 6);
POWERPC_TBL_STOP_COUNT(altivec_fft_num, s->nbits >= 6);
#endif /* ALTIVEC_USE_REFERENCE_C_CODE */
}
......@@ -28,7 +28,7 @@
*/
void gmc1_altivec(UINT8 *dst /* align 8 */, UINT8 *src /* align1 */, int stride, int h, int x16, int y16, int rounder)
{
ALTIVEC_TBL_DECLARE(altivec_gmc1_num, h == 8);
POWERPC_TBL_DECLARE(altivec_gmc1_num, h == 8);
#ifdef ALTIVEC_USE_REFERENCE_C_CODE
const int A=(16-x16)*(16-y16);
const int B=( x16)*(16-y16);
......@@ -36,7 +36,7 @@ ALTIVEC_TBL_DECLARE(altivec_gmc1_num, h == 8);
const int D=( x16)*( y16);
int i;
ALTIVEC_TBL_START_COUNT(altivec_gmc1_num, h == 8);
POWERPC_TBL_START_COUNT(altivec_gmc1_num, h == 8);
for(i=0; i<h; i++)
{
......@@ -52,7 +52,7 @@ ALTIVEC_TBL_START_COUNT(altivec_gmc1_num, h == 8);
src+= stride;
}
ALTIVEC_TBL_STOP_COUNT(altivec_gmc1_num, h == 8);
POWERPC_TBL_STOP_COUNT(altivec_gmc1_num, h == 8);
#else /* ALTIVEC_USE_REFERENCE_C_CODE */
const unsigned short __attribute__ ((aligned(16))) rounder_a[8] =
......@@ -75,7 +75,7 @@ ALTIVEC_TBL_STOP_COUNT(altivec_gmc1_num, h == 8);
unsigned long src_really_odd = (unsigned long)src & 0x0000000F;
ALTIVEC_TBL_START_COUNT(altivec_gmc1_num, h == 8);
POWERPC_TBL_START_COUNT(altivec_gmc1_num, h == 8);
tempA = vec_ld(0, (unsigned short*)ABCD);
Av = vec_splat(tempA, 0);
......@@ -163,7 +163,7 @@ ALTIVEC_TBL_START_COUNT(altivec_gmc1_num, h == 8);
src += stride;
}
ALTIVEC_TBL_STOP_COUNT(altivec_gmc1_num, h == 8);
POWERPC_TBL_STOP_COUNT(altivec_gmc1_num, h == 8);
#endif /* ALTIVEC_USE_REFERENCE_C_CODE */
}
......@@ -161,16 +161,16 @@ static const vector_s16_t constants[5] = {
void idct_put_altivec(uint8_t* dest, int stride, vector_s16_t* block)
{
ALTIVEC_TBL_DECLARE(altivec_idct_put_num, 1);
POWERPC_TBL_DECLARE(altivec_idct_put_num, 1);
#ifdef ALTIVEC_USE_REFERENCE_C_CODE
ALTIVEC_TBL_START_COUNT(altivec_idct_put_num, 1);
POWERPC_TBL_START_COUNT(altivec_idct_put_num, 1);
void simple_idct_put(UINT8 *dest, int line_size, INT16 *block);
simple_idct_put(dest, stride, (INT16*)block);
ALTIVEC_TBL_STOP_COUNT(altivec_idct_put_num, 1);
POWERPC_TBL_STOP_COUNT(altivec_idct_put_num, 1);
#else /* ALTIVEC_USE_REFERENCE_C_CODE */
vector_u8_t tmp;
ALTIVEC_TBL_START_COUNT(altivec_idct_put_num, 1);
POWERPC_TBL_START_COUNT(altivec_idct_put_num, 1);
IDCT
......@@ -188,18 +188,18 @@ ALTIVEC_TBL_START_COUNT(altivec_idct_put_num, 1);
COPY (dest, vx6) dest += stride;
COPY (dest, vx7)
ALTIVEC_TBL_STOP_COUNT(altivec_idct_put_num, 1);
POWERPC_TBL_STOP_COUNT(altivec_idct_put_num, 1);
#endif /* ALTIVEC_USE_REFERENCE_C_CODE */
}
void idct_add_altivec(uint8_t* dest, int stride, vector_s16_t* block)
{
ALTIVEC_TBL_DECLARE(altivec_idct_add_num, 1);
POWERPC_TBL_DECLARE(altivec_idct_add_num, 1);
#ifdef ALTIVEC_USE_REFERENCE_C_CODE
ALTIVEC_TBL_START_COUNT(altivec_idct_add_num, 1);
POWERPC_TBL_START_COUNT(altivec_idct_add_num, 1);
void simple_idct_add(UINT8 *dest, int line_size, INT16 *block);
simple_idct_add(dest, stride, (INT16*)block);
ALTIVEC_TBL_STOP_COUNT(altivec_idct_add_num, 1);
POWERPC_TBL_STOP_COUNT(altivec_idct_add_num, 1);
#else /* ALTIVEC_USE_REFERENCE_C_CODE */
vector_u8_t tmp;
vector_s16_t tmp2, tmp3;
......@@ -207,7 +207,7 @@ ALTIVEC_TBL_STOP_COUNT(altivec_idct_add_num, 1);
vector_u8_t perm1;
vector_u8_t p0, p1, p;
ALTIVEC_TBL_START_COUNT(altivec_idct_add_num, 1);
POWERPC_TBL_START_COUNT(altivec_idct_add_num, 1);
IDCT
......@@ -235,7 +235,7 @@ ALTIVEC_TBL_START_COUNT(altivec_idct_add_num, 1);
ADD (dest, vx6, perm0) dest += stride;
ADD (dest, vx7, perm1)
ALTIVEC_TBL_STOP_COUNT(altivec_idct_add_num, 1);
POWERPC_TBL_STOP_COUNT(altivec_idct_add_num, 1);
#endif /* ALTIVEC_USE_REFERENCE_C_CODE */
}
......@@ -511,13 +511,13 @@ int dct_quantize_altivec(MpegEncContext* s,
void dct_unquantize_h263_altivec(MpegEncContext *s,
DCTELEM *block, int n, int qscale)
{
ALTIVEC_TBL_DECLARE(altivec_dct_unquantize_h263_num, 1);
POWERPC_TBL_DECLARE(altivec_dct_unquantize_h263_num, 1);
int i, level, qmul, qadd;
int nCoeffs;
assert(s->block_last_index[n]>=0);
ALTIVEC_TBL_START_COUNT(altivec_dct_unquantize_h263_num, 1);
POWERPC_TBL_START_COUNT(altivec_dct_unquantize_h263_num, 1);
qadd = (qscale - 1) | 1;
qmul = qscale << 1;
......@@ -630,5 +630,5 @@ ALTIVEC_TBL_START_COUNT(altivec_dct_unquantize_h263_num, 1);
}
#endif /* ALTIVEC_USE_REFERENCE_C_CODE */
ALTIVEC_TBL_STOP_COUNT(altivec_dct_unquantize_h263_num, nCoeffs == 63);
POWERPC_TBL_STOP_COUNT(altivec_dct_unquantize_h263_num, nCoeffs == 63);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册