[FFmpeg-devel] [PATCH] avcodec: use av_mod_intp2() where possible
James Almer
jamrial at gmail.com
Tue Apr 21 22:45:25 CEST 2015
Signed-off-by: James Almer <jamrial at gmail.com>
---
libavcodec/acelp_vectors.c | 8 +++-----
libavcodec/adpcm.c | 2 +-
libavcodec/alacenc.c | 3 +--
libavcodec/atrac3plus.c | 4 ++--
libavcodec/dnxhdenc.c | 2 +-
libavcodec/dvenc.c | 2 +-
libavcodec/ffv1.h | 2 +-
libavcodec/ffv1dec.c | 3 +--
libavcodec/g726.c | 2 +-
libavcodec/g729dec.c | 2 +-
libavcodec/golomb.h | 2 +-
libavcodec/h264.c | 5 ++---
libavcodec/h264_refs.c | 2 +-
libavcodec/hevc.c | 26 ++++++++++++--------------
libavcodec/hevc_cabac.c | 8 ++++----
libavcodec/hevc_filter.c | 15 ++++++---------
libavcodec/hevc_mvs.c | 4 ++--
libavcodec/hevc_ps.c | 4 ++--
libavcodec/hevc_refs.c | 5 ++---
libavcodec/hevcpred_template.c | 4 ++--
libavcodec/mpeg12enc.c | 8 ++++----
libavcodec/opus.h | 2 +-
libavcodec/opus_celt.c | 9 ++++-----
libavcodec/proresenc_kostya.c | 6 ++----
libavcodec/put_bits.h | 2 +-
libavcodec/vorbisdec.c | 5 ++---
26 files changed, 61 insertions(+), 76 deletions(-)
diff --git a/libavcodec/acelp_vectors.c b/libavcodec/acelp_vectors.c
index 86851a3..7aef8c7 100644
--- a/libavcodec/acelp_vectors.c
+++ b/libavcodec/acelp_vectors.c
@@ -133,12 +133,11 @@ void ff_acelp_fc_pulse_per_track(
int pulse_count,
int bits)
{
- int mask = (1 << bits) - 1;
int i;
for(i=0; i<pulse_count; i++)
{
- fc_v[i + tab1[pulse_indexes & mask]] +=
+ fc_v[i + tab1[av_mod_uintp2(pulse_indexes, bits)]] +=
(pulse_signs & 1) ? 8191 : -8192; // +/-1 in (2.13)
pulse_indexes >>= bits;
@@ -154,13 +153,12 @@ void ff_decode_10_pulses_35bits(const int16_t *fixed_index,
int half_pulse_count, int bits)
{
int i;
- int mask = (1 << bits) - 1;
fixed_sparse->no_repeat_mask = 0;
fixed_sparse->n = 2 * half_pulse_count;
for (i = 0; i < half_pulse_count; i++) {
- const int pos1 = gray_decode[fixed_index[2*i+1] & mask] + i;
- const int pos2 = gray_decode[fixed_index[2*i ] & mask] + i;
+ const int pos1 = gray_decode[av_mod_uintp2(fixed_index[2*i+1], bits)] + i;
+ const int pos2 = gray_decode[av_mod_uintp2(fixed_index[2*i ], bits)] + i;
const float sign = (fixed_index[2*i+1] & (1 << bits)) ? -1.0 : 1.0;
fixed_sparse->x[2*i+1] = pos1;
fixed_sparse->x[2*i ] = pos2;
diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index 56d1660..251ed1d 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -197,7 +197,7 @@ static inline int16_t adpcm_ima_wav_expand_nibble(ADPCMChannelStatus *c, GetBitC
step_index = av_clip(step_index, 0, 88);
sign = nibble & (1 << shift);
- delta = nibble & ((1 << shift) - 1);
+ delta = av_mod_uintp2(nibble, shift);
diff = ((2 * delta + 1) * step) >> shift;
predictor = c->predictor;
if (sign) predictor -= diff;
diff --git a/libavcodec/alacenc.c b/libavcodec/alacenc.c
index ce63da6..415796d 100644
--- a/libavcodec/alacenc.c
+++ b/libavcodec/alacenc.c
@@ -396,12 +396,11 @@ static void write_element(AlacEncodeContext *s,
// extract extra bits if needed
if (s->extra_bits) {
- uint32_t mask = (1 << s->extra_bits) - 1;
for (j = 0; j < channels; j++) {
int32_t *extra = s->predictor_buf[j];
int32_t *smp = s->sample_buf[j];
for (i = 0; i < s->frame_size; i++) {
- extra[i] = smp[i] & mask;
+ extra[i] = av_mod_uintp2(smp[i], s->extra_bits);
smp[i] >>= s->extra_bits;
}
}
diff --git a/libavcodec/atrac3plus.c b/libavcodec/atrac3plus.c
index 575a493..f998a7f 100644
--- a/libavcodec/atrac3plus.c
+++ b/libavcodec/atrac3plus.c
@@ -820,7 +820,7 @@ static void decode_qu_spectra(GetBitContext *gb, const Atrac3pSpecCodeTab *tab,
int num_coeffs = tab->num_coeffs;
int bits = tab->bits;
int is_signed = tab->is_signed;
- unsigned val, mask = (1 << bits) - 1;
+ unsigned val;
for (pos = 0; pos < num_specs;) {
if (group_size == 1 || get_bits1(gb)) {
@@ -828,7 +828,7 @@ static void decode_qu_spectra(GetBitContext *gb, const Atrac3pSpecCodeTab *tab,
val = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
for (i = 0; i < num_coeffs; i++) {
- cf = val & mask;
+ cf = av_mod_uintp2(val, bits);
if (is_signed)
cf = sign_extend(cf, bits);
else if (cf && get_bits1(gb))
diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c
index 005602e..90d51ff 100644
--- a/libavcodec/dnxhdenc.c
+++ b/libavcodec/dnxhdenc.c
@@ -450,7 +450,7 @@ static av_always_inline void dnxhd_encode_dc(DNXHDEncContext *ctx, int diff)
}
put_bits(&ctx->m.pb, ctx->cid_table->dc_bits[nbits] + nbits,
(ctx->cid_table->dc_codes[nbits] << nbits) +
- (diff & ((1 << nbits) - 1)));
+ av_mod_uintp2(diff, nbits));
}
static av_always_inline
diff --git a/libavcodec/dvenc.c b/libavcodec/dvenc.c
index 2442f2b..9ce7273 100644
--- a/libavcodec/dvenc.c
+++ b/libavcodec/dvenc.c
@@ -176,7 +176,7 @@ static av_always_inline PutBitContext *dv_encode_ac(EncBlockInfo *bi,
if (bits_left) {
size -= bits_left;
put_bits(pb, bits_left, vlc >> size);
- vlc = vlc & ((1 << size) - 1);
+ vlc = av_mod_uintp2(vlc, size);
}
if (pb + 1 >= pb_end) {
bi->partial_bit_count = size;
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index 5081397..bfc4d71 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -143,7 +143,7 @@ static av_always_inline int fold(int diff, int bits)
diff = (int8_t)diff;
else {
diff += 1 << (bits - 1);
- diff &= (1 << bits) - 1;
+ diff = av_mod_uintp2(diff, bits);
diff -= 1 << (bits - 1);
}
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 78ba1be..fda3f09 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -172,8 +172,7 @@ static av_always_inline void decode_line(FFV1Context *s, int w,
if (sign)
diff = -diff;
- sample[1][x] = (predict(sample[1] + x, sample[0] + x) + diff) &
- ((1 << bits) - 1);
+ sample[1][x] = av_mod_uintp2(predict(sample[1] + x, sample[0] + x) + diff, bits);
}
s->run_index = run_index;
}
diff --git a/libavcodec/g726.c b/libavcodec/g726.c
index 5b9986a..5bbf897 100644
--- a/libavcodec/g726.c
+++ b/libavcodec/g726.c
@@ -298,7 +298,7 @@ static int16_t g726_encode(G726Context* c, int16_t sig)
{
uint8_t i;
- i = quant(c, sig/4 - c->se) & ((1<<c->code_size) - 1);
+ i = av_mod_uintp2(quant(c, sig/4 - c->se), c->code_size);
g726_decode(c, i);
return i;
}
diff --git a/libavcodec/g729dec.c b/libavcodec/g729dec.c
index e97677b..ed717ba 100644
--- a/libavcodec/g729dec.c
+++ b/libavcodec/g729dec.c
@@ -512,7 +512,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
if (frame_erasure) {
ctx->rand_value = g729_prng(ctx->rand_value);
- fc_indexes = ctx->rand_value & ((1 << format->fc_indexes_bits) - 1);
+ fc_indexes = av_mod_uintp2(ctx->rand_value, format->fc_indexes_bits);
ctx->rand_value = g729_prng(ctx->rand_value);
pulses_signs = ctx->rand_value;
diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h
index 28ae213..76da6a2 100644
--- a/libavcodec/golomb.h
+++ b/libavcodec/golomb.h
@@ -518,7 +518,7 @@ static inline void set_ur_golomb(PutBitContext *pb, int i, int k, int limit,
e = i >> k;
if (e < limit)
- put_bits(pb, e + k + 1, (1 << k) + (i & ((1 << k) - 1)));
+ put_bits(pb, e + k + 1, (1 << k) + av_mod_uintp2(i, k));
else
put_bits(pb, limit + esc_len, i - limit + 1);
}
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index 0ed57a2..0f756a2 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1559,9 +1559,8 @@ again:
h->valid_recovery_point = 1;
if ( h->recovery_frame < 0
- || ((h->recovery_frame - h->frame_num) & ((1 << h->sps.log2_max_frame_num)-1)) > h->sei_recovery_frame_cnt) {
- h->recovery_frame = (h->frame_num + h->sei_recovery_frame_cnt) &
- ((1 << h->sps.log2_max_frame_num) - 1);
+ || av_mod_uintp2(h->recovery_frame - h->frame_num, h->sps.log2_max_frame_num) > h->sei_recovery_frame_cnt) {
+ h->recovery_frame = av_mod_uintp2(h->frame_num + h->sei_recovery_frame_cnt, h->sps.log2_max_frame_num);
if (!h->valid_recovery_point)
h->recovery_frame = h->frame_num;
diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c
index c424b9e..0b2008a 100644
--- a/libavcodec/h264_refs.c
+++ b/libavcodec/h264_refs.c
@@ -772,7 +772,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count)
for (i = 0; i<h->short_ref_count; i++) {
pic = h->short_ref[i];
if (pic->invalid_gap) {
- int d = (h->cur_pic_ptr->frame_num - pic->frame_num) & ((1 << h->sps.log2_max_frame_num)-1);
+ int d = av_mod_uintp2(h->cur_pic_ptr->frame_num - pic->frame_num, h->sps.log2_max_frame_num);
if (d > h->sps.ref_frame_count)
remove_short(h, pic->frame_num, 0);
}
diff --git a/libavcodec/hevc.c b/libavcodec/hevc.c
index 926a19e..3f47c45 100644
--- a/libavcodec/hevc.c
+++ b/libavcodec/hevc.c
@@ -1461,8 +1461,8 @@ static void chroma_mc_uni(HEVCContext *s, uint8_t *dst0,
int idx = ff_hevc_pel_weight[block_w];
int hshift = s->sps->hshift[1];
int vshift = s->sps->vshift[1];
- intptr_t mx = mv->x & ((1 << (2 + hshift)) - 1);
- intptr_t my = mv->y & ((1 << (2 + vshift)) - 1);
+ intptr_t mx = av_mod_uintp2(mv->x, 2 + hshift);
+ intptr_t my = av_mod_uintp2(mv->y, 2 + vshift);
intptr_t _mx = mx << (1 - hshift);
intptr_t _my = my << (1 - vshift);
@@ -1530,10 +1530,10 @@ static void chroma_mc_bi(HEVCContext *s, uint8_t *dst0, ptrdiff_t dststride, AVF
int hshift = s->sps->hshift[1];
int vshift = s->sps->vshift[1];
- intptr_t mx0 = mv0->x & ((1 << (2 + hshift)) - 1);
- intptr_t my0 = mv0->y & ((1 << (2 + vshift)) - 1);
- intptr_t mx1 = mv1->x & ((1 << (2 + hshift)) - 1);
- intptr_t my1 = mv1->y & ((1 << (2 + vshift)) - 1);
+ intptr_t mx0 = av_mod_uintp2(mv0->x, 2 + hshift);
+ intptr_t my0 = av_mod_uintp2(mv0->y, 2 + vshift);
+ intptr_t mx1 = av_mod_uintp2(mv1->x, 2 + hshift);
+ intptr_t my1 = av_mod_uintp2(mv1->y, 2 + vshift);
intptr_t _mx0 = mx0 << (1 - hshift);
intptr_t _my0 = my0 << (1 - vshift);
intptr_t _mx1 = mx1 << (1 - hshift);
@@ -1791,8 +1791,8 @@ static int luma_intra_pred_mode(HEVCContext *s, int x0, int y0, int pu_size,
int y_pu = y0 >> s->sps->log2_min_pu_size;
int min_pu_width = s->sps->min_pu_width;
int size_in_pus = pu_size >> s->sps->log2_min_pu_size;
- int x0b = x0 & ((1 << s->sps->log2_ctb_size) - 1);
- int y0b = y0 & ((1 << s->sps->log2_ctb_size) - 1);
+ int x0b = av_mod_uintp2(x0, s->sps->log2_ctb_size);
+ int y0b = av_mod_uintp2(y0, s->sps->log2_ctb_size);
int cand_up = (lc->ctb_up_flag || y0b) ?
s->tab_ipm[(y_pu - 1) * min_pu_width + x_pu] : INTRA_DC;
@@ -1981,7 +1981,6 @@ static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size)
int x_cb = x0 >> log2_min_cb_size;
int y_cb = y0 >> log2_min_cb_size;
int idx = log2_cb_size - 2;
- int qp_block_mask = (1<<(s->sps->log2_ctb_size - s->pps->diff_cu_qp_delta_depth)) - 1;
int x, y, ret;
lc->cu.x = x0;
@@ -2124,8 +2123,8 @@ static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size)
x += min_cb_width;
}
- if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
- ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) {
+ if(!av_mod_uintp2(x0 + (1<<log2_cb_size), s->sps->log2_ctb_size - s->pps->diff_cu_qp_delta_depth) &&
+ !av_mod_uintp2(y0 + (1<<log2_cb_size), s->sps->log2_ctb_size - s->pps->diff_cu_qp_delta_depth)) {
lc->qPy_pred = lc->qp_y;
}
@@ -2162,7 +2161,6 @@ static int hls_coding_quadtree(HEVCContext *s, int x0, int y0,
}
if (split_cu) {
- int qp_block_mask = (1<<(s->sps->log2_ctb_size - s->pps->diff_cu_qp_delta_depth)) - 1;
const int cb_size_split = cb_size >> 1;
const int x1 = x0 + cb_size_split;
const int y1 = y0 + cb_size_split;
@@ -2190,8 +2188,8 @@ static int hls_coding_quadtree(HEVCContext *s, int x0, int y0,
return more_data;
}
- if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
- ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0)
+ if(!av_mod_uintp2(x0 + (1<<log2_cb_size), s->sps->log2_ctb_size - s->pps->diff_cu_qp_delta_depth) &&
+ !av_mod_uintp2(y0 + (1<<log2_cb_size), s->sps->log2_ctb_size - s->pps->diff_cu_qp_delta_depth))
lc->qPy_pred = lc->qp_y;
if (more_data)
diff --git a/libavcodec/hevc_cabac.c b/libavcodec/hevc_cabac.c
index 3862df7..cb369eb 100644
--- a/libavcodec/hevc_cabac.c
+++ b/libavcodec/hevc_cabac.c
@@ -658,8 +658,8 @@ int ff_hevc_skip_flag_decode(HEVCContext *s, int x0, int y0, int x_cb, int y_cb)
{
int min_cb_width = s->sps->min_cb_width;
int inc = 0;
- int x0b = x0 & ((1 << s->sps->log2_ctb_size) - 1);
- int y0b = y0 & ((1 << s->sps->log2_ctb_size) - 1);
+ int x0b = av_mod_uintp2(x0, s->sps->log2_ctb_size);
+ int y0b = av_mod_uintp2(y0, s->sps->log2_ctb_size);
if (s->HEVClc->ctb_left_flag || x0b)
inc = !!SAMPLE_CTB(s->skip_flag, x_cb - 1, y_cb);
@@ -723,8 +723,8 @@ int ff_hevc_pred_mode_decode(HEVCContext *s)
int ff_hevc_split_coding_unit_flag_decode(HEVCContext *s, int ct_depth, int x0, int y0)
{
int inc = 0, depth_left = 0, depth_top = 0;
- int x0b = x0 & ((1 << s->sps->log2_ctb_size) - 1);
- int y0b = y0 & ((1 << s->sps->log2_ctb_size) - 1);
+ int x0b = av_mod_uintp2(x0, s->sps->log2_ctb_size);
+ int y0b = av_mod_uintp2(y0, s->sps->log2_ctb_size);
int x_cb = x0 >> s->sps->log2_min_cb_size;
int y_cb = y0 >> s->sps->log2_min_cb_size;
diff --git a/libavcodec/hevc_filter.c b/libavcodec/hevc_filter.c
index f50a640..78a2331 100644
--- a/libavcodec/hevc_filter.c
+++ b/libavcodec/hevc_filter.c
@@ -79,18 +79,15 @@ static int chroma_tc(HEVCContext *s, int qp_y, int c_idx, int tc_offset)
static int get_qPy_pred(HEVCContext *s, int xBase, int yBase, int log2_cb_size)
{
HEVCLocalContext *lc = s->HEVClc;
- int ctb_size_mask = (1 << s->sps->log2_ctb_size) - 1;
- int MinCuQpDeltaSizeMask = (1 << (s->sps->log2_ctb_size -
- s->pps->diff_cu_qp_delta_depth)) - 1;
- int xQgBase = xBase - (xBase & MinCuQpDeltaSizeMask);
- int yQgBase = yBase - (yBase & MinCuQpDeltaSizeMask);
+ int xQgBase = xBase - av_mod_uintp2(xBase, s->sps->log2_ctb_size - s->pps->diff_cu_qp_delta_depth);
+ int yQgBase = yBase - av_mod_uintp2(yBase, s->sps->log2_ctb_size - s->pps->diff_cu_qp_delta_depth);
int min_cb_width = s->sps->min_cb_width;
int x_cb = xQgBase >> s->sps->log2_min_cb_size;
int y_cb = yQgBase >> s->sps->log2_min_cb_size;
- int availableA = (xBase & ctb_size_mask) &&
- (xQgBase & ctb_size_mask);
- int availableB = (yBase & ctb_size_mask) &&
- (yQgBase & ctb_size_mask);
+ int availableA = av_mod_uintp2(xBase, s->sps->log2_ctb_size) &&
+ av_mod_uintp2(xQgBase, s->sps->log2_ctb_size);
+ int availableB = av_mod_uintp2(yBase, s->sps->log2_ctb_size) &&
+ av_mod_uintp2(yQgBase, s->sps->log2_ctb_size);
int qPy_pred, qPy_a, qPy_b;
// qPy_pred
diff --git a/libavcodec/hevc_mvs.c b/libavcodec/hevc_mvs.c
index 7e34669..e504257 100644
--- a/libavcodec/hevc_mvs.c
+++ b/libavcodec/hevc_mvs.c
@@ -42,8 +42,8 @@ void ff_hevc_set_neighbour_available(HEVCContext *s, int x0, int y0,
int nPbW, int nPbH)
{
HEVCLocalContext *lc = s->HEVClc;
- int x0b = x0 & ((1 << s->sps->log2_ctb_size) - 1);
- int y0b = y0 & ((1 << s->sps->log2_ctb_size) - 1);
+ int x0b = av_mod_uintp2(x0, s->sps->log2_ctb_size);
+ int y0b = av_mod_uintp2(y0, s->sps->log2_ctb_size);
lc->na.cand_up = (lc->ctb_up_flag || y0b);
lc->na.cand_left = (lc->ctb_left_flag || x0b);
diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index 6a1a8f6..3d4f3e7 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -1123,8 +1123,8 @@ int ff_hevc_decode_nal_sps(HEVCContext *s)
sps->qp_bd_offset = 6 * (sps->bit_depth - 8);
- if (sps->width & ((1 << sps->log2_min_cb_size) - 1) ||
- sps->height & ((1 << sps->log2_min_cb_size) - 1)) {
+ if (av_mod_uintp2(sps->width, sps->log2_min_cb_size) ||
+ av_mod_uintp2(sps->height, sps->log2_min_cb_size)) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid coded frame dimensions.\n");
goto err;
}
diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
index fea3d12..bef44f9 100644
--- a/libavcodec/hevc_refs.c
+++ b/libavcodec/hevc_refs.c
@@ -368,12 +368,11 @@ int ff_hevc_slice_rpl(HEVCContext *s)
static HEVCFrame *find_ref_idx(HEVCContext *s, int poc)
{
int i;
- int LtMask = (1 << s->sps->log2_max_poc_lsb) - 1;
for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
HEVCFrame *ref = &s->DPB[i];
if (ref->frame->buf[0] && (ref->sequence == s->seq_decode)) {
- if ((ref->poc & LtMask) == poc)
+ if (av_mod_uintp2(ref->poc, s->sps->log2_max_poc_lsb) == poc)
return ref;
}
}
@@ -381,7 +380,7 @@ static HEVCFrame *find_ref_idx(HEVCContext *s, int poc)
for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
HEVCFrame *ref = &s->DPB[i];
if (ref->frame->buf[0] && ref->sequence == s->seq_decode) {
- if (ref->poc == poc || (ref->poc & LtMask) == poc)
+ if (ref->poc == poc || av_mod_uintp2(ref->poc, s->sps->log2_max_poc_lsb) == poc)
return ref;
}
}
diff --git a/libavcodec/hevcpred_template.c b/libavcodec/hevcpred_template.c
index 8124230..6b763b3 100644
--- a/libavcodec/hevcpred_template.c
+++ b/libavcodec/hevcpred_template.c
@@ -117,8 +117,8 @@ do { \
if (s->pps->constrained_intra_pred_flag == 1) {
int size_in_luma_pu_v = PU(size_in_luma_v);
int size_in_luma_pu_h = PU(size_in_luma_h);
- int on_pu_edge_x = !(x0 & ((1 << s->sps->log2_min_pu_size) - 1));
- int on_pu_edge_y = !(y0 & ((1 << s->sps->log2_min_pu_size) - 1));
+ int on_pu_edge_x = !av_mod_uintp2(x0, s->sps->log2_min_pu_size);
+ int on_pu_edge_y = !av_mod_uintp2(y0, s->sps->log2_min_pu_size);
if (!size_in_luma_pu_h)
size_in_luma_pu_h++;
if (cand_bottom_left == 1 && on_pu_edge_x) {
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index 9795b7f..edcce35 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -620,12 +620,12 @@ static inline void encode_dc(MpegEncContext *s, int diff, int component)
put_bits(&s->pb,
ff_mpeg12_vlc_dc_lum_bits[index] + index,
(ff_mpeg12_vlc_dc_lum_code[index] << index) +
- (diff & ((1 << index) - 1)));
+ av_mod_uintp2(diff, index));
else
put_bits(&s->pb,
ff_mpeg12_vlc_dc_chroma_bits[index] + index,
(ff_mpeg12_vlc_dc_chroma_code[index] << index) +
- (diff & ((1 << index) - 1)));
+ av_mod_uintp2(diff, index));
} else {
if (component == 0)
put_bits(&s->pb,
@@ -1041,12 +1041,12 @@ av_cold void ff_mpeg1_encode_init(MpegEncContext *s)
bits = ff_mpeg12_vlc_dc_lum_bits[index] + index;
code = (ff_mpeg12_vlc_dc_lum_code[index] << index) +
- (diff & ((1 << index) - 1));
+ av_mod_uintp2(diff, index);
mpeg1_lum_dc_uni[i + 255] = bits + (code << 8);
bits = ff_mpeg12_vlc_dc_chroma_bits[index] + index;
code = (ff_mpeg12_vlc_dc_chroma_code[index] << index) +
- (diff & ((1 << index) - 1));
+ av_mod_uintp2(diff, index);
mpeg1_chr_dc_uni[i + 255] = bits + (code << 8);
}
diff --git a/libavcodec/opus.h b/libavcodec/opus.h
index 1faa7d3..92bb28a 100644
--- a/libavcodec/opus.h
+++ b/libavcodec/opus.h
@@ -279,7 +279,7 @@ static av_always_inline unsigned int opus_getrawbits(OpusRangeCoder *rc, unsigne
rc->rb.bytes--;
}
- value = rc->rb.cacheval & ((1<<count)-1);
+ value = av_mod_uintp2(rc->rb.cacheval, count);
rc->rb.cacheval >>= count;
rc->rb.cachelen -= count;
rc->total_read_bits += count;
diff --git a/libavcodec/opus_celt.c b/libavcodec/opus_celt.c
index e5d615e..1665102 100644
--- a/libavcodec/opus_celt.c
+++ b/libavcodec/opus_celt.c
@@ -1454,7 +1454,7 @@ static unsigned int celt_decode_band(CeltContext *s, OpusRangeCoder *rc,
if (itheta == 0) {
imid = 32767;
iside = 0;
- fill &= (1 << blocks) - 1;
+ fill = av_mod_uintp2(fill, blocks);
delta = -16384;
} else if (itheta == 16384) {
imid = 0;
@@ -1602,8 +1602,7 @@ static unsigned int celt_decode_band(CeltContext *s, OpusRangeCoder *rc,
} else {
/* If there's no pulse, fill the band anyway */
int j;
- unsigned int cm_mask = (1 << blocks) - 1;
- fill &= cm_mask;
+ fill = av_mod_uintp2(fill, blocks);
if (!fill) {
for (j = 0; j < N; j++)
X[j] = 0.0f;
@@ -1612,7 +1611,7 @@ static unsigned int celt_decode_band(CeltContext *s, OpusRangeCoder *rc,
/* Noise */
for (j = 0; j < N; j++)
X[j] = (((int32_t)celt_rng(s)) >> 20);
- cm = cm_mask;
+ cm = (1 << blocks) - 1;
} else {
/* Folded spectrum */
for (j = 0; j < N; j++) {
@@ -1666,7 +1665,7 @@ static unsigned int celt_decode_band(CeltContext *s, OpusRangeCoder *rc,
for (j = 0; j < N0; j++)
lowband_out[j] = n * X[j];
}
- cm &= (1 << blocks) - 1;
+ cm = av_mod_uintp2(cm, blocks);
}
return cm;
}
diff --git a/libavcodec/proresenc_kostya.c b/libavcodec/proresenc_kostya.c
index 440cc8b..a2a8d73 100644
--- a/libavcodec/proresenc_kostya.c
+++ b/libavcodec/proresenc_kostya.c
@@ -440,12 +440,11 @@ static int encode_slice_plane(ProresContext *ctx, PutBitContext *pb,
static void put_alpha_diff(PutBitContext *pb, int cur, int prev, int abits)
{
- const int mask = (1 << abits) - 1;
const int dbits = (abits == 8) ? 4 : 7;
const int dsize = 1 << dbits - 1;
int diff = cur - prev;
- diff &= mask;
+ diff = av_mod_uintp2(diff, abits);
if (diff >= (1 << abits) - dsize)
diff -= 1 << abits;
if (diff < -dsize || diff > dsize || !diff) {
@@ -689,12 +688,11 @@ static int estimate_slice_plane(ProresContext *ctx, int *error, int plane,
static int est_alpha_diff(int cur, int prev, int abits)
{
- const int mask = (1 << abits) - 1;
const int dbits = (abits == 8) ? 4 : 7;
const int dsize = 1 << dbits - 1;
int diff = cur - prev;
- diff &= mask;
+ diff = av_mod_uintp2(diff, abits);
if (diff >= (1 << abits) - dsize)
diff -= 1 << abits;
if (diff < -dsize || diff > dsize || !diff)
diff --git a/libavcodec/put_bits.h b/libavcodec/put_bits.h
index 81be6b3..760b233 100644
--- a/libavcodec/put_bits.h
+++ b/libavcodec/put_bits.h
@@ -193,7 +193,7 @@ static inline void put_sbits(PutBitContext *pb, int n, int32_t value)
{
av_assert2(n >= 0 && n <= 31);
- put_bits(pb, n, value & ((1 << n) - 1));
+ put_bits(pb, n, av_mod_uintp2(value, n));
}
/**
diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c
index 2926e8e..7862302 100644
--- a/libavcodec/vorbisdec.c
+++ b/libavcodec/vorbisdec.c
@@ -1200,7 +1200,7 @@ static int vorbis_floor1_decode(vorbis_context *vc,
uint16_t floor1_Y[258];
uint16_t floor1_Y_final[258];
int floor1_flag[258];
- unsigned partition_class, cdim, cbits, csub, cval, offset, i, j;
+ unsigned partition_class, cdim, cbits, cval, offset, i, j;
int book, adx, ady, dy, off, predicted, err;
@@ -1219,7 +1219,6 @@ static int vorbis_floor1_decode(vorbis_context *vc,
partition_class = vf->partition_class[i];
cdim = vf->class_dimensions[partition_class];
cbits = vf->class_subclasses[partition_class];
- csub = (1 << cbits) - 1;
cval = 0;
ff_dlog(NULL, "Cbits %u\n", cbits);
@@ -1229,7 +1228,7 @@ static int vorbis_floor1_decode(vorbis_context *vc,
vc->codebooks[vf->class_masterbook[partition_class]].nb_bits, 3);
for (j = 0; j < cdim; ++j) {
- book = vf->subclass_books[partition_class][cval & csub];
+ book = vf->subclass_books[partition_class][av_mod_uintp2(cval, cbits)];
ff_dlog(NULL, "book %d Cbits %u cval %u bits:%d\n",
book, cbits, cval, get_bits_count(gb));
--
2.3.5
More information about the ffmpeg-devel
mailing list