Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fn cdef: Make safe #1239

Merged
merged 17 commits into from
Jul 10, 2024
Merged

fn cdef: Make safe #1239

merged 17 commits into from
Jul 10, 2024

Conversation

randomPoison
Copy link
Collaborator

@randomPoison randomPoison commented Jun 21, 2024

Makes the remaining Rust fallback in cdef.rs safe by passing in additional arguments.

@randomPoison randomPoison requested a review from kkysen June 21, 2024 21:18
@kkysen kkysen self-assigned this Jun 21, 2024
@kkysen kkysen changed the title cdef::Fn::call: Make safe fn cdef::Fn::call: Make safe Jun 21, 2024
src/cdef.rs Outdated Show resolved Hide resolved
src/cdef.rs Outdated Show resolved Hide resolved
src/cdef.rs Outdated Show resolved Hide resolved
src/cdef.rs Outdated Show resolved Hide resolved
src/cdef.rs Outdated Show resolved Hide resolved
src/cdef_apply.rs Outdated Show resolved Hide resolved
src/cdef_apply.rs Outdated Show resolved Hide resolved
src/cdef.rs Outdated Show resolved Hide resolved
src/cdef_apply.rs Outdated Show resolved Hide resolved
src/cdef_apply.rs Outdated Show resolved Hide resolved
@kkysen kkysen changed the title fn cdef::Fn::call: Make safe fn cdef: Make safe Jun 23, 2024
kkysen added a commit that referenced this pull request Jun 28, 2024
`rav1d_cdef_brow` is wrapped in TODO `unsafe` blocks
since #1239 fixes that already (not merged yet).
kkysen added a commit that referenced this pull request Jun 29, 2024
`rav1d_cdef_brow` is wrapped in TODO `unsafe` blocks
since #1239 fixes that already (not merged yet).
kkysen added a commit that referenced this pull request Jun 29, 2024
`rav1d_cdef_brow` is wrapped in TODO `unsafe` blocks
since #1239 fixes that already (not merged yet).
kkysen added a commit that referenced this pull request Jun 29, 2024
`rav1d_cdef_brow` is wrapped in TODO `unsafe` blocks
since #1239 fixes that already (not merged yet).
kkysen added a commit that referenced this pull request Jul 1, 2024
`rav1d_cdef_brow` is wrapped in TODO `unsafe` blocks
since #1239 fixes that already (not merged yet).
@kkysen kkysen closed this in #1268 Jul 1, 2024
@kkysen kkysen closed this in 093a17d Jul 1, 2024
@randomPoison randomPoison reopened this Jul 1, 2024
@kkysen
Copy link
Collaborator

kkysen commented Jul 1, 2024

Wait how did 093a17d close this PR?

@randomPoison
Copy link
Collaborator Author

Wait how did 093a17d close this PR?

"Resolve" is a keyword to trigger closing a PR.

kkysen added a commit that referenced this pull request Jul 1, 2024
* Fixes #848.
* Fixes #855.
* Fixes #841.

This does add back some bounds checks since the only and final slicing
is done in `fn loopfilter_sb::Fn::call`, which is inside inner loops.
@fbossen, how does this look for perf?

Only 2 `unsafe` ops left (after #1239 is merged, too)! Though still 122
`unsafe` ops in `neon` `fn`s.

## Addendum

So it turns out the `- b4strideb` in `fn loop_filter_sb128_rust` makes
the index negative, so the initial slice needs to be larger. This is
difficult to safely do, though, because all of the other uses of
`f.lf.level` do not go through `DisjointMut`'s safe APIs since there
were overlapping `&mut`s since indices 0 and 1 are written
simultaneously to 2 and 3, and thus were done `unsafe`ly. This loses the
disjointedness checking, though, which is a problem for making other
changes.

Thus, this PR leaves the `- b4strideb` as an `unsafe`
`lvl.as_ptr().sub(b4strideb)` for now. In a follow-up PR, I'm going to
change the `[u8; 4]` `lvl` elements to just `u8`s. This will allow the
disjoint writes to `[0..2]` and `[2..4]` to be done safely with
`DisjointMut`s APIs and will remove the need for `fn
unaligned_lvl_slice`.

Fixed in #1273 now.
kkysen added a commit that referenced this pull request Jul 1, 2024
Including #1239, this is the last of non-`neon` `unsafe` ops.
@kkysen
Copy link
Collaborator

kkysen commented Jul 1, 2024

Wait how did 093a17d close this PR?

"Resolve" is a keyword to trigger closing a PR.

Ugh, but I only linked a comment on a PR, not the PR itself. GitHub should be smarter.

kkysen added a commit that referenced this pull request Jul 7, 2024
Assuming #1239 is already merged, this removes the last of `unsafe` ops
when compiling for `target_arch = "arm"`. Now only `target_arch =
"aarch64"` remains with 110 `unsafe` ops in `mod looprestoration::neon`
(`x86`, `x86_64` are already done).
@randomPoison
Copy link
Collaborator Author

@kkysen I've reworked this to use PicOrBuf and WithOffset, please give this another look.

@randomPoison randomPoison requested a review from kkysen July 8, 2024 22:31
src/cdef.rs Outdated Show resolved Hide resolved
src/cdef.rs Outdated Show resolved Hide resolved
src/cdef.rs Outdated Show resolved Hide resolved
src/cdef.rs Outdated Show resolved Hide resolved
src/cdef.rs Outdated Show resolved Hide resolved
src/cdef_apply.rs Outdated Show resolved Hide resolved
src/cdef_apply.rs Outdated Show resolved Hide resolved
src/cdef_apply.rs Outdated Show resolved Hide resolved
src/cdef_apply.rs Outdated Show resolved Hide resolved
src/cdef_apply.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@kkysen kkysen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My previous comments were just little nitpicks, so I fixed them myself and I'll merge now. I also squashed one of the commits that was broken with its fix.

@kkysen kkysen merged commit ab4b6de into main Jul 10, 2024
27 checks passed
@kkysen kkysen deleted the legare/cdef branch July 10, 2024 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cdef_apply.rs: Unsafe cleanup cdef.rs: Unsafe cleanup
2 participants