Message ID | GV1SPRMB00522C0643F94C65650C6D7E8F212@GV1SPRMB0052.EURP250.PROD.OUTLOOK.COM |
---|---|
State | Accepted |
Commit | 0b2ed7f6c7e44c9dbf6b79aa36b8db033d192760 |
Headers | show |
Series | [FFmpeg-devel] avcodec/xbmdec: Use LUT for hex char->number conversion | expand |
Context | Check | Description |
---|---|---|
yinshiyou/make_loongarch64 | success | Make finished |
yinshiyou/make_fate_loongarch64 | success | Make fate finished |
andriy/make_x86 | success | Make finished |
andriy/make_fate_x86 | success | Make fate finished |
Andreas Rheinhardt: > Improves performance by about 30%. > > Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> > --- > [1] is a patch that would also move the bitreverse into the LUT; > it didn't make a difference in the benchmarks here, but if it is > an improvement for someone else, it could still be applied. > [1]: https://github.com/mkver/FFmpeg/commit/d4fdac5335d2ccf29f7b55fe3147edf388bb7efa > libavcodec/xbmdec.c | 27 ++++++++++++++++----------- > 1 file changed, 16 insertions(+), 11 deletions(-) > > diff --git a/libavcodec/xbmdec.c b/libavcodec/xbmdec.c > index ecfc957a3f..2d84327e02 100644 > --- a/libavcodec/xbmdec.c > +++ b/libavcodec/xbmdec.c > @@ -28,17 +28,22 @@ > > static int get_nibble(uint8_t x) > { > - int ret = 255; > - > - if (x <= '9') { > - if (x >= '0') > - ret = x - '0'; > - } else if (x >= 'a') { > - if (x <= 'f') > - ret = x - ('a' - 10); > - } else if (x >= 'A' && x <= 'F') > - ret = x - ('A' - 10); > - return ret; > +#define TIMES256(idx) \ > +TIMES64(4 * (idx)) TIMES64(4 * (idx) + 1) TIMES64(4 * (idx) + 2) TIMES64(4 * (idx) + 3) > +#define TIMES64(idx) \ > +TIMES16(4 * (idx)) TIMES16(4 * (idx) + 1) TIMES16(4 * (idx) + 2) TIMES16(4 * (idx) + 3) > +#define TIMES16(idx) \ > +TIMES4(4 * (idx)) TIMES4(4 * (idx) + 1) TIMES4(4 * (idx) + 2) TIMES4(4 * (idx) + 3) > +#define TIMES4(idx) \ > +ENTRY(4 * (idx)) ENTRY(4 * (idx) + 1) ENTRY(4 * (idx) + 2) ENTRY(4 * (idx) + 3) > +#define ENTRY(x) [x] = ((x) >= 'a' && (x) <= 'f') ? (x) - ('a' - 10) : \ > + ((x) >= 'A' && (x) <= 'F') ? (x) - ('A' - 10) : \ > + ((x) >= '0' && (x) <= '9') ? (x) - '0' : 255, > + > + static const uint8_t lut[] = { > + TIMES256(0) > + }; > + return lut[x]; > } > > static int parse_str_int(const uint8_t *p, const uint8_t *end, const uint8_t *key) Will apply. - Andreas
diff --git a/libavcodec/xbmdec.c b/libavcodec/xbmdec.c index ecfc957a3f..2d84327e02 100644 --- a/libavcodec/xbmdec.c +++ b/libavcodec/xbmdec.c @@ -28,17 +28,22 @@ static int get_nibble(uint8_t x) { - int ret = 255; - - if (x <= '9') { - if (x >= '0') - ret = x - '0'; - } else if (x >= 'a') { - if (x <= 'f') - ret = x - ('a' - 10); - } else if (x >= 'A' && x <= 'F') - ret = x - ('A' - 10); - return ret; +#define TIMES256(idx) \ +TIMES64(4 * (idx)) TIMES64(4 * (idx) + 1) TIMES64(4 * (idx) + 2) TIMES64(4 * (idx) + 3) +#define TIMES64(idx) \ +TIMES16(4 * (idx)) TIMES16(4 * (idx) + 1) TIMES16(4 * (idx) + 2) TIMES16(4 * (idx) + 3) +#define TIMES16(idx) \ +TIMES4(4 * (idx)) TIMES4(4 * (idx) + 1) TIMES4(4 * (idx) + 2) TIMES4(4 * (idx) + 3) +#define TIMES4(idx) \ +ENTRY(4 * (idx)) ENTRY(4 * (idx) + 1) ENTRY(4 * (idx) + 2) ENTRY(4 * (idx) + 3) +#define ENTRY(x) [x] = ((x) >= 'a' && (x) <= 'f') ? (x) - ('a' - 10) : \ + ((x) >= 'A' && (x) <= 'F') ? (x) - ('A' - 10) : \ + ((x) >= '0' && (x) <= '9') ? (x) - '0' : 255, + + static const uint8_t lut[] = { + TIMES256(0) + }; + return lut[x]; } static int parse_str_int(const uint8_t *p, const uint8_t *end, const uint8_t *key)
Improves performance by about 30%. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- [1] is a patch that would also move the bitreverse into the LUT; it didn't make a difference in the benchmarks here, but if it is an improvement for someone else, it could still be applied. [1]: https://github.com/mkver/FFmpeg/commit/d4fdac5335d2ccf29f7b55fe3147edf388bb7efa libavcodec/xbmdec.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-)