Commit 9b28d1c5 authored by Josh Holmer's avatar Josh Holmer Committed by Thomas Daede

Pass small copy types by value

It is more performant to pass small types which implement `Copy` by
value, because they can be passed directly through registers. Clippy is
conservative with this lint and optimizes for 32-bit architectures. The
setting can be overridden in `clippy.toml` if we choose to further
optimize for 64-bit architectures.
parent 271d1c76
......@@ -1475,13 +1475,13 @@ impl BlockContext {
}
}
pub fn set_motion_vectors(&mut self, bo: &BlockOffset, bsize: BlockSize, mvs: &[MotionVector; 2]) {
pub fn set_motion_vectors(&mut self, bo: &BlockOffset, bsize: BlockSize, mvs: [MotionVector; 2]) {
let bw = bsize.width_mi();
let bh = bsize.height_mi();
for y in 0..bh {
for x in 0..bw {
self.blocks[bo.y + y as usize][bo.x + x as usize].mv = *mvs;
self.blocks[bo.y + y as usize][bo.x + x as usize].mv = mvs;
}
}
}
......@@ -1709,19 +1709,19 @@ impl CFLParams {
scale: [1, 0]
}
}
pub fn joint_sign(&self) -> u32 {
pub fn joint_sign(self) -> u32 {
assert!(self.sign[0] != CFL_SIGN_ZERO || self.sign[1] != CFL_SIGN_ZERO);
(self.sign[0] as u32) * (CFL_SIGNS as u32) + (self.sign[1] as u32) - 1
}
pub fn context(&self, uv: usize) -> usize {
pub fn context(self, uv: usize) -> usize {
assert!(self.sign[uv] != CFL_SIGN_ZERO);
(self.sign[uv] as usize - 1) * CFL_SIGNS + (self.sign[1 - uv] as usize)
}
pub fn index(&self, uv: usize) -> u32 {
pub fn index(self, uv: usize) -> u32 {
assert!(self.sign[uv] != CFL_SIGN_ZERO && self.scale[uv] != 0);
(self.scale[uv] - 1) as u32
}
pub fn alpha(&self, uv: usize) -> i16 {
pub fn alpha(self, uv: usize) -> i16 {
cfl_sign_value[self.sign[uv] as usize] * (self.scale[uv] as i16)
}
pub fn from_alpha(u: i16, v: i16) -> CFLParams {
......@@ -2058,7 +2058,7 @@ impl ContextWriter {
cmp::max(col_offset, -(mi_col as isize))
}
fn find_matching_mv(&self, mv: &MotionVector, mv_stack: &mut Vec<CandidateMV>) -> bool {
fn find_matching_mv(&self, mv: MotionVector, mv_stack: &mut Vec<CandidateMV>) -> bool {
for mv_cand in mv_stack {
if mv.row == mv_cand.this_mv.row && mv.col == mv_cand.this_mv.col {
return true;
......@@ -2067,7 +2067,7 @@ impl ContextWriter {
false
}
fn find_matching_mv_and_update_weight(&self, mv: &MotionVector, mv_stack: &mut Vec<CandidateMV>, weight: u32) -> bool {
fn find_matching_mv_and_update_weight(&self, mv: MotionVector, mv_stack: &mut Vec<CandidateMV>, weight: u32) -> bool {
for mut mv_cand in mv_stack {
if mv.row == mv_cand.this_mv.row && mv.col == mv_cand.this_mv.col {
mv_cand.weight += weight;
......@@ -2077,7 +2077,7 @@ impl ContextWriter {
false
}
fn find_matching_comp_mv_and_update_weight(&self, mvs: &[MotionVector; 2], mv_stack: &mut Vec<CandidateMV>, weight: u32) -> bool {
fn find_matching_comp_mv_and_update_weight(&self, mvs: [MotionVector; 2], mv_stack: &mut Vec<CandidateMV>, weight: u32) -> bool {
for mut mv_cand in mv_stack {
if mvs[0].row == mv_cand.this_mv.row && mvs[0].col == mv_cand.this_mv.col &&
mvs[1].row == mv_cand.comp_mv.row && mvs[1].col == mv_cand.comp_mv.col {
......@@ -2094,7 +2094,7 @@ impl ContextWriter {
false
} else if is_compound {
if blk.ref_frames[0] == ref_frames[0] && blk.ref_frames[1] == ref_frames[1] {
let found_match = self.find_matching_comp_mv_and_update_weight(&blk.mv, mv_stack, weight);
let found_match = self.find_matching_comp_mv_and_update_weight(blk.mv, mv_stack, weight);
if !found_match && mv_stack.len() < MAX_REF_MV_STACK_SIZE {
let mv_cand = CandidateMV {
......@@ -2122,7 +2122,7 @@ impl ContextWriter {
let mut found = false;
for i in 0..2 {
if blk.ref_frames[i] == ref_frames[0] {
let found_match = self.find_matching_mv_and_update_weight(&blk.mv[i], mv_stack, weight);
let found_match = self.find_matching_mv_and_update_weight(blk.mv[i], mv_stack, weight);
if !found_match && mv_stack.len() < MAX_REF_MV_STACK_SIZE {
let mv_cand = CandidateMV {
......@@ -2194,7 +2194,7 @@ impl ContextWriter {
mv.col = -mv.col;
}
if !self.find_matching_mv(&mv, mv_stack) {
if !self.find_matching_mv(mv, mv_stack) {
let mv_cand = CandidateMV {
this_mv: mv,
comp_mv: MotionVector { row: 0, col: 0 },
......@@ -2882,10 +2882,10 @@ impl ContextWriter {
}
pub fn write_mv(&mut self, w: &mut dyn Writer,
mv: &MotionVector, ref_mv: &MotionVector,
mv: MotionVector, ref_mv: MotionVector,
mv_precision: MvSubpelPrecision) {
let diff = MotionVector { row: mv.row - ref_mv.row, col: mv.col - ref_mv.col };
let j: MvJointType = av1_get_mv_joint(&diff);
let j: MvJointType = av1_get_mv_joint(diff);
w.symbol_with_update(j as u32, &mut self.fc.nmv_context.joints_cdf);
......@@ -3543,7 +3543,7 @@ const MV_LOW: i32 = (-(1 << MV_IN_USE_BITS));
#[inline(always)]
pub fn av1_get_mv_joint(mv: &MotionVector) -> MvJointType {
pub fn av1_get_mv_joint(mv: MotionVector) -> MvJointType {
if mv.row == 0 {
if mv.col == 0 { MvJointType::MV_JOINT_ZERO } else { MvJointType::MV_JOINT_HNZVZ }
} else {
......
......@@ -1410,7 +1410,7 @@ pub fn encode_tx_block(
}
pub fn motion_compensate(fi: &FrameInvariants, fs: &mut FrameState, cw: &mut ContextWriter,
luma_mode: PredictionMode, ref_frames: &[usize; 2], mvs: &[MotionVector; 2],
luma_mode: PredictionMode, ref_frames: &[usize; 2], mvs: [MotionVector; 2],
bsize: BlockSize, bo: &BlockOffset, bit_depth: usize,
luma_only: bool) {
if luma_mode.is_intra() { return; }
......@@ -1435,16 +1435,16 @@ pub fn motion_compensate(fi: &FrameInvariants, fs: &mut FrameState, cw: &mut Con
if some_use_intra {
luma_mode.predict_inter(fi, p, &po, &mut rec.mut_slice(&po), plane_bsize.width(),
plane_bsize.height(), ref_frames, &mvs, bit_depth);
plane_bsize.height(), ref_frames, mvs, bit_depth);
} else {
assert!(xdec == 1 && ydec == 1);
// TODO: these are only valid for 4:2:0
let mv0 = &cw.bc.at(&bo.with_offset(-1,-1)).mv;
let mv0 = cw.bc.at(&bo.with_offset(-1,-1)).mv;
let rf0 = &cw.bc.at(&bo.with_offset(-1,-1)).ref_frames;
let mv1 = &cw.bc.at(&bo.with_offset(0,-1)).mv;
let mv1 = cw.bc.at(&bo.with_offset(0,-1)).mv;
let rf1 = &cw.bc.at(&bo.with_offset(0,-1)).ref_frames;
let po1 = PlaneOffset { x: po.x+2, y: po.y };
let mv2 = &cw.bc.at(&bo.with_offset(-1,0)).mv;
let mv2 = cw.bc.at(&bo.with_offset(-1,0)).mv;
let rf2 = &cw.bc.at(&bo.with_offset(-1,0)).ref_frames;
let po2 = PlaneOffset { x: po.x, y: po.y+2 };
let po3 = PlaneOffset { x: po.x+2, y: po.y+2 };
......@@ -1455,7 +1455,7 @@ pub fn motion_compensate(fi: &FrameInvariants, fs: &mut FrameState, cw: &mut Con
}
} else {
luma_mode.predict_inter(fi, p, &po, &mut rec.mut_slice(&po), plane_bsize.width(),
plane_bsize.height(), ref_frames, &mvs, bit_depth);
plane_bsize.height(), ref_frames, mvs, bit_depth);
}
}
}
......@@ -1474,10 +1474,10 @@ pub fn encode_block_a(seq: &Sequence,
pub fn encode_block_b(seq: &Sequence, fi: &FrameInvariants, fs: &mut FrameState,
cw: &mut ContextWriter, w: &mut dyn Writer,
luma_mode: PredictionMode, chroma_mode: PredictionMode,
ref_frames: &[usize; 2], mvs: &[MotionVector; 2],
ref_frames: &[usize; 2], mvs: [MotionVector; 2],
bsize: BlockSize, bo: &BlockOffset, skip: bool, bit_depth: usize,
cfl: CFLParams, tx_size: TxSize, tx_type: TxType,
mode_context: usize, mv_stack: &Vec<CandidateMV>, for_rdo_use: bool)
mode_context: usize, mv_stack: &[CandidateMV], for_rdo_use: bool)
-> i64 {
let is_inter = !luma_mode.is_intra();
if is_inter { assert!(luma_mode == chroma_mode); };
......@@ -1547,11 +1547,11 @@ pub fn encode_block_b(seq: &Sequence, fi: &FrameInvariants, fs: &mut FrameState,
if luma_mode == PredictionMode::NEWMV ||
luma_mode == PredictionMode::NEW_NEWMV ||
luma_mode == PredictionMode::NEW_NEARESTMV {
cw.write_mv(w, &mvs[0], &ref_mvs[0], mv_precision);
cw.write_mv(w, mvs[0], ref_mvs[0], mv_precision);
}
if luma_mode == PredictionMode::NEW_NEWMV ||
luma_mode == PredictionMode::NEAREST_NEWMV {
cw.write_mv(w, &mvs[1], &ref_mvs[1], mv_precision);
cw.write_mv(w, mvs[1], ref_mvs[1], mv_precision);
}
if luma_mode >= PredictionMode::NEAR0MV && luma_mode <= PredictionMode::NEAR2MV {
......@@ -1883,7 +1883,7 @@ fn encode_partition_bottomup(seq: &Sequence, fi: &FrameInvariants, fs: &mut Fram
let cfl = mode_decision.pred_cfl_params;
{
let ref_frames = &mode_decision.ref_frames;
let mvs = &mode_decision.mvs;
let mvs = mode_decision.mvs;
let skip = mode_decision.skip;
let mut cdef_coded = cw.bc.cdef_coded;
let (tx_size, tx_type) = (mode_decision.tx_size, mode_decision.tx_type);
......@@ -1966,7 +1966,7 @@ fn encode_partition_bottomup(seq: &Sequence, fi: &FrameInvariants, fs: &mut Fram
let (mode_luma, mode_chroma) = (best_decision.pred_mode_luma, best_decision.pred_mode_chroma);
let cfl = best_decision.pred_cfl_params;
let ref_frames = &best_decision.ref_frames;
let mvs = &best_decision.mvs;
let mvs = best_decision.mvs;
let skip = best_decision.skip;
let mut cdef_coded = cw.bc.cdef_coded;
let (tx_size, tx_type) = (best_decision.tx_size, best_decision.tx_type);
......@@ -2068,7 +2068,7 @@ fn encode_partition_topdown(seq: &Sequence, fi: &FrameInvariants, fs: &mut Frame
let cfl = part_decision.pred_cfl_params;
let skip = part_decision.skip;
let ref_frames = &part_decision.ref_frames;
let mvs = &part_decision.mvs;
let mvs = part_decision.mvs;
let mut cdef_coded = cw.bc.cdef_coded;
// NOTE: Cannot avoid calling rdo_tx_size_type() here again,
......
......@@ -49,7 +49,7 @@ fn get_mv_range(fi: &FrameInvariants, bo: &BlockOffset, blk_w: usize, blk_h: usi
pub fn motion_estimation(
fi: &FrameInvariants, fs: &FrameState, bsize: BlockSize,
bo: &BlockOffset, ref_frame: usize, pmv: &MotionVector
bo: &BlockOffset, ref_frame: usize, pmv: MotionVector
) -> MotionVector {
match fi.rec_buffer.frames[fi.ref_frames[ref_frame - LAST_FRAME] as usize] {
Some(ref rec) => {
......@@ -109,7 +109,7 @@ pub fn motion_estimation(
mode.predict_inter(
fi, 0, &po, tmp_slice, blk_w, blk_h, &[ref_frame, NONE_FRAME],
&[cand_mv, MotionVector{ row: 0, col: 0 }], 8,
[cand_mv, MotionVector{ row: 0, col: 0 }], 8,
);
}
......
......@@ -950,7 +950,7 @@ impl PredictionMode {
pub fn predict_inter<'a>(
self, fi: &FrameInvariants, p: usize, po: &PlaneOffset,
dst: &'a mut PlaneMutSlice<'a>, width: usize, height: usize,
ref_frames: &[usize; 2], mvs: &[MotionVector; 2], bit_depth: usize
ref_frames: &[usize; 2], mvs: [MotionVector; 2], bit_depth: usize
) {
assert!(!self.is_intra());
......
......@@ -271,7 +271,7 @@ fn compute_tx_rd_cost(
pub fn rdo_tx_size_type(
seq: &Sequence, fi: &FrameInvariants, fs: &mut FrameState,
cw: &mut ContextWriter, bsize: BlockSize, bo: &BlockOffset,
luma_mode: PredictionMode, ref_frames: &[usize; 2], mvs: &[MotionVector; 2], skip: bool
luma_mode: PredictionMode, ref_frames: &[usize; 2], mvs: [MotionVector; 2], skip: bool
) -> (TxSize, TxType) {
// these rules follow TX_MODE_LARGEST
let tx_size = match bsize {
......@@ -384,7 +384,7 @@ pub fn rdo_mode_decision(
let slot_idx = fi.ref_frames[i - LAST_FRAME];
ref_slot_set.push(slot_idx);
let pmv = pmvs[slot_idx as usize].unwrap();
mvs_from_me.push([motion_estimation(fi, fs, bsize, bo, i, &pmv), MotionVector { row: 0, col: 0 }]);
mvs_from_me.push([motion_estimation(fi, fs, bsize, bo, i, pmv), MotionVector { row: 0, col: 0 }]);
}
}
assert!(ref_frames_set.len() != 0);
......@@ -448,7 +448,7 @@ pub fn rdo_mode_decision(
}
let luma_rdo = |luma_mode: PredictionMode, fs: &mut FrameState, cw: &mut ContextWriter, best: &mut EncodingSettings,
mvs: &[MotionVector; 2], ref_frames: &[usize; 2], mode_set_chroma: &[PredictionMode], luma_mode_is_intra: bool,
mvs: [MotionVector; 2], ref_frames: &[usize; 2], mode_set_chroma: &[PredictionMode], luma_mode_is_intra: bool,
mode_context: usize, mv_stack: &Vec<CandidateMV>| {
let (tx_size, mut tx_type) = rdo_tx_size_type(
seq, fi, fs, cw, bsize, bo, luma_mode, ref_frames, mvs, false,
......@@ -520,7 +520,7 @@ pub fn rdo_mode_decision(
best.mode_luma = luma_mode;
best.mode_chroma = chroma_mode;
best.ref_frames = *ref_frames;
best.mvs = *mvs;
best.mvs = mvs;
best.skip = skip;
best.tx_size = tx_size;
best.tx_type = tx_type;
......@@ -563,13 +563,13 @@ pub fn rdo_mode_decision(
};
let mode_set_chroma = vec![luma_mode];
luma_rdo(luma_mode, fs, cw, &mut best, &mvs, &ref_frames_set[i], &mode_set_chroma, false,
luma_rdo(luma_mode, fs, cw, &mut best, mvs, &ref_frames_set[i], &mode_set_chroma, false,
mode_contexts[i], &mv_stacks[i]);
});
if !best.skip {
intra_mode_set.iter().for_each(|&luma_mode| {
let mvs = &[MotionVector { row: 0, col: 0 }; 2];
let mvs = [MotionVector { row: 0, col: 0 }; 2];
let ref_frames = &[INTRA_FRAME, NONE_FRAME];
let mut mode_set_chroma = vec![luma_mode];
if is_chroma_block && luma_mode != PredictionMode::DC_PRED {
......@@ -616,7 +616,7 @@ pub fn rdo_mode_decision(
best.mode_luma,
chroma_mode,
&best.ref_frames,
&best.mvs,
best.mvs,
bsize,
bo,
best.skip,
......@@ -657,7 +657,7 @@ pub fn rdo_mode_decision(
cw.bc.set_mode(bo, bsize, best.mode_luma);
cw.bc.set_ref_frames(bo, bsize, &best.ref_frames);
cw.bc.set_motion_vectors(bo, bsize, &best.mvs);
cw.bc.set_motion_vectors(bo, bsize, best.mvs);
assert!(best.rd >= 0_f64);
......@@ -725,7 +725,7 @@ pub fn rdo_cfl_alpha(
// RDO-based transform type decision
pub fn rdo_tx_type_decision(
fi: &FrameInvariants, fs: &mut FrameState, cw: &mut ContextWriter,
mode: PredictionMode, ref_frames: &[usize; 2], mvs: &[MotionVector; 2], bsize: BlockSize, bo: &BlockOffset, tx_size: TxSize,
mode: PredictionMode, ref_frames: &[usize; 2], mvs: [MotionVector; 2], bsize: BlockSize, bo: &BlockOffset, tx_size: TxSize,
tx_set: TxSet, bit_depth: usize
) -> TxType {
let mut best_type = TxType::DCT_DCT;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment