Skip to content

Commit

Permalink
fn get_upsample: Cleanup and make safe (#1133)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkysen authored May 28, 2024
2 parents 244d15b + 4328515 commit 456defa
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions src/ipred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,8 @@ unsafe fn filter_edge<BD: BitDepth>(
}

#[inline]
unsafe fn get_upsample(wh: c_int, angle: c_int, is_sm: c_int) -> c_int {
return (angle < 40 && wh <= 16 >> is_sm) as c_int;
fn get_upsample(wh: c_int, angle: c_int, is_sm: c_int) -> bool {
angle < 40 && wh <= (16 >> is_sm)
}

#[inline(never)]
Expand Down Expand Up @@ -856,9 +856,9 @@ unsafe fn ipred_z1_rust<BD: BitDepth>(
let upsample_above = if enable_intra_edge_filter != 0 {
get_upsample(width + height, 90 - angle, is_sm)
} else {
0 as c_int
false
};
if upsample_above != 0 {
if upsample_above {
upsample_edge::<BD>(
top_out.as_mut_ptr(),
width + height,
Expand Down Expand Up @@ -894,7 +894,7 @@ unsafe fn ipred_z1_rust<BD: BitDepth>(
max_base_x = width + cmp::min(width, height) - 1;
}
}
let base_inc = 1 + upsample_above;
let base_inc = 1 + upsample_above as c_int;
let mut y = 0;
let mut xpos = dx;
while y < height {
Expand Down Expand Up @@ -947,16 +947,16 @@ unsafe fn ipred_z2_rust<BD: BitDepth>(
let upsample_left = if enable_intra_edge_filter != 0 {
get_upsample(width + height, 180 - angle, is_sm)
} else {
0 as c_int
false
};
let upsample_above = if enable_intra_edge_filter != 0 {
get_upsample(width + height, angle - 90, is_sm)
} else {
0 as c_int
false
};
let mut edge: [BD::Pixel; 129] = [0.into(); 129];
let topleft: *mut BD::Pixel = &mut *edge.as_mut_ptr().offset(64) as *mut BD::Pixel;
if upsample_above != 0 {
if upsample_above {
upsample_edge::<BD>(topleft, width + 1, topleft_in, 0 as c_int, width + 1, bd);
dx <<= 1;
} else {
Expand Down Expand Up @@ -985,7 +985,7 @@ unsafe fn ipred_z2_rust<BD: BitDepth>(
);
}
}
if upsample_left != 0 {
if upsample_left {
upsample_edge::<BD>(
&mut *topleft.offset((-height * 2) as isize),
height + 1,
Expand Down Expand Up @@ -1027,24 +1027,24 @@ unsafe fn ipred_z2_rust<BD: BitDepth>(
}
}
*topleft = *topleft_in;
let base_inc_x = 1 + upsample_above;
let base_inc_x = 1 + upsample_above as c_int;
let left: *const BD::Pixel =
&mut *topleft.offset(-(1 + upsample_left) as isize) as *mut BD::Pixel;
&mut *topleft.offset(-(1 + upsample_left as isize)) as *mut BD::Pixel;
let mut y = 0;
let mut xpos = (1 + upsample_above << 6) - dx;
let mut xpos = (1 + (upsample_above as c_int) << 6) - dx;
while y < height {
let mut base_x = xpos >> 6;
let frac_x = xpos & 0x3e as c_int;
let mut x = 0;
let mut ypos = (y << 6 + upsample_left) - dy;
let mut ypos = (y << 6 + upsample_left as c_int) - dy;
while x < width {
let v;
if base_x >= 0 {
v = (*topleft.offset(base_x as isize)).as_::<c_int>() * (64 - frac_x)
+ (*topleft.offset((base_x + 1) as isize)).as_::<c_int>() * frac_x;
} else {
let base_y = ypos >> 6;
if !(base_y >= -(1 + upsample_left)) {
if !(base_y >= -(1 + upsample_left as c_int)) {
unreachable!();
}
let frac_y = ypos & 0x3e as c_int;
Expand Down Expand Up @@ -1086,9 +1086,9 @@ unsafe fn ipred_z3_rust<BD: BitDepth>(
let upsample_left = if enable_intra_edge_filter != 0 {
get_upsample(width + height, angle - 180, is_sm)
} else {
0 as c_int
false
};
if upsample_left != 0 {
if upsample_left {
upsample_edge::<BD>(
left_out.as_mut_ptr(),
width + height,
Expand Down Expand Up @@ -1127,7 +1127,7 @@ unsafe fn ipred_z3_rust<BD: BitDepth>(
max_base_y = height + cmp::min(width, height) - 1;
}
}
let base_inc = 1 + upsample_left;
let base_inc = 1 + upsample_left as c_int;
let mut x = 0;
let mut ypos = dy;
while x < width {
Expand Down Expand Up @@ -1661,9 +1661,9 @@ mod neon {
let upsample_above = if enable_intra_edge_filter != 0 {
get_upsample(width + height, 90 - angle, is_sm)
} else {
0 as c_int
false
};
if upsample_above != 0 {
if upsample_above {
bd_fn!(z1_upsample_edge::decl_fn, BD, ipred_z1_upsample_edge, neon).call(
top_out.as_mut_ptr(),
width + height,
Expand Down Expand Up @@ -1697,14 +1697,14 @@ mod neon {
);
}
}
let base_inc = 1 + upsample_above;
let base_inc = 1 + upsample_above as c_int;
let pad_pixels = width + 15;
rav1d_ipred_pixel_set_neon::<BD>(
top_out.as_mut_ptr().offset((max_base_x + 1) as isize),
top_out[max_base_x as usize],
(pad_pixels * base_inc) as c_int,
);
if upsample_above != 0 {
if upsample_above {
bd_fn!(z13_fill::decl_fn, BD, ipred_z1_fill2, neon).call::<BD>(
dst,
stride,
Expand Down Expand Up @@ -1757,15 +1757,15 @@ mod neon {
let upsample_left = if enable_intra_edge_filter != 0 {
get_upsample(width + height, 180 - angle, is_sm)
} else {
0 as c_int
false
};
let upsample_above = if enable_intra_edge_filter != 0 {
get_upsample(width + height, angle - 90, is_sm)
} else {
0 as c_int
false
};

if upsample_above != 0 {
if upsample_above {
bd_fn!(z2_upsample_edge::decl_fn, BD, ipred_z2_upsample_edge, neon).call(
buf.as_mut_ptr().offset(top_offset),
width,
Expand Down Expand Up @@ -1806,7 +1806,7 @@ mod neon {
}
}

if upsample_left != 0 {
if upsample_left {
buf[flipped_offset as usize] = *topleft_in;
bd_fn!(reverse::decl_fn, BD, ipred_reverse, neon).call::<BD>(
buf.as_mut_ptr().offset(1 + flipped_offset),
Expand Down Expand Up @@ -1863,11 +1863,11 @@ mod neon {
buf[top_offset as usize] = *topleft_in;
buf[left_offset as usize] = *topleft_in;

if upsample_above != 0 && upsample_left != 0 {
if upsample_above && upsample_left {
unreachable!();
}

if upsample_above == 0 && upsample_left == 0 {
if !upsample_above && !upsample_left {
bd_fn!(z2_fill::decl_fn, BD, ipred_z2_fill1, neon).call::<BD>(
dst,
stride,
Expand All @@ -1878,7 +1878,7 @@ mod neon {
dx,
dy,
);
} else if upsample_above != 0 {
} else if upsample_above {
bd_fn!(z2_fill::decl_fn, BD, ipred_z2_fill2, neon).call::<BD>(
dst,
stride,
Expand Down Expand Up @@ -1927,9 +1927,9 @@ mod neon {
let upsample_left = if enable_intra_edge_filter != 0 {
get_upsample(width + height, angle - 180, is_sm)
} else {
0 as c_int
false
};
if upsample_left != 0 {
if upsample_left {
flipped[0] = *topleft_in.offset(0);
bd_fn!(reverse::decl_fn, BD, ipred_reverse, neon).call::<BD>(
flipped.as_mut_ptr().offset(1),
Expand Down Expand Up @@ -1975,14 +1975,14 @@ mod neon {
max_base_y = height + cmp::min(width, height) - 1;
}
}
let base_inc = 1 + upsample_left;
let base_inc = 1 + upsample_left as c_int;
let pad_pixels = cmp::max(64 - max_base_y - 1, height + 15);
rav1d_ipred_pixel_set_neon::<BD>(
left_out.as_mut_ptr().offset((max_base_y + 1) as isize),
left_out[max_base_y as usize],
(pad_pixels * base_inc) as c_int,
);
if upsample_left != 0 {
if upsample_left {
bd_fn!(z13_fill::decl_fn, BD, ipred_z3_fill2, neon).call::<BD>(
dst,
stride,
Expand Down Expand Up @@ -2062,7 +2062,7 @@ impl Rav1dIntraPredDSPContext {
}),
cfl_pred: {
// Not all elements are initialized with fns,
// so we default initialize first so that there is no unitialized memory.
// so we default initialize first so that there is no uninitialized memory.
// The defaults just call `unimplemented!()`,
// which shouldn't slow down the other code paths at all.
let mut a = [DefaultValue::DEFAULT; 6];
Expand Down

0 comments on commit 456defa

Please sign in to comment.