[FFmpeg-cvslog] avcodec/wmalosslessdec: optimize sign operation
zhaoxiu.zeng
git at videolan.org
Fri Feb 13 18:35:02 CET 2015
ffmpeg | branch: master | zhaoxiu.zeng <zhaoxiu.zeng at gmail.com> | Sat Feb 14 00:51:27 2015 +0800| [80f13780051fd9afa924e1c0db2eb36701592c75] | committer: Michael Niedermayer
avcodec/wmalosslessdec: optimize sign operation
Signed-off-by: Zeng Zhaoxiu <zhaoxiu.zeng at gmail.com>
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=80f13780051fd9afa924e1c0db2eb36701592c75
---
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)
{
More information about the ffmpeg-cvslog
mailing list