Skip to content

Commit

Permalink
extern "C" fns: Remove extern "C" from all fns if possible (i.e…
Browse files Browse the repository at this point in the history
…., not a `#[no_mangle]`/`DAV1D-API`, a `fn` ptr, vararg).
  • Loading branch information
kkysen committed Oct 3, 2023
1 parent 819a1d8 commit 72d9473
Show file tree
Hide file tree
Showing 45 changed files with 207 additions and 268 deletions.
4 changes: 2 additions & 2 deletions src/cdef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ extern "C" {
}

#[inline]
pub unsafe extern "C" fn constrain(diff: c_int, threshold: c_int, shift: c_int) -> c_int {
pub unsafe fn constrain(diff: c_int, threshold: c_int, shift: c_int) -> c_int {
let adiff = diff.abs();
return apply_sign(
cmp::min(adiff, cmp::max(0 as c_int, threshold - (adiff >> shift))),
Expand All @@ -537,7 +537,7 @@ pub unsafe extern "C" fn constrain(diff: c_int, threshold: c_int, shift: c_int)
}

#[inline]
pub unsafe extern "C" fn fill(mut tmp: *mut i16, stride: ptrdiff_t, w: c_int, h: c_int) {
pub unsafe fn fill(mut tmp: *mut i16, stride: ptrdiff_t, w: c_int, h: c_int) {
let mut y = 0;
while y < h {
let mut x = 0;
Expand Down
8 changes: 4 additions & 4 deletions src/cdef_apply_tmpl_16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ pub const BACKUP_2X8_UV: Backup2x8Flags = 2;
pub const BACKUP_2X8_Y: Backup2x8Flags = 1;

#[inline]
unsafe extern "C" fn PXSTRIDE(x: ptrdiff_t) -> ptrdiff_t {
unsafe fn PXSTRIDE(x: ptrdiff_t) -> ptrdiff_t {
if x & 1 != 0 {
unreachable!();
}
return x >> 1;
}

unsafe extern "C" fn backup2lines(
unsafe fn backup2lines(
dst: *const *mut pixel,
src: *const *mut pixel,
stride: *const ptrdiff_t,
Expand Down Expand Up @@ -93,7 +93,7 @@ unsafe extern "C" fn backup2lines(
}
}

unsafe extern "C" fn backup2x8(
unsafe fn backup2x8(
dst: *mut [[pixel; 2]; 8],
src: *const *mut pixel,
src_stride: *const ptrdiff_t,
Expand Down Expand Up @@ -143,7 +143,7 @@ unsafe extern "C" fn backup2x8(
}
}

unsafe extern "C" fn adjust_strength(strength: c_int, var: c_uint) -> c_int {
unsafe fn adjust_strength(strength: c_int, var: c_uint) -> c_int {
if var == 0 {
return 0 as c_int;
}
Expand Down
6 changes: 3 additions & 3 deletions src/cdef_apply_tmpl_8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub type Backup2x8Flags = c_uint;
pub const BACKUP_2X8_UV: Backup2x8Flags = 2;
pub const BACKUP_2X8_Y: Backup2x8Flags = 1;

unsafe extern "C" fn backup2lines(
unsafe fn backup2lines(
dst: *const *mut pixel,
src: *const *mut pixel,
stride: *const ptrdiff_t,
Expand Down Expand Up @@ -85,7 +85,7 @@ unsafe extern "C" fn backup2lines(
}
}

unsafe extern "C" fn backup2x8(
unsafe fn backup2x8(
dst: *mut [[pixel; 2]; 8],
src: *const *mut pixel,
src_stride: *const ptrdiff_t,
Expand Down Expand Up @@ -135,7 +135,7 @@ unsafe extern "C" fn backup2x8(
}
}

unsafe extern "C" fn adjust_strength(strength: c_int, var: c_uint) -> c_int {
unsafe fn adjust_strength(strength: c_int, var: c_uint) -> c_int {
if var == 0 {
return 0 as c_int;
}
Expand Down
10 changes: 5 additions & 5 deletions src/cdef_tmpl_16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ use crate::src::cpu::{rav1d_get_cpu_flags, CpuFlags};
pub type pixel = u16;

#[inline]
unsafe extern "C" fn PXSTRIDE(x: ptrdiff_t) -> ptrdiff_t {
unsafe fn PXSTRIDE(x: ptrdiff_t) -> ptrdiff_t {
if x & 1 != 0 {
unreachable!();
}
return x >> 1;
}

unsafe extern "C" fn padding(
unsafe fn padding(
mut tmp: *mut i16,
tmp_stride: ptrdiff_t,
mut src: *const pixel,
Expand Down Expand Up @@ -134,7 +134,7 @@ unsafe extern "C" fn padding(
}

#[inline(never)]
unsafe extern "C" fn cdef_filter_block_c(
unsafe fn cdef_filter_block_c(
mut dst: *mut pixel,
dst_stride: ptrdiff_t,
left: *const [pixel; 2],
Expand Down Expand Up @@ -500,7 +500,7 @@ unsafe fn cdef_find_dir_rust(

#[inline(always)]
#[cfg(all(feature = "asm", any(target_arch = "x86", target_arch = "x86_64"),))]
unsafe extern "C" fn cdef_dsp_init_x86(c: *mut Rav1dCdefDSPContext) {
unsafe fn cdef_dsp_init_x86(c: *mut Rav1dCdefDSPContext) {
// TODO(legare): Temporary import until init fns are deduplicated.
use crate::src::cdef::*;

Expand Down Expand Up @@ -544,7 +544,7 @@ unsafe extern "C" fn cdef_dsp_init_x86(c: *mut Rav1dCdefDSPContext) {

#[inline(always)]
#[cfg(all(feature = "asm", any(target_arch = "arm", target_arch = "aarch64"),))]
unsafe extern "C" fn cdef_dsp_init_arm(c: *mut Rav1dCdefDSPContext) {
unsafe fn cdef_dsp_init_arm(c: *mut Rav1dCdefDSPContext) {
// TODO(legare): Temporary import until init fns are deduplicated.
use crate::src::cdef::*;

Expand Down
8 changes: 4 additions & 4 deletions src/cdef_tmpl_8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use cfg_if::cfg_if;

pub type pixel = u8;

unsafe extern "C" fn padding(
unsafe fn padding(
mut tmp: *mut i16,
tmp_stride: ptrdiff_t,
mut src: *const pixel,
Expand Down Expand Up @@ -126,7 +126,7 @@ unsafe extern "C" fn padding(
}

#[inline(never)]
unsafe extern "C" fn cdef_filter_block_c(
unsafe fn cdef_filter_block_c(
mut dst: *mut pixel,
dst_stride: ptrdiff_t,
left: *const [pixel; 2],
Expand Down Expand Up @@ -486,7 +486,7 @@ use crate::src::cpu::{rav1d_get_cpu_flags, CpuFlags};

#[inline(always)]
#[cfg(all(feature = "asm", any(target_arch = "x86", target_arch = "x86_64"),))]
unsafe extern "C" fn cdef_dsp_init_x86(c: *mut Rav1dCdefDSPContext) {
unsafe fn cdef_dsp_init_x86(c: *mut Rav1dCdefDSPContext) {
// TODO(legare): Temporary import until init fns are deduplicated.
use crate::src::cdef::*;

Expand Down Expand Up @@ -541,7 +541,7 @@ unsafe extern "C" fn cdef_dsp_init_x86(c: *mut Rav1dCdefDSPContext) {

#[inline(always)]
#[cfg(all(feature = "asm", any(target_arch = "arm", target_arch = "aarch64"),))]
unsafe extern "C" fn cdef_dsp_init_arm(c: *mut Rav1dCdefDSPContext) {
unsafe fn cdef_dsp_init_arm(c: *mut Rav1dCdefDSPContext) {
// TODO(legare): Temporary import until init fns are deduplicated.
use crate::src::cdef::*;

Expand Down
2 changes: 1 addition & 1 deletion src/cdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5598,7 +5598,7 @@ pub(crate) unsafe fn rav1d_cdf_thread_update(
}

#[inline]
unsafe extern "C" fn get_qcat_idx(q: c_int) -> c_int {
unsafe fn get_qcat_idx(q: c_int) -> c_int {
if q <= 20 {
return 0 as c_int;
}
Expand Down
9 changes: 2 additions & 7 deletions src/fg_apply_tmpl_16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,14 @@ pub type pixel = u16;
pub type entry = i16;

#[inline]
unsafe extern "C" fn PXSTRIDE(x: ptrdiff_t) -> ptrdiff_t {
unsafe fn PXSTRIDE(x: ptrdiff_t) -> ptrdiff_t {
if x & 1 != 0 {
unreachable!();
}
return x >> 1;
}

unsafe extern "C" fn generate_scaling(
bitdepth: c_int,
points: *const [u8; 2],
num: c_int,
scaling: *mut u8,
) {
unsafe fn generate_scaling(bitdepth: c_int, points: *const [u8; 2], num: c_int, scaling: *mut u8) {
if !(bitdepth > 8) {
unreachable!();
}
Expand Down
7 changes: 1 addition & 6 deletions src/fg_apply_tmpl_8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ use std::ffi::c_void;
pub type pixel = u8;
pub type entry = i8;

unsafe extern "C" fn generate_scaling(
_bitdepth: c_int,
points: *const [u8; 2],
num: c_int,
scaling: *mut u8,
) {
unsafe fn generate_scaling(_bitdepth: c_int, points: *const [u8; 2], num: c_int, scaling: *mut u8) {
let shift_x = 0;
let scaling_size = 256;
if num == 0 {
Expand Down
4 changes: 2 additions & 2 deletions src/filmgrain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use std::ffi::c_int;
use std::ffi::c_uint;

#[inline]
pub unsafe extern "C" fn get_random_number(bits: c_int, state: *mut c_uint) -> c_int {
pub unsafe fn get_random_number(bits: c_int, state: *mut c_uint) -> c_int {
let r = *state as c_int;
let bit: c_uint = ((r >> 0 ^ r >> 1 ^ r >> 3 ^ r >> 12) & 1) as c_uint;
*state = (r >> 1) as c_uint | bit << 15;
return (*state >> 16 - bits & (((1 as c_int) << bits) - 1) as c_uint) as c_int;
}

#[inline]
pub unsafe extern "C" fn round2(x: c_int, shift: u64) -> c_int {
pub unsafe fn round2(x: c_int, shift: u64) -> c_int {
return x + ((1 as c_int) << shift >> 1) >> shift;
}

Expand Down
24 changes: 12 additions & 12 deletions src/filmgrain_tmpl_16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ pub type pixel = u16;
pub type entry = i16;

#[inline]
unsafe extern "C" fn PXSTRIDE(x: ptrdiff_t) -> ptrdiff_t {
unsafe fn PXSTRIDE(x: ptrdiff_t) -> ptrdiff_t {
if x & 1 != 0 {
unreachable!();
}
Expand All @@ -374,7 +374,7 @@ unsafe extern "C" fn generate_grain_y_c_erased(
generate_grain_y_rust(buf.cast(), data, bitdepth_max)
}

unsafe extern "C" fn generate_grain_y_rust(
unsafe fn generate_grain_y_rust(
buf: *mut [entry; 82],
data: *const Dav1dFilmGrainData,
bitdepth_max: c_int,
Expand Down Expand Up @@ -431,7 +431,7 @@ unsafe extern "C" fn generate_grain_y_rust(
}

#[inline(never)]
unsafe extern "C" fn generate_grain_uv_c(
unsafe fn generate_grain_uv_c(
buf: *mut [entry; 82],
buf_y: *const [entry; 82],
data: *const Dav1dFilmGrainData,
Expand Down Expand Up @@ -572,7 +572,7 @@ unsafe extern "C" fn generate_grain_uv_444_c_erased(
}

#[inline]
unsafe extern "C" fn sample_lut(
unsafe fn sample_lut(
grain_lut: *const [entry; 82],
offsets: *const [c_int; 2],
subx: c_int,
Expand Down Expand Up @@ -615,7 +615,7 @@ unsafe extern "C" fn fgy_32x32xn_c_erased(
);
}

unsafe extern "C" fn fgy_32x32xn_rust(
unsafe fn fgy_32x32xn_rust(
dst_row: *mut pixel,
src_row: *const pixel,
stride: ptrdiff_t,
Expand Down Expand Up @@ -882,7 +882,7 @@ unsafe extern "C" fn fgy_32x32xn_rust(
}

#[inline(never)]
unsafe extern "C" fn fguv_32x32xn_c(
unsafe fn fguv_32x32xn_c(
dst_row: *mut pixel,
src_row: *const pixel,
stride: ptrdiff_t,
Expand Down Expand Up @@ -1341,7 +1341,7 @@ unsafe extern "C" fn fguv_32x32xn_444_c_erased(

#[cfg(all(feature = "asm", any(target_arch = "x86", target_arch = "x86_64"),))]
#[inline(always)]
unsafe extern "C" fn film_grain_dsp_init_x86(c: *mut Rav1dFilmGrainDSPContext) {
unsafe fn film_grain_dsp_init_x86(c: *mut Rav1dFilmGrainDSPContext) {
let flags = rav1d_get_cpu_flags();

if !flags.contains(CpuFlags::SSSE3) {
Expand Down Expand Up @@ -1404,7 +1404,7 @@ unsafe extern "C" fn film_grain_dsp_init_x86(c: *mut Rav1dFilmGrainDSPContext) {

#[cfg(all(feature = "asm", any(target_arch = "arm", target_arch = "aarch64"),))]
#[inline(always)]
unsafe extern "C" fn film_grain_dsp_init_arm(c: *mut Rav1dFilmGrainDSPContext) {
unsafe fn film_grain_dsp_init_arm(c: *mut Rav1dFilmGrainDSPContext) {
let flags = rav1d_get_cpu_flags();

if !flags.contains(CpuFlags::NEON) {
Expand Down Expand Up @@ -1453,7 +1453,7 @@ unsafe extern "C" fn fgy_32x32xn_neon_erased(
}

#[cfg(all(feature = "asm", any(target_arch = "arm", target_arch = "aarch64"),))]
unsafe extern "C" fn fgy_32x32xn_neon(
unsafe fn fgy_32x32xn_neon(
dst_row: *mut pixel,
src_row: *const pixel,
stride: ptrdiff_t,
Expand Down Expand Up @@ -1550,7 +1550,7 @@ unsafe extern "C" fn fguv_32x32xn_420_neon_erased(
}

#[cfg(all(feature = "asm", any(target_arch = "arm", target_arch = "aarch64"),))]
unsafe extern "C" fn fguv_32x32xn_420_neon(
unsafe fn fguv_32x32xn_420_neon(
dst_row: *mut pixel,
src_row: *const pixel,
stride: ptrdiff_t,
Expand Down Expand Up @@ -1657,7 +1657,7 @@ unsafe extern "C" fn fguv_32x32xn_422_neon_erased(
}

#[cfg(all(feature = "asm", any(target_arch = "arm", target_arch = "aarch64"),))]
unsafe extern "C" fn fguv_32x32xn_422_neon(
unsafe fn fguv_32x32xn_422_neon(
dst_row: *mut pixel,
src_row: *const pixel,
stride: ptrdiff_t,
Expand Down Expand Up @@ -1764,7 +1764,7 @@ unsafe extern "C" fn fguv_32x32xn_444_neon_erased(
}

#[cfg(all(feature = "asm", any(target_arch = "arm", target_arch = "aarch64"),))]
unsafe extern "C" fn fguv_32x32xn_444_neon(
unsafe fn fguv_32x32xn_444_neon(
dst_row: *mut pixel,
src_row: *const pixel,
stride: ptrdiff_t,
Expand Down
Loading

0 comments on commit 72d9473

Please sign in to comment.