Skip to content

Commit

Permalink
Cleanup trivial redundant casts after removing most gotos (#427)
Browse files Browse the repository at this point in the history
This is a repeat of #166 after #425, since #425 heavily reduced
indentation, making a lot of the regexes from #166 now work.
  • Loading branch information
kkysen authored Aug 31, 2023
2 parents 00faf25 + da4ee09 commit 66f0ae1
Show file tree
Hide file tree
Showing 15 changed files with 494 additions and 634 deletions.
6 changes: 3 additions & 3 deletions src/cdef_tmpl_16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ unsafe extern "C" fn cdef_filter_block_c(
tmp, tmp_stride, dst, dst_stride, left, top, bottom, w, h, edges,
);
if pri_strength != 0 {
let bitdepth_min_8 = 32 as libc::c_int - clz(bitdepth_max as libc::c_uint) - 8;
let pri_tap = 4 as libc::c_int - (pri_strength >> bitdepth_min_8 & 1);
let bitdepth_min_8 = 32 - clz(bitdepth_max as libc::c_uint) - 8;
let pri_tap = 4 - (pri_strength >> bitdepth_min_8 & 1);
let pri_shift = imax(
0 as libc::c_int,
damping - ulog2(pri_strength as libc::c_uint),
Expand Down Expand Up @@ -393,7 +393,7 @@ unsafe fn cdef_find_dir_rust(
var: *mut libc::c_uint,
bitdepth_max: libc::c_int,
) -> libc::c_int {
let bitdepth_min_8 = 32 as libc::c_int - clz(bitdepth_max as libc::c_uint) - 8;
let bitdepth_min_8 = 32 - clz(bitdepth_max as libc::c_uint) - 8;
let mut partial_sum_hv: [[libc::c_int; 8]; 2] =
[[0 as libc::c_int, 0, 0, 0, 0, 0, 0, 0], [0; 8]];
let mut partial_sum_diag: [[libc::c_int; 15]; 2] = [
Expand Down
2 changes: 1 addition & 1 deletion src/cdef_tmpl_8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ unsafe extern "C" fn cdef_filter_block_c(
);
if pri_strength != 0 {
let bitdepth_min_8 = 8 - 8;
let pri_tap = 4 as libc::c_int - (pri_strength >> bitdepth_min_8 & 1);
let pri_tap = 4 - (pri_strength >> bitdepth_min_8 & 1);
let pri_shift = imax(
0 as libc::c_int,
damping - ulog2(pri_strength as libc::c_uint),
Expand Down
513 changes: 212 additions & 301 deletions src/decode.rs

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions src/filmgrain_tmpl_16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ unsafe extern "C" fn generate_grain_y_c(
data: *const Dav1dFilmGrainData,
bitdepth_max: libc::c_int,
) {
let bitdepth_min_8 = 32 as libc::c_int - clz(bitdepth_max as libc::c_uint) - 8;
let bitdepth_min_8 = 32 - clz(bitdepth_max as libc::c_uint) - 8;
let mut seed: libc::c_uint = (*data).seed;
let shift = 4 - bitdepth_min_8 + (*data).grain_scale_shift;
let grain_ctr = (128 as libc::c_int) << bitdepth_min_8;
Expand Down Expand Up @@ -472,7 +472,7 @@ unsafe extern "C" fn generate_grain_uv_c(
suby: libc::c_int,
bitdepth_max: libc::c_int,
) {
let bitdepth_min_8 = 32 as libc::c_int - clz(bitdepth_max as libc::c_uint) - 8;
let bitdepth_min_8 = 32 - clz(bitdepth_max as libc::c_uint) - 8;
let mut seed: libc::c_uint = (*data).seed
^ (if uv != 0 {
0x49d8 as libc::c_int
Expand Down Expand Up @@ -620,8 +620,8 @@ unsafe extern "C" fn sample_lut(
y: libc::c_int,
) -> entry {
let randval = (*offsets.offset(bx as isize))[by as usize];
let offx = 3 as libc::c_int + (2 >> subx) * (3 + (randval >> 4));
let offy = 3 as libc::c_int + (2 >> suby) * (3 + (randval & 0xf as libc::c_int));
let offx = 3 + (2 >> subx) * (3 + (randval >> 4));
let offy = 3 + (2 >> suby) * (3 + (randval & 0xf as libc::c_int));
return (*grain_lut.offset((offy + y + (32 >> suby) * by) as isize))
[(offx + x + (32 >> subx) * bx) as usize];
}
Expand All @@ -637,8 +637,8 @@ unsafe extern "C" fn fgy_32x32xn_c(
row_num: libc::c_int,
bitdepth_max: libc::c_int,
) {
let rows = 1 as libc::c_int + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let bitdepth_min_8 = 32 as libc::c_int - clz(bitdepth_max as libc::c_uint) - 8;
let rows = 1 + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let bitdepth_min_8 = 32 - clz(bitdepth_max as libc::c_uint) - 8;
let grain_ctr = (128 as libc::c_int) << bitdepth_min_8;
let grain_min = -grain_ctr;
let grain_max = grain_ctr - 1;
Expand Down Expand Up @@ -915,8 +915,8 @@ unsafe extern "C" fn fguv_32x32xn_c(
sy: libc::c_int,
bitdepth_max: libc::c_int,
) {
let rows = 1 as libc::c_int + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let bitdepth_min_8 = 32 as libc::c_int - clz(bitdepth_max as libc::c_uint) - 8;
let rows = 1 + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let bitdepth_min_8 = 32 - clz(bitdepth_max as libc::c_uint) - 8;
let grain_ctr = (128 as libc::c_int) << bitdepth_min_8;
let grain_min = -grain_ctr;
let grain_max = grain_ctr - 1;
Expand Down Expand Up @@ -1473,7 +1473,7 @@ unsafe extern "C" fn fgy_32x32xn_neon(
row_num: libc::c_int,
bitdepth_max: libc::c_int,
) {
let rows = 1 as libc::c_int + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let rows = 1 + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let mut seed: [libc::c_uint; 2] = [0; 2];
let mut i = 0;
while i < rows {
Expand Down Expand Up @@ -1541,7 +1541,7 @@ unsafe extern "C" fn fguv_32x32xn_420_neon(
is_id: libc::c_int,
bitdepth_max: libc::c_int,
) {
let rows = 1 as libc::c_int + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let rows = 1 + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let mut seed: [libc::c_uint; 2] = [0; 2];
let mut i = 0;
while i < rows {
Expand Down Expand Up @@ -1615,7 +1615,7 @@ unsafe extern "C" fn fguv_32x32xn_422_neon(
is_id: libc::c_int,
bitdepth_max: libc::c_int,
) {
let rows = 1 as libc::c_int + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let rows = 1 + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let mut seed: [libc::c_uint; 2] = [0; 2];
let mut i = 0;
while i < rows {
Expand Down Expand Up @@ -1689,7 +1689,7 @@ unsafe extern "C" fn fguv_32x32xn_444_neon(
is_id: libc::c_int,
bitdepth_max: libc::c_int,
) {
let rows = 1 as libc::c_int + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let rows = 1 + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let mut seed: [libc::c_uint; 2] = [0; 2];
let mut i = 0;
while i < rows {
Expand Down
16 changes: 8 additions & 8 deletions src/filmgrain_tmpl_8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,8 @@ unsafe extern "C" fn sample_lut(
y: libc::c_int,
) -> entry {
let randval = (*offsets.offset(bx as isize))[by as usize];
let offx = 3 as libc::c_int + (2 >> subx) * (3 + (randval >> 4));
let offy = 3 as libc::c_int + (2 >> suby) * (3 + (randval & 0xf as libc::c_int));
let offx = 3 + (2 >> subx) * (3 + (randval >> 4));
let offy = 3 + (2 >> suby) * (3 + (randval & 0xf as libc::c_int));
return (*grain_lut.offset((offy + y + (32 >> suby) * by) as isize))
[(offx + x + (32 >> subx) * bx) as usize];
}
Expand All @@ -561,7 +561,7 @@ unsafe extern "C" fn fgy_32x32xn_c(
bh: libc::c_int,
row_num: libc::c_int,
) {
let rows = 1 as libc::c_int + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let rows = 1 + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let bitdepth_min_8 = 8 - 8;
let grain_ctr = (128 as libc::c_int) << bitdepth_min_8;
let grain_min = -grain_ctr;
Expand Down Expand Up @@ -838,7 +838,7 @@ unsafe extern "C" fn fguv_32x32xn_c(
sx: libc::c_int,
sy: libc::c_int,
) {
let rows = 1 as libc::c_int + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let rows = 1 + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let bitdepth_min_8 = 8 - 8;
let grain_ctr = (128 as libc::c_int) << bitdepth_min_8;
let grain_min = -grain_ctr;
Expand Down Expand Up @@ -1378,7 +1378,7 @@ unsafe extern "C" fn fgy_32x32xn_neon(
bh: libc::c_int,
row_num: libc::c_int,
) {
let rows = 1 as libc::c_int + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let rows = 1 + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let mut seed: [libc::c_uint; 2] = [0; 2];
let mut i = 0;
while i < rows {
Expand Down Expand Up @@ -1444,7 +1444,7 @@ unsafe extern "C" fn fguv_32x32xn_420_neon(
uv: libc::c_int,
is_id: libc::c_int,
) {
let rows = 1 as libc::c_int + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let rows = 1 + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let mut seed: [libc::c_uint; 2] = [0; 2];
let mut i = 0;
while i < rows {
Expand Down Expand Up @@ -1516,7 +1516,7 @@ unsafe extern "C" fn fguv_32x32xn_422_neon(
uv: libc::c_int,
is_id: libc::c_int,
) {
let rows = 1 as libc::c_int + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let rows = 1 + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let mut seed: [libc::c_uint; 2] = [0; 2];
let mut i = 0;
while i < rows {
Expand Down Expand Up @@ -1588,7 +1588,7 @@ unsafe extern "C" fn fguv_32x32xn_444_neon(
uv: libc::c_int,
is_id: libc::c_int,
) {
let rows = 1 as libc::c_int + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let rows = 1 + ((*data).overlap_flag != 0 && row_num > 0) as libc::c_int;
let mut seed: [libc::c_uint; 2] = [0; 2];
let mut i = 0;
while i < rows {
Expand Down
4 changes: 2 additions & 2 deletions src/lf_apply_tmpl_16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ unsafe extern "C" fn backup_lpf(
}
if lr_backup != 0 && (*(*f).frame_hdr).width[0] != (*(*f).frame_hdr).width[1] {
while row + stripe_h <= row_h {
let n_lines = 4 as libc::c_int - (row + stripe_h + 1 == h) as libc::c_int;
let n_lines = 4 - (row + stripe_h + 1 == h) as libc::c_int;
((*(*f).dsp).mc.resize).expect("non-null function pointer")(
dst,
dst_stride,
Expand Down Expand Up @@ -654,7 +654,7 @@ unsafe extern "C" fn backup_lpf(
}
} else {
while row + stripe_h <= row_h {
let n_lines_0 = 4 as libc::c_int - (row + stripe_h + 1 == h) as libc::c_int;
let n_lines_0 = 4 - (row + stripe_h + 1 == h) as libc::c_int;
let mut i = 0;
while i < 4 {
memcpy(
Expand Down
4 changes: 2 additions & 2 deletions src/lf_apply_tmpl_8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ unsafe extern "C" fn backup_lpf(
}
if lr_backup != 0 && (*(*f).frame_hdr).width[0] != (*(*f).frame_hdr).width[1] {
while row + stripe_h <= row_h {
let n_lines = 4 as libc::c_int - (row + stripe_h + 1 == h) as libc::c_int;
let n_lines = 4 - (row + stripe_h + 1 == h) as libc::c_int;
((*(*f).dsp).mc.resize).expect("non-null function pointer")(
dst,
dst_stride,
Expand All @@ -610,7 +610,7 @@ unsafe extern "C" fn backup_lpf(
}
} else {
while row + stripe_h <= row_h {
let n_lines_0 = 4 as libc::c_int - (row + stripe_h + 1 == h) as libc::c_int;
let n_lines_0 = 4 - (row + stripe_h + 1 == h) as libc::c_int;
let mut i = 0;
while i < 4 {
memcpy(
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ pub unsafe extern "C" fn dav1d_open(
&& ((*s).frame_size_limit).wrapping_sub(1 as libc::c_int as libc::c_uint)
>= (8192 * 8192) as libc::c_uint
{
(*c).frame_size_limit = (8192 as libc::c_int * 8192) as libc::c_uint;
(*c).frame_size_limit = (8192 * 8192) as libc::c_uint;
if (*s).frame_size_limit != 0 {
dav1d_log(
c,
Expand Down Expand Up @@ -1461,7 +1461,7 @@ unsafe extern "C" fn output_picture_ready(c: *mut Dav1dContext, drain: libc::c_i
}
unsafe extern "C" fn drain_picture(c: *mut Dav1dContext, out: *mut Dav1dPicture) -> libc::c_int {
let mut drain_count: libc::c_uint = 0 as libc::c_int as libc::c_uint;
let mut drained: libc::c_int = 0 as libc::c_int;
let mut drained = 0;
loop {
let next: libc::c_uint = (*c).frame_thread.next;
let f: *mut Dav1dFrameContext =
Expand All @@ -1475,7 +1475,7 @@ unsafe extern "C" fn drain_picture(c: *mut Dav1dContext, out: *mut Dav1dPicture)
}
let out_delayed: *mut Dav1dThreadPicture =
&mut *((*c).frame_thread.out_delayed).offset(next as isize) as *mut Dav1dThreadPicture;
if !((*out_delayed).p.data[0 as libc::c_int as usize]).is_null()
if !((*out_delayed).p.data[0]).is_null()
|| ::core::intrinsics::atomic_load_seqcst(
&mut (*f).task_thread.error as *mut atomic_int,
) != 0
Expand Down
2 changes: 1 addition & 1 deletion src/loopfilter_tmpl_16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ unsafe extern "C" fn loop_filter(
wd: libc::c_int,
bitdepth_max: libc::c_int,
) {
let bitdepth_min_8 = 32 as libc::c_int - clz(bitdepth_max as libc::c_uint) - 8;
let bitdepth_min_8 = 32 - clz(bitdepth_max as libc::c_uint) - 8;
let F = (1 as libc::c_int) << bitdepth_min_8;
E <<= bitdepth_min_8;
I <<= bitdepth_min_8;
Expand Down
8 changes: 4 additions & 4 deletions src/mc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ pub unsafe fn warp_affine_8x8_rust<BD: BitDepth>(
let mut tmx = mx;
while x < 8 {
let filter: *const i8 =
(dav1d_mc_warp_filter[(64 as libc::c_int + (tmx + 512 >> 10)) as usize]).as_ptr();
(dav1d_mc_warp_filter[(64 + (tmx + 512 >> 10)) as usize]).as_ptr();
*mid_ptr.offset(x as isize) = (*filter.offset(0) as libc::c_int
* (*src.offset((x - 3 * 1) as isize)).as_::<libc::c_int>()
+ *filter.offset(1) as libc::c_int
Expand Down Expand Up @@ -958,7 +958,7 @@ pub unsafe fn warp_affine_8x8_rust<BD: BitDepth>(
let mut tmy = my;
while x_0 < 8 {
let filter_0: *const i8 =
(dav1d_mc_warp_filter[(64 as libc::c_int + (tmy + 512 >> 10)) as usize]).as_ptr();
(dav1d_mc_warp_filter[(64 + (tmy + 512 >> 10)) as usize]).as_ptr();
*dst.offset(x_0 as isize) = bd.iclip_pixel(
*filter_0.offset(0) as libc::c_int
* *mid_ptr.offset((x_0 - 3 * 8) as isize) as libc::c_int
Expand Down Expand Up @@ -1010,7 +1010,7 @@ pub unsafe fn warp_affine_8x8t_rust<BD: BitDepth>(
let mut tmx = mx;
while x < 8 {
let filter: *const i8 =
(dav1d_mc_warp_filter[(64 as libc::c_int + (tmx + 512 >> 10)) as usize]).as_ptr();
(dav1d_mc_warp_filter[(64 + (tmx + 512 >> 10)) as usize]).as_ptr();
*mid_ptr.offset(x as isize) = (*filter.offset(0) as libc::c_int
* (*src.offset((x - 3 * 1) as isize)).as_::<libc::c_int>()
+ *filter.offset(1) as libc::c_int
Expand Down Expand Up @@ -1044,7 +1044,7 @@ pub unsafe fn warp_affine_8x8t_rust<BD: BitDepth>(
let mut tmy = my;
while x_0 < 8 {
let filter_0: *const i8 =
(dav1d_mc_warp_filter[(64 as libc::c_int + (tmy + 512 >> 10)) as usize]).as_ptr();
(dav1d_mc_warp_filter[(64 + (tmy + 512 >> 10)) as usize]).as_ptr();
*tmp.offset(x_0 as isize) = ((*filter_0.offset(0) as libc::c_int
* *mid_ptr.offset((x_0 - 3 * 8) as isize) as libc::c_int
+ *filter_0.offset(1) as libc::c_int
Expand Down
Loading

0 comments on commit 66f0ae1

Please sign in to comment.