[FFmpeg-devel] [PATCHv2 2/3] avcodec/mpegaudio_tablegen: speed up table generation

Ganesh Ajjanagadde gajjanagadde at gmail.com
Thu Nov 26 16:44:43 CET 2015


On Thu, Nov 26, 2015 at 10:37 AM, Ronald S. Bultje <rsbultje at gmail.com> wrote:
> Hi,
>
> On Thu, Nov 26, 2015 at 10:23 AM, Ganesh Ajjanagadde
> <gajjanagadde at gmail.com> wrote:
>>
>> This does some miscellaneous stuff mainly avoiding the usage of pow to
>> achieve significant speedups. This is not speed critical, but is
>> unnecessary latency and cycles wasted for a user.
>>
>> All tables tested and are identical to the old ones
>> (bit-exact even in floating point case).
>>
>> Sample benchmark (x86-64, Haswell, GNU/Linux):
>> old:
>> 102329530 decicycles in mpegaudio_tableinit,       1 runs,      0 skips
>>
>> new:
>> 34111900 decicycles in mpegaudio_tableinit,       1 runs,      0 skips
>>
>> Signed-off-by: Ganesh Ajjanagadde <gajjanagadde at gmail.com>
>> ---
>>  libavcodec/mpegaudio_tablegen.h | 21 +++++++++++++++------
>>  1 file changed, 15 insertions(+), 6 deletions(-)
>>
>> diff --git a/libavcodec/mpegaudio_tablegen.h
>> b/libavcodec/mpegaudio_tablegen.h
>> index 86b2cd3..6cd5ad6 100644
>> --- a/libavcodec/mpegaudio_tablegen.h
>> +++ b/libavcodec/mpegaudio_tablegen.h
>> @@ -29,9 +29,11 @@
>>
>>  #define TABLE_4_3_SIZE (8191 + 16)*4
>>  #if CONFIG_HARDCODED_TABLES
>> +#include "libavutil/tablegen.h"
>>  #define mpegaudio_tableinit()
>>  #include "libavcodec/mpegaudio_tables.h"
>>  #else
>> +#include "libavutil/libm.h"
>
>
> I don't think this works yet. Check mpegaudio_tablegen.c (it should be
> obvious why it does this):
>
> #include <stdlib.h>
> #define CONFIG_HARDCODED_TABLES 0
> #include "mpegaudio_tablegen.h"
> #include "tableprint.h"
>
> Note that this is the table generation which runs on the host platform. So,
> the location where you add this, is important. I would recommend including
> tablegen.h inside mpegaudio_tablegen.c, and then including libavutil/libm.h
> outside the scope of this header, e.g. in users of this header, if
> tablegen.h wasn't included. Make sure make checkheaders passes after your
> changes, and the build works with as well as without hardcoded_tables.

I did a build test with and without hardcoded , did not think of
checkheaders, will recheck and correct depending on the result.

>
>>  static int8_t   table_4_3_exp[TABLE_4_3_SIZE];
>>  static uint32_t table_4_3_value[TABLE_4_3_SIZE];
>>  static uint32_t exp_table_fixed[512];
>> @@ -45,12 +47,21 @@ static float expval_table_float[512][16];
>>  static av_cold void mpegaudio_tableinit(void)
>>  {
>>      int i, value, exponent;
>> +    double pow2_lut[4] = {
>
>
> I think somebody else already mentioned exp2. I'd call this table exp2,
> since table[idx] corresponds to exp2(idx * constant).

Fine, will change.

>
>>
>> +            double f = value * cbrt_lut[value] * pow(2, (exponent - 400)
>> * 0.25 + FRAC_BITS + 5) / IMDCT_SCALAR;
>
>
> exp2 here also. For compatibility, you can #define exp2(x) to pow(2, x) in
> libavutil/tablegen.h.

This won't be done, I already discussed with Timothy - if it is being
improved, it needs to improved well, and belongs in a separate patch.
Bascially, the exp2 can be removed entirely. For me, it is low
priority as it won't improve > 10% overall perf.

>
> Ronald


More information about the ffmpeg-devel mailing list