forge
Explore
Log in

Don't you dare go Hollow

U15: ec-prores merge the two DC-only shortcuts into reference::put_dc, drop allow(dead_code) on reference (rustc flags nothing)

Browse files at this commit

bd0a0d299825b9a02d9c5ea6234efc0d4ef1d06aAhmet Kaan GümüşParent: 96d0c86
crates/ec-prores/src/idct.rsmodified+17 -23
@@ -13,8 +13,6 @@ use wide::{i16x8, i32x4, i32x8};
13 13
14 /// Scalar implementation in raster layout, a line-for-line port of ffmpeg's.14 /// Scalar implementation in raster layout, a line-for-line port of ffmpeg's.
15 pub mod reference {15 pub mod reference {
16- #![allow(dead_code)]
17-
18 pub struct K {16 pub struct K {
19 /// `a` (even part) coefficient rows for r2, r4, r6.17 /// `a` (even part) coefficient rows for r2, r4, r6.
20 pub a2: [i32; 4],18 pub a2: [i32; 4],
@@ -119,6 +117,20 @@ pub mod reference {
119 out117 out
120 }118 }
121 119
120+ pub fn put_dc<const B12: bool>(dst: &mut [u8], stride: usize, dc: i16) {
121+ let k = if B12 { &K12 } else { &K10 };
122+ let (lo, hi): (i16, i16) = if B12 { (4, 4091) } else { (4, 1019) };
123+ let t = (i32::from(dc).wrapping_add(1) >> 1) as i16;
124+ let c0 = t.wrapping_add(8192) as i32;
125+ let bias = (1i32 << (k.col_shift - 1)) / k.w4;
126+ let v = ((k.w4.wrapping_mul(c0.wrapping_add(bias)) >> k.col_shift) as i16).clamp(lo, hi) as u16;
127+ for r in 0..8 {
128+ for c in dst[r * stride * 2..r * stride * 2 + 16].as_chunks_mut::<2>().0.iter_mut() {
129+ *c = v.to_le_bytes();
130+ }
131+ }
132+ }
133+
122 /// Run the IDCT on an already dequantised `block` and store the clipped 8x8 result at134 /// Run the IDCT on an already dequantised `block` and store the clipped 8x8 result at
123 /// `dst[0]`, row pitch `stride`. With `dc_only` only `block[0]` is read (the block's other135 /// `dst[0]`, row pitch `stride`. With `dc_only` only `block[0]` is read (the block's other
124 /// coefficients are zero), which is exact: the shortcut rows and columns of the full136 /// coefficients are zero), which is exact: the shortcut rows and columns of the full
@@ -128,15 +140,7 @@ pub mod reference {
128 let k = if B12 { &K12 } else { &K10 };140 let k = if B12 { &K12 } else { &K10 };
129 let (lo, hi): (i16, i16) = if B12 { (4, 4091) } else { (4, 1019) };141 let (lo, hi): (i16, i16) = if B12 { (4, 4091) } else { (4, 1019) };
130 if dc_only {142 if dc_only {
131- let t = (i32::from(block[0]).wrapping_add(1) >> 1) as i16;143+ put_dc::<B12>(dst, stride, block[0]);
132- let c0 = t.wrapping_add(8192) as i32;
133- let bias = (1i32 << (k.col_shift - 1)) / k.w4;
134- let v = ((k.w4.wrapping_mul(c0.wrapping_add(bias)) >> k.col_shift) as i16).clamp(lo, hi) as u16;
135- for r in 0..8 {
136- for c in dst[r * stride * 2..r * stride * 2 + 16].as_chunks_mut::<2>().0.iter_mut() {
137- *c = v.to_le_bytes();
138- }
139- }
140 return;144 return;
141 }145 }
142 for r in 0..8 {146 for r in 0..8 {
@@ -153,7 +157,7 @@ pub mod reference {
153 }157 }
154 }158 }
155 159
156-use reference::{K10, K12};160+use reference::K10;
157 use archmage::{SimdToken, X64V1Token};161 use archmage::{SimdToken, X64V1Token};
158 use reference::K;162 use reference::K;
159 163
@@ -369,18 +373,8 @@ fn idct_put_10(dst: &mut [u8], stride: usize, block: &[i16; 64]) {
369 #[inline(always)]373 #[inline(always)]
370 pub fn idct_put<const B12: bool>(dst: &mut [u8], stride: usize, block: &mut [i16; 64]) {374 pub fn idct_put<const B12: bool>(dst: &mut [u8], stride: usize, block: &mut [i16; 64]) {
371 let dc_only = block[1..].iter().fold(0, |a, &x| a | x) == 0;375 let dc_only = block[1..].iter().fold(0, |a, &x| a | x) == 0;
372- let k = if B12 { &K12 } else { &K10 };
373- let (lo, hi): (i16, i16) = if B12 { (4, 4091) } else { (4, 1019) };
374 if dc_only {376 if dc_only {
375- let t = (i32::from(block[0]).wrapping_add(1) >> 1) as i16;377+ reference::put_dc::<B12>(dst, stride, block[0]);
376- let c0 = t.wrapping_add(8192) as i32;
377- let bias = (1i32 << (k.col_shift - 1)) / k.w4;
378- let v = ((k.w4.wrapping_mul(c0.wrapping_add(bias)) >> k.col_shift) as i16).clamp(lo, hi) as u16;
379- for r in 0..8 {
380- for c in dst[r * stride * 2..r * stride * 2 + 16].as_chunks_mut::<2>().0.iter_mut() {
381- *c = v.to_le_bytes();
382- }
383- }
384 return;378 return;
385 }379 }
386 if B12 {380 if B12 {