extern const unsigned int vp9_prob_cost[256];
+// The factor to scale from cost in bits to cost in vp9_prob_cost units.
+#define VP9_PROB_COST_SHIFT 8
+
#define vp9_cost_zero(prob) (vp9_prob_cost[prob])
#define vp9_cost_one(prob) vp9_cost_zero(vpx_complement(prob))
pd->dst.buf, pd->dst.stride);
}
-#define RDTRUNC(RM, DM, R, D) ((128 + (R) * (RM)) & 0xFF)
+#define RDTRUNC(RM, DM, R, D) \
+ (((1 << (VP9_PROB_COST_SHIFT - 1)) + (R) * (RM)) & \
+ ((1 << VP9_PROB_COST_SHIFT) - 1))
typedef struct vp9_token_state {
int rate;
vpx_prob upd_p) {
const vpx_prob new_p = get_binary_prob(ct[0], ct[1]) | 1;
const int update = cost_branch256(ct, *cur_p) + vp9_cost_zero(upd_p) >
- cost_branch256(ct, new_p) + vp9_cost_one(upd_p) + 7 * 256;
+ cost_branch256(ct, new_p) + vp9_cost_one(upd_p) +
+ (7 << VP9_PROB_COST_SHIFT);
vpx_write(w, update, upd_p);
if (update) {
*cur_p = new_p;
}
if (*skippable == 0) {
- *rate <<= 10;
- *rate += (eob_cost << 8);
+ *rate <<= (2 + VP9_PROB_COST_SHIFT);
+ *rate += (eob_cost << VP9_PROB_COST_SHIFT);
}
}
#endif
(((uint64_t)qstep * qstep << (n_log2 + 10)) + (var >> 1)) / var;
const int xsq_q10 = (int)VPXMIN(xsq_q10_64, MAX_XSQ_Q10);
model_rd_norm(xsq_q10, &r_q10, &d_q10);
- *rate = ((r_q10 << n_log2) + 2) >> 2;
+ *rate = ROUND_POWER_OF_TWO(r_q10 << n_log2, 10 - VP9_PROB_COST_SHIFT);
*dist = (var * (int64_t)d_q10 + 512) >> 10;
}
}
#include "vp9/encoder/vp9_block.h"
#include "vp9/encoder/vp9_context_tree.h"
+#include "vp9/encoder/vp9_cost.h"
#ifdef __cplusplus
extern "C" {
#define RDDIV_BITS 7
#define RDCOST(RM, DM, R, D) \
- (((128 + ((int64_t)R) * (RM)) >> 8) + (D << DM))
+ (ROUND_POWER_OF_TWO(((int64_t)R) * (RM), VP9_PROB_COST_SHIFT) + (D << DM))
#define QIDX_SKIP_THRESH 115
#define MV_COST_WEIGHT 108
int quantizer = (pd->dequant[1] >> dequant_shift);
if (quantizer < 120)
- rate = (square_error * (280 - quantizer)) >> 8;
+ rate = (square_error * (280 - quantizer)) >> (16 - VP9_PROB_COST_SHIFT);
else
rate = 0;
dist = (square_error * quantizer) >> 8;
static int prob_diff_update_cost(vpx_prob newp, vpx_prob oldp) {
int delp = remap_prob(newp, oldp);
- return update_bits[delp] * 256;
+ return update_bits[delp] << VP9_PROB_COST_SHIFT;
}
static void encode_uniform(vpx_writer *w, int v) {