Commit 916badfa authored by Michael Bebenita's avatar Michael Bebenita Committed by Yushin Cho

Pad strides to 16 bytes.

parent a78777c6
......@@ -243,7 +243,7 @@ pub fn cdef_frame(fi: &FrameInvariants, rec: &mut Frame, bc: &mut BlockContext)
}
} else {
let rec_stride = rec.planes[p].cfg.stride;
cdef_row.copy_from_slice(&rec.planes[p].data[(row-2)*rec_stride..(row-1)*rec_stride]);
cdef_row.copy_from_slice(&rec.planes[p].data[(row-2)*rec_stride..(row-1)*rec_stride][..rec_w]);
}
}
}
......
......@@ -237,32 +237,6 @@ impl FrameState {
}
}
trait Fixed {
fn floor_log2(&self, n: usize) -> usize;
fn ceil_log2(&self, n: usize) -> usize;
fn align_power_of_two(&self, n: usize) -> usize;
fn align_power_of_two_and_shift(&self, n: usize) -> usize;
}
impl Fixed for usize {
#[inline]
fn floor_log2(&self, n: usize) -> usize {
self & !((1 << n) - 1)
}
#[inline]
fn ceil_log2(&self, n: usize) -> usize {
(self + (1 << n) - 1).floor_log2(n)
}
#[inline]
fn align_power_of_two(&self, n: usize) -> usize {
self.ceil_log2(n)
}
#[inline]
fn align_power_of_two_and_shift(&self, n: usize) -> usize {
(self + (1 << n) - 1) >> n
}
}
// Frame Invariants are invariant inside a frame
#[allow(dead_code)]
#[derive(Debug)]
......@@ -2145,7 +2119,7 @@ mod test_encode_decode {
}
// TODO: support non-multiple-of-16 dimensions
static DIMENSION_OFFSETS: &[(usize, usize)] = &[(0, 0), (16, 16)];
static DIMENSION_OFFSETS: &[(usize, usize)] = &[(0, 0), (4, 4), (8, 8), (16, 16)];
#[test]
#[ignore]
......
......@@ -9,6 +9,8 @@
#![cfg_attr(feature = "cargo-clippy", allow(cast_lossless))]
use util::*;
/// Plane-specific configuration.
#[derive(Debug, Clone)]
pub struct PlaneConfig {
......@@ -34,9 +36,10 @@ pub struct Plane {
impl Plane {
pub fn new(width: usize, height: usize, xdec: usize, ydec: usize) -> Plane {
let stride = width.align_power_of_two(4); // Force 16 byte alignment.
Plane {
data: vec![128; width * height],
cfg: PlaneConfig { stride: width, width, height, xdec, ydec }
data: vec![128; stride * height],
cfg: PlaneConfig { stride, width, height, xdec, ydec }
}
}
......
......@@ -46,3 +46,29 @@ fn sanity() {
let a: AlignedArray<_> = AlignedArray([0u8; 3]);
assert!(a.array.as_ptr() as usize % 16 == 0);
}
pub trait Fixed {
fn floor_log2(&self, n: usize) -> usize;
fn ceil_log2(&self, n: usize) -> usize;
fn align_power_of_two(&self, n: usize) -> usize;
fn align_power_of_two_and_shift(&self, n: usize) -> usize;
}
impl Fixed for usize {
#[inline]
fn floor_log2(&self, n: usize) -> usize {
self & !((1 << n) - 1)
}
#[inline]
fn ceil_log2(&self, n: usize) -> usize {
(self + (1 << n) - 1).floor_log2(n)
}
#[inline]
fn align_power_of_two(&self, n: usize) -> usize {
self.ceil_log2(n)
}
#[inline]
fn align_power_of_two_and_shift(&self, n: usize) -> usize {
(self + (1 << n) - 1) >> n
}
}
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