Resolve the deblock kernels' bit-depth reads once per call
Browse files at this commit801fe73e920a29f6052bc005df88f97285043276Parent: 583ed90- perf
- resolve the deblock kernels' bit-depth reads once per call
1 changed file +22 -16
- crates/ec-av1/src/decode.rs +22 -16
crates/ec-av1/src/decode.rsmodified+22 -16
| @@ -15996,7 +15996,12 @@ fn filter4(mask: bool, thresh: i32, p1: i32, p0: i32, q0: i32, q1: i32) -> [i32; | ||
| 15996 | 15996 | return [p1, p0, q0, q1]; |
| 15997 | 15997 | } |
| 15998 | 15998 | let hev = (p1 - p0).abs() > thresh || (q1 - q0).abs() > thresh; |
| 15999 | - let centre = 128i32 << (bit_depth() - 8); | |
| 15999 | + // lane-perf6: `sclamp` re-read the thread-local bit depth on every one of | |
| 16000 | + // this kernel's eight clamps, and this kernel runs per deblocked sample. | |
| 16001 | + // Same bound, resolved once. | |
| 16002 | + let scale = 1i32 << (bit_depth() - 8); | |
| 16003 | + let sclamp = |v: i32| v.clamp(-128 * scale, 128 * scale - 1); | |
| 16004 | + let centre = 128i32 * scale; | |
| 16000 | 16005 | let (ps1, ps0, qs0, qs1) = (p1 - centre, p0 - centre, q0 - centre, q1 - centre); |
| 16001 | 16006 | let outer = if hev { sclamp(ps1 - qs1) } else { 0 }; |
| 16002 | 16007 | let filter = sclamp(outer + 3 * (qs0 - ps0)); |
| @@ -16164,6 +16169,7 @@ fn filter_edge( | ||
| 16164 | 16169 | let shift = bit_depth() - 8; |
| 16165 | 16170 | let (blimit, limit, hev_thr) = (blimit << shift, limit << shift, hev_thr << shift); |
| 16166 | 16171 | let flat_thresh = 1i32 << shift; |
| 16172 | + let smax = sample_max(); | |
| 16167 | 16173 | for i in 0..4isize { |
| 16168 | 16174 | let center = (base as isize + i * outer_stride) as usize; |
| 16169 | 16175 | let idx = |k: isize| -> usize { (center as isize + k * tap_stride) as usize }; |
| @@ -16175,10 +16181,10 @@ fn filter_edge( | ||
| 16175 | 16181 | && (q1 - q0).abs() <= limit |
| 16176 | 16182 | && (p0 - q0).abs() * 2 + (p1 - q1).abs() / 2 <= blimit; |
| 16177 | 16183 | let [op1, op0, oq0, oq1] = filter4(mask, hev_thr, p1, p0, q0, q1); |
| 16178 | - data[idx(-2)] = op1.clamp(0, sample_max()) as u16; | |
| 16179 | - data[idx(-1)] = op0.clamp(0, sample_max()) as u16; | |
| 16180 | - data[idx(0)] = oq0.clamp(0, sample_max()) as u16; | |
| 16181 | - data[idx(1)] = oq1.clamp(0, sample_max()) as u16; | |
| 16184 | + data[idx(-2)] = op1.clamp(0, smax) as u16; | |
| 16185 | + data[idx(-1)] = op0.clamp(0, smax) as u16; | |
| 16186 | + data[idx(0)] = oq0.clamp(0, smax) as u16; | |
| 16187 | + data[idx(1)] = oq1.clamp(0, smax) as u16; | |
| 16182 | 16188 | } |
| 16183 | 16189 | 6 => { |
| 16184 | 16190 | let (p2, p1, p0, q0, q1, q2) = (px(-3), px(-2), px(-1), px(0), px(1), px(2)); |
| @@ -16192,10 +16198,10 @@ fn filter_edge( | ||
| 16192 | 16198 | && (p2 - p0).abs() <= flat_thresh |
| 16193 | 16199 | && (q2 - q0).abs() <= flat_thresh; |
| 16194 | 16200 | let [op1, op0, oq0, oq1] = filter6(mask, hev_thr, flat, p2, p1, p0, q0, q1, q2); |
| 16195 | - data[idx(-2)] = op1.clamp(0, sample_max()) as u16; | |
| 16196 | - data[idx(-1)] = op0.clamp(0, sample_max()) as u16; | |
| 16197 | - data[idx(0)] = oq0.clamp(0, sample_max()) as u16; | |
| 16198 | - data[idx(1)] = oq1.clamp(0, sample_max()) as u16; | |
| 16201 | + data[idx(-2)] = op1.clamp(0, smax) as u16; | |
| 16202 | + data[idx(-1)] = op0.clamp(0, smax) as u16; | |
| 16203 | + data[idx(0)] = oq0.clamp(0, smax) as u16; | |
| 16204 | + data[idx(1)] = oq1.clamp(0, smax) as u16; | |
| 16199 | 16205 | } |
| 16200 | 16206 | 8 => { |
| 16201 | 16207 | let (p3, p2, p1, p0, q0, q1, q2, q3) = |
| @@ -16215,12 +16221,12 @@ fn filter_edge( | ||
| 16215 | 16221 | && (q3 - q0).abs() <= flat_thresh; |
| 16216 | 16222 | let [op2, op1, op0, oq0, oq1, oq2] = |
| 16217 | 16223 | filter8(mask, hev_thr, flat, p3, p2, p1, p0, q0, q1, q2, q3); |
| 16218 | - data[idx(-3)] = op2.clamp(0, sample_max()) as u16; | |
| 16219 | - data[idx(-2)] = op1.clamp(0, sample_max()) as u16; | |
| 16220 | - data[idx(-1)] = op0.clamp(0, sample_max()) as u16; | |
| 16221 | - data[idx(0)] = oq0.clamp(0, sample_max()) as u16; | |
| 16222 | - data[idx(1)] = oq1.clamp(0, sample_max()) as u16; | |
| 16223 | - data[idx(2)] = oq2.clamp(0, sample_max()) as u16; | |
| 16224 | + data[idx(-3)] = op2.clamp(0, smax) as u16; | |
| 16225 | + data[idx(-2)] = op1.clamp(0, smax) as u16; | |
| 16226 | + data[idx(-1)] = op0.clamp(0, smax) as u16; | |
| 16227 | + data[idx(0)] = oq0.clamp(0, smax) as u16; | |
| 16228 | + data[idx(1)] = oq1.clamp(0, smax) as u16; | |
| 16229 | + data[idx(2)] = oq2.clamp(0, smax) as u16; | |
| 16224 | 16230 | } |
| 16225 | 16231 | _ => { |
| 16226 | 16232 | let (p6, p5, p4, p3, p2, p1, p0) = |
| @@ -16251,7 +16257,7 @@ fn filter_edge( | ||
| 16251 | 16257 | q6, |
| 16252 | 16258 | ); |
| 16253 | 16259 | for (k, v) in (-6..=5isize).zip(out) { |
| 16254 | - data[idx(k)] = v.clamp(0, sample_max()) as u16; | |
| 16260 | + data[idx(k)] = v.clamp(0, smax) as u16; | |
| 16255 | 16261 | } |
| 16256 | 16262 | } |
| 16257 | 16263 | } |