Commit f5890e30 authored by Michael Bebenita's avatar Michael Bebenita Committed by Thomas Daede

Format with latest rustfmt.

parent 3a410e29
......@@ -69,8 +69,21 @@ make -j8
# Contributing
Check code formatting with [rustfmt](https://github.com/rust-lang-nursery/rustfmt) before submitting a PR.
rav1e currently uses a [forked version](https://github.com/mbebenita/rustfmt) of rustfmt.
To install rustfmt:
```
git clone https://github.com/mbebenita/rustfmt
cd rustfmt
cargo +nightly build // Depends on the Rust nightly toolchain.
cargo +nightly install -f // Overwrite the installed rustfmt.
```
then
```
cd rav1e
cargo +nightly fmt -- --check
```
......
......@@ -361,16 +361,10 @@ pub fn write_b() -> Vec<TestDescAndFn> {
let mut benches = ::std::vec::Vec::new();
for &tx_size in &[TxSize::TX_4X4, TxSize::TX_8X8] {
for &qi in &[20, 55] {
let w = WriteB {
tx_size,
qi
};
let w = WriteB { tx_size, qi };
let n = format!("write_b_bench({:?}, {})", tx_size, qi);
benches.push(TestDescAndFn {
desc: TestDesc {
name: Cow::from(n),
ignore: false
},
desc: TestDesc { name: Cow::from(n), ignore: false },
testfn: TestFn::DynBenchFn(Box::new(w))
});
}
......@@ -397,19 +391,13 @@ fn write_b_bench(b: &mut Bencher, tx_size: TxSize, qindex: usize) {
b.iter(|| {
for &mode in RAV1E_INTRA_MODES {
let sbo = SuperBlockOffset {
x: sbx,
y: sby
};
let sbo = SuperBlockOffset { x: sbx, y: sby };
fs.qc.update(fi.qindex, tx_size);
for p in 1..3 {
for by in 0..8 {
for bx in 0..8 {
let bo = sbo.block_offset(bx, by);
let tx_bo = BlockOffset {
x: bo.x + bx,
y: bo.y + by
};
let tx_bo = BlockOffset { x: bo.x + bx, y: bo.y + by };
let po = tx_bo.plane_offset(&fs.input.planes[p].cfg);
encode_tx_block(
&mut fi,
......
......@@ -4,7 +4,7 @@ max_width = 79
comment_width = 79
force_explicit_abi = false
fn_args_density = "Compressed"
use_small_heuristics = false
use_small_heuristics = "Max"
match_arm_blocks = false
reorder_imports = true
tab_spaces = 2
......
......@@ -39,11 +39,8 @@ fn main() {
let mut last_rec: Option<Frame> = None;
loop {
//fi.frame_type = FrameType::KEY;
fi.frame_type = if fi.number % 30 == 0 {
FrameType::KEY
} else {
FrameType::INTER
};
fi.frame_type =
if fi.number % 30 == 0 { FrameType::KEY } else { FrameType::INTER };
fi.intra_only = fi.frame_type == FrameType::KEY
|| fi.frame_type == FrameType::INTRA_ONLY;
......
......@@ -67,11 +67,7 @@ impl od_ec_enc {
if val {
l += r - v
};
r = if val {
v
} else {
r - v
};
r = if val { v } else { r - v };
self.od_ec_enc_normalize(l, r as u16);
}
......@@ -86,11 +82,7 @@ impl od_ec_enc {
assert!(cdf[cdf.len() - 1] == 0);
let nsyms = cdf.len();
self.od_ec_encode_q15(
if s > 0 {
cdf[s - 1]
} else {
32768
},
if s > 0 { cdf[s - 1] } else { 32768 },
cdf[s],
s,
nsyms
......@@ -296,11 +288,7 @@ impl Writer {
// Single loop (faster)
for i in 0..(nsymbs - 1) {
tmp = if i as u32 == val {
0
} else {
tmp
};
tmp = if i as u32 == val { 0 } else { tmp };
if tmp < cdf[i] {
cdf[i] -= (cdf[i] - tmp) >> rate;
} else {
......@@ -440,11 +428,7 @@ impl<'a> BCodeWriter for BitWriter<'a, BE> {
let mut i = 0;
let mut mk = 0;
loop {
let b = if i > 0 {
k + i - 1
} else {
k
};
let b = if i > 0 { k + i - 1 } else { k };
let a = 1 << b;
if n <= mk + 3 * a {
return self.write_quniform(n - mk, v - mk);
......@@ -530,10 +514,7 @@ mod test {
impl<'a> Reader<'a> {
fn new(buf: &'a [u8]) -> Self {
let mut r = Reader {
dec: unsafe { mem::uninitialized() },
_dummy: buf
};
let mut r = Reader { dec: unsafe { mem::uninitialized() }, _dummy: buf };
unsafe { od_ec_dec_init(&mut r.dec, buf.as_ptr(), buf.len() as u32) };
......
......@@ -31,28 +31,16 @@ impl Plane {
pub fn new(width: usize, height: usize, xdec: usize, ydec: usize) -> Plane {
Plane {
data: vec![128; width * height],
cfg: PlaneConfig {
stride: width,
xdec,
ydec
}
cfg: PlaneConfig { stride: width, xdec, ydec }
}
}
pub fn slice<'a>(&'a self, po: &PlaneOffset) -> PlaneSlice<'a> {
PlaneSlice {
plane: self,
x: po.x,
y: po.y
}
PlaneSlice { plane: self, x: po.x, y: po.y }
}
pub fn mut_slice<'a>(&'a mut self, po: &PlaneOffset) -> PlaneMutSlice<'a> {
PlaneMutSlice {
plane: self,
x: po.x,
y: po.y
}
PlaneMutSlice { plane: self, x: po.x, y: po.y }
}
pub fn p(&self, x: usize, y: usize) -> u16 {
......@@ -98,20 +86,12 @@ impl<'a> PlaneSlice<'a> {
/// A slice starting i pixels above the current one.
pub fn go_up(&'a self, i: usize) -> PlaneSlice<'a> {
PlaneSlice {
plane: self.plane,
x: self.x,
y: self.y - i
}
PlaneSlice { plane: self.plane, x: self.x, y: self.y - i }
}
/// A slice starting i pixels to the left of the current one.
pub fn go_left(&'a self, i: usize) -> PlaneSlice<'a> {
PlaneSlice {
plane: self.plane,
x: self.x - i,
y: self.y
}
PlaneSlice { plane: self.plane, x: self.x - i, y: self.y }
}
pub fn p(&self, add_x: usize, add_y: usize) -> u16 {
......@@ -137,20 +117,12 @@ impl<'a> PlaneMutSlice<'a> {
/// A slice starting i pixels above the current one.
pub fn go_up(&'a self, i: usize) -> PlaneSlice<'a> {
PlaneSlice {
plane: self.plane,
x: self.x,
y: self.y - i
}
PlaneSlice { plane: self.plane, x: self.x, y: self.y - i }
}
/// A slice starting i pixels to the left of the current one.
pub fn go_left(&'a self, i: usize) -> PlaneSlice<'a> {
PlaneSlice {
plane: self.plane,
x: self.x - i,
y: self.y
}
PlaneSlice { plane: self.plane, x: self.x - i, y: self.y }
}
pub fn p(&self, add_x: usize, add_y: usize) -> u16 {
......
......@@ -34,98 +34,100 @@ pub fn ac_q(qindex: usize) -> i16 {
#[derive(Debug, Default, Clone, Copy)]
pub struct QuantizationContext {
tx_scale: i32,
dc_quant: u32,
dc_offset: i32,
dc_mul_add: (u32, u32, u32),
ac_quant: u32,
ac_offset: i32,
ac_mul_add: (u32, u32, u32),
tx_scale: i32,
dc_quant: u32,
dc_offset: i32,
dc_mul_add: (u32, u32, u32),
ac_quant: u32,
ac_offset: i32,
ac_mul_add: (u32, u32, u32)
}
use std::mem;
fn divu_gen(d: u32) -> (u32, u32, u32) {
let nbits = (mem::size_of_val(&d) as u64) * 8;
let m = nbits - d.leading_zeros() as u64 - 1;
if (d & (d - 1)) == 0 {
(0xFFFFFFFF, 0xFFFFFFFF, m as u32)
let nbits = (mem::size_of_val(&d) as u64) * 8;
let m = nbits - d.leading_zeros() as u64 - 1;
if (d & (d - 1)) == 0 {
(0xFFFFFFFF, 0xFFFFFFFF, m as u32)
} else {
let d = d as u64;
let t = (1u64 << (m + nbits)) / d;
let r = (t * d + d) & ((1 << nbits) - 1);
if r <= 1u64 << m {
(t as u32 + 1, 0u32, m as u32)
} else {
let d = d as u64;
let t = (1u64 << (m + nbits)) / d;
let r = (t * d + d) & ((1 << nbits) - 1);
if r <= 1u64 << m {
(t as u32 + 1, 0u32, m as u32)
} else {
(t as u32, t as u32, m as u32)
}
(t as u32, t as u32, m as u32)
}
}
}
#[inline]
fn divu_pair(x: i32, d: (u32, u32, u32)) -> i32 {
let y = if x < 0 {-x} else {x} as u64;
let (a, b, shift) = d;
let shift = shift as u64;
let a = a as u64;
let b = b as u64;
let y = (((a * y + b) >> 32) >> shift) as i32;
if x < 0 { -y } else { y }
let y = if x < 0 { -x } else { x } as u64;
let (a, b, shift) = d;
let shift = shift as u64;
let a = a as u64;
let b = b as u64;
let y = (((a * y + b) >> 32) >> shift) as i32;
if x < 0 {
-y
} else {
y
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_divu_pair() {
for d in 1..1024 {
for x in -1000..1000 {
let ab = divu_gen(d as u32);
assert_eq!(x/d, divu_pair(x, ab));
}
}
use super::*;
#[test]
fn test_divu_pair() {
for d in 1..1024 {
for x in -1000..1000 {
let ab = divu_gen(d as u32);
assert_eq!(x / d, divu_pair(x, ab));
}
}
#[test]
fn gen_divu_table() {
let b: Vec<(u32, u32, u32)> = dc_qlookup_Q3.iter().map(|&v| {
divu_gen(v as u32)
}).collect();
}
#[test]
fn gen_divu_table() {
let b: Vec<(u32, u32, u32)> =
dc_qlookup_Q3.iter().map(|&v| divu_gen(v as u32)).collect();
println!("{:?}", b);
}
println!("{:?}", b);
}
}
impl QuantizationContext {
pub fn update(&mut self, qindex: usize, tx_size: TxSize) {
self.tx_scale = get_tx_scale(tx_size) as i32;
pub fn update(&mut self, qindex: usize, tx_size: TxSize) {
self.tx_scale = get_tx_scale(tx_size) as i32;
self.dc_quant = dc_q(qindex) as u32;
self.dc_mul_add = divu_gen(self.dc_quant);
self.dc_quant = dc_q(qindex) as u32;
self.dc_mul_add = divu_gen(self.dc_quant);
self.ac_quant = ac_q(qindex) as u32;
self.ac_mul_add = divu_gen(self.ac_quant);
self.ac_quant = ac_q(qindex) as u32;
self.ac_mul_add = divu_gen(self.ac_quant);
self.dc_offset = self.dc_quant as i32 * 21 / 64;
self.ac_offset = self.ac_quant as i32 * 21 / 64;
}
self.dc_offset = self.dc_quant as i32 * 21 / 64;
self.ac_offset = self.ac_quant as i32 * 21 / 64;
}
#[inline]
pub fn quantize(&self, coeffs: &mut [i32]) {
coeffs[0] *= self.tx_scale;
coeffs[0] += coeffs[0].signum() * self.dc_offset;
coeffs[0] = divu_pair(coeffs[0], self.dc_mul_add);
#[inline]
pub fn quantize(&self, coeffs: &mut [i32]) {
coeffs[0] *= self.tx_scale;
coeffs[0] += coeffs[0].signum() * self.dc_offset;
coeffs[0] = divu_pair(coeffs[0], self.dc_mul_add);
for c in coeffs[1..].iter_mut() {
*c *= self.tx_scale;
*c += c.signum() * self.ac_offset;
*c = divu_pair(*c, self.ac_mul_add);
}
for c in coeffs[1..].iter_mut() {
*c *= self.tx_scale;
*c += c.signum() * self.ac_offset;
*c = divu_pair(*c, self.ac_mul_add);
}
}
}
pub fn quantize_in_place(qindex: usize, coeffs: &mut [i32], tx_size: TxSize) {
let tx_scale = get_tx_scale(tx_size) as i32;
......
......@@ -117,11 +117,7 @@ pub fn rdo_mode_decision(
let w = bsize.width();
let h = bsize.height();
let PlaneConfig {
xdec,
ydec,
..
} = fs.input.planes[1].cfg;
let PlaneConfig { xdec, ydec, .. } = fs.input.planes[1].cfg;
let mut w_uv = w >> xdec;
let mut h_uv = h >> ydec;
......@@ -244,11 +240,7 @@ pub fn rdo_tx_type_decision(
let w = bsize.width();
let h = bsize.height();
let PlaneConfig {
xdec,
ydec,
..
} = fs.input.planes[1].cfg;
let PlaneConfig { xdec, ydec, .. } = fs.input.planes[1].cfg;
let mut w_uv = w >> xdec;
let mut h_uv = h >> ydec;
......@@ -345,37 +337,26 @@ pub fn rdo_partition_decision(
let bs = bsize.width_mi();
let hbs = bs >> 1; // Half the block size in blocks
let offset = BlockOffset {
x: bo.x,
y: bo.y
};
let offset = BlockOffset { x: bo.x, y: bo.y };
let mode_decision = rdo_mode_decision(fi, fs, cw, subsize, &offset)
.part_modes[0]
.clone();
child_modes.push(mode_decision);
let offset = BlockOffset {
x: bo.x + hbs as usize,
y: bo.y
};
let offset = BlockOffset { x: bo.x + hbs as usize, y: bo.y };
let mode_decision = rdo_mode_decision(fi, fs, cw, subsize, &offset)
.part_modes[0]
.clone();
child_modes.push(mode_decision);
let offset = BlockOffset {
x: bo.x,
y: bo.y + hbs as usize
};
let offset = BlockOffset { x: bo.x, y: bo.y + hbs as usize };
let mode_decision = rdo_mode_decision(fi, fs, cw, subsize, &offset)
.part_modes[0]
.clone();
child_modes.push(mode_decision);
let offset = BlockOffset {
x: bo.x + hbs as usize,
y: bo.y + hbs as usize
};
let offset =
BlockOffset { x: bo.x + hbs as usize, y: bo.y + hbs as usize };
let mode_decision = rdo_mode_decision(fi, fs, cw, subsize, &offset)
.part_modes[0]
.clone();
......
......@@ -15,7 +15,7 @@ struct Align16;
/// ```
/// extern crate rav1e;
/// use rav1e::util::*;
///
///
/// let mut x: AlignedArray<[i16; 64 * 64]> = AlignedArray([0; 64 * 64]);
/// assert!(x.array.as_ptr() as usize % 16 == 0);
///
......@@ -32,10 +32,7 @@ where
#[allow(non_snake_case)]
pub fn AlignedArray<ARRAY>(array: ARRAY) -> AlignedArray<ARRAY> {
AlignedArray {
_alignment: [],
array
}
AlignedArray { _alignment: [], array }
}
#[allow(non_snake_case)]
......
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