00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "libavutil/x86_cpu.h"
00023 #include "libavcodec/dsputil.h"
00024 #include "libavcodec/mlp.h"
00025
00026 #if HAVE_7REGS && HAVE_TEN_OPERANDS
00027
00028 extern void ff_mlp_firorder_8;
00029 extern void ff_mlp_firorder_7;
00030 extern void ff_mlp_firorder_6;
00031 extern void ff_mlp_firorder_5;
00032 extern void ff_mlp_firorder_4;
00033 extern void ff_mlp_firorder_3;
00034 extern void ff_mlp_firorder_2;
00035 extern void ff_mlp_firorder_1;
00036 extern void ff_mlp_firorder_0;
00037
00038 extern void ff_mlp_iirorder_4;
00039 extern void ff_mlp_iirorder_3;
00040 extern void ff_mlp_iirorder_2;
00041 extern void ff_mlp_iirorder_1;
00042 extern void ff_mlp_iirorder_0;
00043
00044 static const void *firtable[9] = { &ff_mlp_firorder_0, &ff_mlp_firorder_1,
00045 &ff_mlp_firorder_2, &ff_mlp_firorder_3,
00046 &ff_mlp_firorder_4, &ff_mlp_firorder_5,
00047 &ff_mlp_firorder_6, &ff_mlp_firorder_7,
00048 &ff_mlp_firorder_8 };
00049 static const void *iirtable[5] = { &ff_mlp_iirorder_0, &ff_mlp_iirorder_1,
00050 &ff_mlp_iirorder_2, &ff_mlp_iirorder_3,
00051 &ff_mlp_iirorder_4 };
00052
00053 #if ARCH_X86_64
00054
00055 #define MLPMUL(label, offset, offs, offc) \
00056 LABEL_MANGLE(label)": \n\t" \
00057 "movslq "offset"+"offs"(%0), %%rax\n\t" \
00058 "movslq "offset"+"offc"(%1), %%rdx\n\t" \
00059 "imul %%rdx, %%rax\n\t" \
00060 "add %%rax, %%rsi\n\t"
00061
00062 #define FIRMULREG(label, offset, firc)\
00063 LABEL_MANGLE(label)": \n\t" \
00064 "movslq "#offset"(%0), %%rax\n\t" \
00065 "imul %"#firc", %%rax\n\t" \
00066 "add %%rax, %%rsi\n\t"
00067
00068 #define CLEAR_ACCUM \
00069 "xor %%rsi, %%rsi\n\t"
00070
00071 #define SHIFT_ACCUM \
00072 "shr %%cl, %%rsi\n\t"
00073
00074 #define ACCUM "%%rdx"
00075 #define RESULT "%%rsi"
00076 #define RESULT32 "%%esi"
00077
00078 #else
00079
00080 #define MLPMUL(label, offset, offs, offc) \
00081 LABEL_MANGLE(label)": \n\t" \
00082 "mov "offset"+"offs"(%0), %%eax\n\t" \
00083 "imull "offset"+"offc"(%1) \n\t" \
00084 "add %%eax , %%esi\n\t" \
00085 "adc %%edx , %%ecx\n\t"
00086
00087 #define FIRMULREG(label, offset, firc) \
00088 MLPMUL(label, #offset, "0", "0")
00089
00090 #define CLEAR_ACCUM \
00091 "xor %%esi, %%esi\n\t" \
00092 "xor %%ecx, %%ecx\n\t"
00093
00094 #define SHIFT_ACCUM \
00095 "mov %%ecx, %%edx\n\t" \
00096 "mov %%esi, %%eax\n\t" \
00097 "movzbl %7 , %%ecx\n\t" \
00098 "shrd %%cl, %%edx, %%eax\n\t" \
00099
00100 #define ACCUM "%%edx"
00101 #define RESULT "%%eax"
00102 #define RESULT32 "%%eax"
00103
00104 #endif
00105
00106 #define BINC AV_STRINGIFY(4* MAX_CHANNELS)
00107 #define IOFFS AV_STRINGIFY(4*(MAX_FIR_ORDER + MAX_BLOCKSIZE))
00108 #define IOFFC AV_STRINGIFY(4* MAX_FIR_ORDER)
00109
00110 #define FIRMUL(label, offset) MLPMUL(label, #offset, "0", "0")
00111 #define IIRMUL(label, offset) MLPMUL(label, #offset, IOFFS, IOFFC)
00112
00113 static void mlp_filter_channel_x86(int32_t *state, const int32_t *coeff,
00114 int firorder, int iirorder,
00115 unsigned int filter_shift, int32_t mask,
00116 int blocksize, int32_t *sample_buffer)
00117 {
00118 const void *firjump = firtable[firorder];
00119 const void *iirjump = iirtable[iirorder];
00120
00121 blocksize = -blocksize;
00122
00123 __asm__ volatile(
00124 "1: \n\t"
00125 CLEAR_ACCUM
00126 "jmp *%5 \n\t"
00127 FIRMUL (ff_mlp_firorder_8, 0x1c )
00128 FIRMUL (ff_mlp_firorder_7, 0x18 )
00129 FIRMUL (ff_mlp_firorder_6, 0x14 )
00130 FIRMUL (ff_mlp_firorder_5, 0x10 )
00131 FIRMUL (ff_mlp_firorder_4, 0x0c )
00132 FIRMULREG(ff_mlp_firorder_3, 0x08,10)
00133 FIRMULREG(ff_mlp_firorder_2, 0x04, 9)
00134 FIRMULREG(ff_mlp_firorder_1, 0x00, 8)
00135 LABEL_MANGLE(ff_mlp_firorder_0)":\n\t"
00136 "jmp *%6 \n\t"
00137 IIRMUL (ff_mlp_iirorder_4, 0x0c )
00138 IIRMUL (ff_mlp_iirorder_3, 0x08 )
00139 IIRMUL (ff_mlp_iirorder_2, 0x04 )
00140 IIRMUL (ff_mlp_iirorder_1, 0x00 )
00141 LABEL_MANGLE(ff_mlp_iirorder_0)":\n\t"
00142 SHIFT_ACCUM
00143 "mov "RESULT" ,"ACCUM" \n\t"
00144 "add (%2) ,"RESULT" \n\t"
00145 "and %4 ,"RESULT" \n\t"
00146 "sub $4 , %0 \n\t"
00147 "mov "RESULT32", (%0) \n\t"
00148 "mov "RESULT32", (%2) \n\t"
00149 "add $"BINC" , %2 \n\t"
00150 "sub "ACCUM" ,"RESULT" \n\t"
00151 "mov "RESULT32","IOFFS"(%0) \n\t"
00152 "incl %3 \n\t"
00153 "js 1b \n\t"
00154 : "+r"(state),
00155 "+r"(coeff),
00156 "+r"(sample_buffer),
00157 #if ARCH_X86_64
00158 "+r"(blocksize)
00159 : "r"((x86_reg)mask), "r"(firjump),
00160 "r"(iirjump) , "c"(filter_shift)
00161 , "r"((int64_t)coeff[0])
00162 , "r"((int64_t)coeff[1])
00163 , "r"((int64_t)coeff[2])
00164 : "rax", "rdx", "rsi"
00165 #else
00166 "+m"(blocksize)
00167 : "m"( mask), "m"(firjump),
00168 "m"(iirjump) , "m"(filter_shift)
00169 : "eax", "edx", "esi", "ecx"
00170 #endif
00171 );
00172 }
00173
00174 #endif
00175
00176 void ff_mlp_init_x86(DSPContext* c, AVCodecContext *avctx)
00177 {
00178 #if HAVE_7REGS && HAVE_TEN_OPERANDS
00179 c->mlp_filter_channel = mlp_filter_channel_x86;
00180 #endif
00181 }