Skip to content

Commit

Permalink
fn BitDepth::pxstride: Remove unnecessary casts when invoking
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Bossen authored and fbossen committed Mar 5, 2024
1 parent 44830a1 commit 58dc72d
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 179 deletions.
54 changes: 24 additions & 30 deletions src/ipred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ unsafe fn splat_dc<BD: BitDepth>(
x = (x as c_ulong).wrapping_add(::core::mem::size_of::<u64>() as c_ulong >> 1)
as c_int as c_int;
}
dst = dst.offset(BD::pxstride(stride as usize) as isize);
dst = dst.offset(BD::pxstride(stride));
y += 1;
}
}
Expand All @@ -248,7 +248,7 @@ unsafe fn cfl_pred<BD: BitDepth>(
x += 1;
}
ac = ac.offset(width as isize);
dst = dst.offset(BD::pxstride(stride as usize) as isize);
dst = dst.offset(BD::pxstride(stride));
y += 1;
}
}
Expand Down Expand Up @@ -422,7 +422,7 @@ unsafe fn ipred_v_rust<BD: BitDepth>(
&slice::from_raw_parts(topleft, width + 1)[1..],
width,
);
dst = dst.offset(BD::pxstride(stride as usize) as isize);
dst = dst.offset(BD::pxstride(stride));
y += 1;
}
}
Expand Down Expand Up @@ -471,7 +471,7 @@ unsafe fn ipred_h_rust<BD: BitDepth>(
*topleft.offset(-(1 + y) as isize),
width,
);
dst = dst.offset(BD::pxstride(stride as usize) as isize);
dst = dst.offset(BD::pxstride(stride));
y += 1;
}
}
Expand Down Expand Up @@ -532,7 +532,7 @@ unsafe fn ipred_paeth_rust<BD: BitDepth>(
.as_::<BD::Pixel>();
x += 1;
}
dst = dst.offset(BD::pxstride(stride as usize) as isize);
dst = dst.offset(BD::pxstride(stride));
y += 1;
}
}
Expand Down Expand Up @@ -589,7 +589,7 @@ unsafe fn ipred_smooth_rust<BD: BitDepth>(
*dst.offset(x as isize) = (pred + 256 >> 9).as_::<BD::Pixel>();
x += 1;
}
dst = dst.offset(BD::pxstride(stride as usize) as isize);
dst = dst.offset(BD::pxstride(stride));
y += 1;
}
}
Expand Down Expand Up @@ -641,7 +641,7 @@ unsafe fn ipred_smooth_v_rust<BD: BitDepth>(
*dst.offset(x as isize) = (pred + 128 >> 8).as_::<BD::Pixel>();
x += 1;
}
dst = dst.offset(BD::pxstride(stride as usize) as isize);
dst = dst.offset(BD::pxstride(stride));
y += 1;
}
}
Expand Down Expand Up @@ -693,7 +693,7 @@ unsafe fn ipred_smooth_h_rust<BD: BitDepth>(
*dst.offset(x as isize) = (pred + 128 >> 8).as_::<BD::Pixel>();
x += 1;
}
dst = dst.offset(BD::pxstride(stride as usize) as isize);
dst = dst.offset(BD::pxstride(stride));
y += 1;
}
}
Expand Down Expand Up @@ -936,7 +936,7 @@ unsafe fn ipred_z1_rust<BD: BitDepth>(
}
}
y += 1;
dst = dst.offset(BD::pxstride(stride as usize) as isize);
dst = dst.offset(BD::pxstride(stride));
xpos += dx;
}
}
Expand Down Expand Up @@ -1074,7 +1074,7 @@ unsafe fn ipred_z2_rust<BD: BitDepth>(
}
y += 1;
xpos -= dx;
dst = dst.offset(BD::pxstride(stride as usize) as isize);
dst = dst.offset(BD::pxstride(stride));
}
}

Expand Down Expand Up @@ -1154,16 +1154,14 @@ unsafe fn ipred_z3_rust<BD: BitDepth>(
if base < max_base_y {
let v = (*left.offset(-base as isize)).as_::<c_int>() * (64 - frac)
+ (*left.offset(-(base + 1) as isize)).as_::<c_int>() * frac;
*dst.offset(
(y as isize * BD::pxstride(stride as usize) as isize + x as isize) as isize,
) = (v + 32 >> 6).as_::<BD::Pixel>();
*dst.offset((y as isize * BD::pxstride(stride) + x as isize) as isize) =
(v + 32 >> 6).as_::<BD::Pixel>();
y += 1;
base += base_inc;
} else {
loop {
*dst.offset(
(y as isize * BD::pxstride(stride as usize) as isize + x as isize) as isize,
) = *left.offset(-max_base_y as isize);
*dst.offset((y as isize * BD::pxstride(stride) + x as isize) as isize) =
*left.offset(-max_base_y as isize);
y += 1;
if !(y < height) {
break;
Expand Down Expand Up @@ -1281,17 +1279,17 @@ unsafe fn ipred_filter_rust<BD: BitDepth>(
xx += 1;
flt_ptr = flt_ptr.offset(FLT_INCR);
}
ptr = ptr.offset(BD::pxstride(stride as usize) as isize);
ptr = ptr.offset(BD::pxstride(stride));
yy += 1;
}
left = &mut *dst.offset((x + 4 - 1) as isize) as *mut BD::Pixel;
left_stride = BD::pxstride(stride as usize) as isize;
left_stride = BD::pxstride(stride);
top = top.offset(4);
topleft = &*top.offset(-(1 as c_int) as isize) as *const BD::Pixel;
x += 4 as c_int;
}
top = &mut *dst.offset(BD::pxstride(stride as usize) as isize) as *mut BD::Pixel;
dst = &mut *dst.offset((BD::pxstride(stride as usize) * 2) as isize) as *mut BD::Pixel;
top = &mut *dst.offset(BD::pxstride(stride)) as *mut BD::Pixel;
dst = &mut *dst.offset(BD::pxstride(stride) * 2) as *mut BD::Pixel;
y += 2 as c_int;
}
}
Expand Down Expand Up @@ -1350,15 +1348,11 @@ unsafe fn cfl_ac_rust<BD: BitDepth>(
ac_sum += (*ypx.offset((x * 2 + 1) as isize)).as_::<c_int>();
}
if ss_ver != 0 {
ac_sum += (*ypx.offset(
((x << ss_hor) as isize + BD::pxstride(stride as usize) as isize) as isize,
))
.as_::<c_int>();
if ss_hor != 0 {
ac_sum += (*ypx.offset(
((x * 2 + 1) as isize + BD::pxstride(stride as usize) as isize) as isize,
))
ac_sum += (*ypx.offset(((x << ss_hor) as isize + BD::pxstride(stride)) as isize))
.as_::<c_int>();
if ss_hor != 0 {
ac_sum += (*ypx.offset(((x * 2 + 1) as isize + BD::pxstride(stride)) as isize))
.as_::<c_int>();
}
}
*ac.offset(x as isize) =
Expand All @@ -1370,7 +1364,7 @@ unsafe fn cfl_ac_rust<BD: BitDepth>(
x += 1;
}
ac = ac.offset(width as isize);
ypx = ypx.offset((BD::pxstride(stride as usize) << ss_ver) as isize);
ypx = ypx.offset(BD::pxstride(stride) << ss_ver);
y += 1;
}
while y < height {
Expand Down Expand Up @@ -1449,7 +1443,7 @@ unsafe fn pal_pred_rust<BD: BitDepth>(
x += 1;
}
idx = idx.offset(w as isize);
dst = dst.offset(BD::pxstride(stride as usize) as isize);
dst = dst.offset(BD::pxstride(stride));
y += 1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ipred_prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub fn rav1d_prepare_intra_edges<BD: BitDepth>(
assert!(y < h && x < w);

let bitdepth = bd.bitdepth();
let stride = BD::pxstride(stride as usize) as isize;
let stride = BD::pxstride(stride);

let dst_offset = 4 * x as usize
+ (if stride >= 0 { 4 * y } else { 4 * (h - y) - 1 }) as usize * stride.unsigned_abs();
Expand Down
12 changes: 6 additions & 6 deletions src/loopfilter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,15 +775,15 @@ unsafe fn loop_filter_h_sb128y_rust<BD: BitDepth>(
E,
I,
H,
BD::pxstride(stride as usize) as isize,
BD::pxstride(stride),
1 as c_int as ptrdiff_t,
(4 as c_int) << idx,
bd,
);
}
}
y <<= 1;
dst = dst.offset(4 * BD::pxstride(stride as usize) as isize);
dst = dst.offset(4 * BD::pxstride(stride));
l = l.offset(b4_stride as isize);
}
}
Expand Down Expand Up @@ -844,7 +844,7 @@ unsafe fn loop_filter_v_sb128y_rust<BD: BitDepth>(
I,
H,
1 as c_int as ptrdiff_t,
BD::pxstride(stride as usize) as isize,
BD::pxstride(stride),
(4 as c_int) << idx,
bd,
);
Expand Down Expand Up @@ -907,15 +907,15 @@ unsafe fn loop_filter_h_sb128uv_rust<BD: BitDepth>(
E,
I,
H,
BD::pxstride(stride as usize) as isize,
BD::pxstride(stride),
1 as c_int as ptrdiff_t,
4 + 2 * idx,
bd,
);
}
}
y <<= 1;
dst = dst.offset(4 * BD::pxstride(stride as usize) as isize);
dst = dst.offset(4 * BD::pxstride(stride));
l = l.offset(b4_stride as isize);
}
}
Expand Down Expand Up @@ -972,7 +972,7 @@ unsafe fn loop_filter_v_sb128uv_rust<BD: BitDepth>(
I,
H,
1 as c_int as ptrdiff_t,
BD::pxstride(stride as usize) as isize,
BD::pxstride(stride),
4 + 2 * idx,
bd,
);
Expand Down
16 changes: 8 additions & 8 deletions src/looprestoration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ unsafe fn padding<BD: BitDepth>(
stripe_h: usize,
edges: LrEdgeFlags,
) {
let stride = BD::pxstride(stride as usize);
let stride = BD::pxstride(stride);

let [have_left, have_right, have_top, have_bottom] =
[LR_HAVE_LEFT, LR_HAVE_RIGHT, LR_HAVE_TOP, LR_HAVE_BOTTOM]
Expand Down Expand Up @@ -363,7 +363,7 @@ unsafe fn wiener_rust<BD: BitDepth>(
sum += z[k * REST_UNIT_STRIDE] as c_int * filter[1][k] as c_int;
}

*p.offset(j as isize * BD::pxstride(stride as usize) as isize + i as isize) =
*p.offset(j as isize * BD::pxstride(stride) + i as isize) =
iclip(sum + rounding_off_v >> round_bits_v, 0, bd.into_c()).as_();
}
}
Expand Down Expand Up @@ -754,7 +754,7 @@ unsafe fn sgr_5x5_rust<BD: BitDepth>(
*p.offset(i as isize) =
bd.iclip_pixel((*p.offset(i as isize)).as_::<c_int>() + (v + (1 << 10) >> 11));
}
p = p.offset(BD::pxstride(stride as usize) as isize);
p = p.offset(BD::pxstride(stride));
}
}

Expand Down Expand Up @@ -824,7 +824,7 @@ unsafe fn sgr_3x3_rust<BD: BitDepth>(
*p.offset(i as isize) =
bd.iclip_pixel((*p.offset(i as isize)).as_::<c_int>() + (v + (1 << 10) >> 11));
}
p = p.offset(BD::pxstride(stride as usize) as isize);
p = p.offset(BD::pxstride(stride));
}
}

Expand Down Expand Up @@ -907,7 +907,7 @@ unsafe fn sgr_mix_rust<BD: BitDepth>(
*p.offset(i as isize) =
bd.iclip_pixel((*p.offset(i as isize)).as_::<c_int>() + (v + (1 << 10) >> 11));
}
p = p.offset(BD::pxstride(stride as usize) as isize);
p = p.offset(BD::pxstride(stride));
}
}

Expand Down Expand Up @@ -1071,7 +1071,7 @@ unsafe fn wiener_filter_neon<BD: BitDepth>(
rav1d_wiener_filter_h_neon(
&mut mid.0[(2 + h as usize) * mid_stride as usize..],
core::ptr::null(),
lpf.offset((6 * BD::pxstride(stride as usize)) as isize),
lpf.offset(6 * BD::pxstride(stride)),
stride,
filter.offset(0),
w as intptr_t,
Expand Down Expand Up @@ -1202,7 +1202,7 @@ unsafe fn rav1d_sgr_filter1_neon<BD: BitDepth>(
&mut *sumsq.offset((h * (384 + 16)) as isize),
&mut *sum.offset((h * (384 + 16)) as isize),
0 as *const [BD::Pixel; 4],
lpf.offset((6 * BD::pxstride(stride as usize)) as isize),
lpf.offset(6 * BD::pxstride(stride)),
stride,
w,
2 as c_int,
Expand Down Expand Up @@ -1323,7 +1323,7 @@ unsafe fn rav1d_sgr_filter2_neon<BD: BitDepth>(
&mut *sumsq.offset((h * (384 + 16)) as isize),
&mut *sum.offset((h * (384 + 16)) as isize),
0 as *const [BD::Pixel; 4],
lpf.offset((6 * BD::pxstride(stride as usize)) as isize),
lpf.offset(6 * BD::pxstride(stride)),
stride,
w,
2 as c_int,
Expand Down
20 changes: 9 additions & 11 deletions src/lr_apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ unsafe fn lr_stripe<BD: BitDepth>(
let stride: ptrdiff_t = f.sr_cur.p.stride[chroma as usize];
let sby = y + (if y != 0 { 8 << ss_ver } else { 0 }) >> 6 - ss_ver + seq_hdr.sb128;
let have_tt = (c.tc.len() > 1) as c_int;
let lpf_stride = BD::pxstride(stride as usize) as isize;
let lpf_plane_sz = BD::pxstride(f.lf.lr_buf_plane_sz[(plane != 0) as usize] as usize) as isize;
let lpf_stride = BD::pxstride(stride);
let lpf_plane_sz = BD::pxstride(f.lf.lr_buf_plane_sz[(plane != 0) as usize] as isize);
let mut lpf_offset = cmp::max(lpf_stride - lpf_plane_sz, 0);
let lpf = &slice::from_raw_parts(
(f.lf.lr_lpf_line[plane as usize] as *const BD::Pixel).offset(-lpf_offset),
Expand Down Expand Up @@ -112,7 +112,7 @@ unsafe fn lr_stripe<BD: BitDepth>(
);
left = &left[stripe_h as usize..];
y += stripe_h;
let p_offset = stripe_h as isize * BD::pxstride(stride as usize) as isize;
let p_offset = stripe_h as isize * BD::pxstride(stride);
edges |= LR_HAVE_TOP;
stripe_h = cmp::min(64 >> ss_ver, row_h - y);
if stripe_h == 0 {
Expand Down Expand Up @@ -262,8 +262,8 @@ pub(crate) unsafe fn rav1d_lr_sbrow<BD: BitDepth>(
lr_sbrow::<BD>(
c,
f,
&mut dst[0][dst_offset[0]
- (offset_y as isize * BD::pxstride(dst_stride[0] as usize) as isize) as usize..],
&mut dst[0]
[dst_offset[0] - (offset_y as isize * BD::pxstride(dst_stride[0])) as usize..],
y_stripe,
w,
h,
Expand All @@ -284,9 +284,8 @@ pub(crate) unsafe fn rav1d_lr_sbrow<BD: BitDepth>(
lr_sbrow::<BD>(
c,
f,
&mut dst[1][dst_offset[1]
- (offset_uv as isize * BD::pxstride(dst_stride[1] as usize) as isize)
as usize..],
&mut dst[1]
[dst_offset[1] - (offset_uv as isize * BD::pxstride(dst_stride[1])) as usize..],
y_stripe,
w,
h,
Expand All @@ -298,9 +297,8 @@ pub(crate) unsafe fn rav1d_lr_sbrow<BD: BitDepth>(
lr_sbrow::<BD>(
c,
f,
&mut dst[2][dst_offset[1]
- (offset_uv as isize * BD::pxstride(dst_stride[1] as usize) as isize)
as usize..],
&mut dst[2]
[dst_offset[1] - (offset_uv as isize * BD::pxstride(dst_stride[1])) as usize..],
y_stripe,
w,
h,
Expand Down
Loading

0 comments on commit 58dc72d

Please sign in to comment.