>From b08b4a38c87000fe5549de96f65de6ba77740b30 Mon Sep 17 00:00:00 2001 From: Zeng Zhaoxiu <zhaoxiu.z...@gmail.com> Date: Fri, 13 Feb 2015 23:52:29 +0800 Subject: [PATCH 2/3] avcodec/wmalosslessdec: optimize sign operation
Signed-off-by: Zeng Zhaoxiu <zhaoxiu.z...@gmail.com> --- libavcodec/wmalosslessdec.c | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/libavcodec/wmalosslessdec.c b/libavcodec/wmalosslessdec.c index 9bd5e7b..1916594 100644 --- a/libavcodec/wmalosslessdec.c +++ b/libavcodec/wmalosslessdec.c @@ -175,6 +175,8 @@ typedef struct WmallDecodeCtx { int channel_coeffs[WMALL_MAX_CHANNELS][WMALL_BLOCK_MAX_SIZE]; } WmallDecodeCtx; +/** Get sign of integer (1 for positive, -1 for negative and 0 for zero) */ +#define WMASIGN(x) ((x > 0) - (x < 0)) static av_cold int decode_init(AVCodecContext *avctx) { @@ -631,22 +633,14 @@ static void mclms_update(WmallDecodeCtx *s, int icoef, int *pred) for (i = 0; i < order * num_channels; i++) s->mclms_coeffs[i + ich * order * num_channels] += s->mclms_updates[s->mclms_recent + i]; - for (j = 0; j < ich; j++) { - if (s->channel_residues[j][icoef] > 0) - s->mclms_coeffs_cur[ich * num_channels + j] += 1; - else if (s->channel_residues[j][icoef] < 0) - s->mclms_coeffs_cur[ich * num_channels + j] -= 1; - } + for (j = 0; j < ich; j++) + s->mclms_coeffs_cur[ich * num_channels + j] += WMASIGN(s->channel_residues[j][icoef]); } else if (pred_error < 0) { for (i = 0; i < order * num_channels; i++) s->mclms_coeffs[i + ich * order * num_channels] -= s->mclms_updates[s->mclms_recent + i]; - for (j = 0; j < ich; j++) { - if (s->channel_residues[j][icoef] > 0) - s->mclms_coeffs_cur[ich * num_channels + j] -= 1; - else if (s->channel_residues[j][icoef] < 0) - s->mclms_coeffs_cur[ich * num_channels + j] += 1; - } + for (j = 0; j < ich; j++) + s->mclms_coeffs_cur[ich * num_channels + j] -= WMASIGN(s->channel_residues[j][icoef]); } } @@ -658,11 +652,7 @@ static void mclms_update(WmallDecodeCtx *s, int icoef, int *pred) else if (s->channel_residues[ich][icoef] < -range) s->mclms_prevvalues[s->mclms_recent] = -range; - s->mclms_updates[s->mclms_recent] = 0; - if (s->channel_residues[ich][icoef] > 0) - s->mclms_updates[s->mclms_recent] = 1; - else if (s->channel_residues[ich][icoef] < 0) - s->mclms_updates[s->mclms_recent] = -1; + s->mclms_updates[s->mclms_recent] = WMASIGN(s->channel_residues[ich][icoef]); } if (s->mclms_recent == 0) { @@ -724,12 +714,7 @@ static void lms_update(WmallDecodeCtx *s, int ich, int ilms, int input) } s->cdlms[ich][ilms].lms_prevvalues[recent] = av_clip(input, -range, range - 1); - if (!input) - s->cdlms[ich][ilms].lms_updates[recent] = 0; - else if (input < 0) - s->cdlms[ich][ilms].lms_updates[recent] = -s->update_speed[ich]; - else - s->cdlms[ich][ilms].lms_updates[recent] = s->update_speed[ich]; + s->cdlms[ich][ilms].lms_updates[recent] = WMASIGN(input) * s->update_speed[ich]; s->cdlms[ich][ilms].lms_updates[recent + (order >> 4)] >>= 2; s->cdlms[ich][ilms].lms_updates[recent + (order >> 3)] >>= 1; @@ -773,9 +758,6 @@ static void use_normal_update_speed(WmallDecodeCtx *s, int ich) s->update_speed[ich] = 8; } -/** Get sign of integer (1 for positive, -1 for negative and 0 for zero) */ -#define WMASIGN(x) ((x > 0) - (x < 0)) - static void revert_cdlms(WmallDecodeCtx *s, int ch, int coef_begin, int coef_end) { -- 2.1.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel