Message ID | GV1SPRMB0052AA3ABD7AB01FD43B26FD8F212@GV1SPRMB0052.EURP250.PROD.OUTLOOK.COM |
---|---|
State | Accepted |
Commit | 9e36e2fb7b0153e3e216870e8d88018f0546f8e6 |
Headers | show |
Series | [FFmpeg-devel] avcodec/xpmdec: 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: > Speeds up decoding and also reduces binary size. > > Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> > --- > libavcodec/xpmdec.c | 25 ++++++++++++++++--------- > 1 file changed, 16 insertions(+), 9 deletions(-) > > diff --git a/libavcodec/xpmdec.c b/libavcodec/xpmdec.c > index 5bc02378c8..804cf8568d 100644 > --- a/libavcodec/xpmdec.c > +++ b/libavcodec/xpmdec.c > @@ -193,15 +193,22 @@ static const ColorEntry color_table[] = { > > static unsigned hex_char_to_number(uint8_t x) > { > - if (x >= 'a' && x <= 'f') > - x -= 'a' - 10; > - else if (x >= 'A' && x <= 'F') > - x -= 'A' - 10; > - else if (x >= '0' && x <= '9') > - x -= '0'; > - else > - x = 0; > - return x; > +#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' : 0, > + > + static const uint8_t lut[] = { > + TIMES256(0) > + }; > + return lut[x]; > } > > /* Will apply. - Andreas
diff --git a/libavcodec/xpmdec.c b/libavcodec/xpmdec.c index 5bc02378c8..804cf8568d 100644 --- a/libavcodec/xpmdec.c +++ b/libavcodec/xpmdec.c @@ -193,15 +193,22 @@ static const ColorEntry color_table[] = { static unsigned hex_char_to_number(uint8_t x) { - if (x >= 'a' && x <= 'f') - x -= 'a' - 10; - else if (x >= 'A' && x <= 'F') - x -= 'A' - 10; - else if (x >= '0' && x <= '9') - x -= '0'; - else - x = 0; - return x; +#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' : 0, + + static const uint8_t lut[] = { + TIMES256(0) + }; + return lut[x]; } /*
Speeds up decoding and also reduces binary size. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/xpmdec.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)