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

struct Rav1dIntraPredDspContext: Fix defaults #583

Merged
merged 2 commits into from
Dec 6, 2023

Conversation

kkysen
Copy link
Collaborator

@kkysen kkysen commented Nov 21, 2023

This replaces the Options on .intra_pred with an initialized: bool field as they are always Some even if .is_none() is checked.

.is_none() appears to be checked so that it can lazily initialize DSPs, relying on things being zero-initialized to begin with.
Ideally we should move initialization to DSP allocation so its not lazy, but for now (and the way closest to the C), we can use a single initialized flag instead of Options on everything.

This also default initializes .cfl_pred as it otherwise isn't fully initialized and is thus leaving uninitialized memory, which is UB if it is made a reference at any point (which it is). This uses DefaultValue::DEFAULT for initialization instead of None, though, which moves the check from before the call (.unwrap()/.expect()) to inside a call that should never happen (unimplemented!()). Normally those unimplemented!()s will be dead code eliminated, but here they won't. Thus, it shouldn't add any perf cost and only a small binary size cost.

@kkysen kkysen requested a review from randomPoison November 21, 2023 23:00
@kkysen kkysen force-pushed the kkysen/mod-ipred-neon branch from fa222c0 to f3feffc Compare November 27, 2023 06:27
@kkysen kkysen force-pushed the kkysen/struct-Rav1dIntraPredDSPContext-defaults branch from 662f110 to 1d210ad Compare November 27, 2023 06:27
src/decode.rs Show resolved Hide resolved
Copy link
Collaborator

@rinon rinon left a comment

Choose a reason for hiding this comment

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

I think we should do something to not reinit on every frame so we don't deviate from the original code. (github won't let me change my review without a comment, that's all this is)

@kkysen kkysen force-pushed the kkysen/mod-ipred-neon branch from f3feffc to 3aa1661 Compare November 29, 2023 07:17
@kkysen kkysen force-pushed the kkysen/struct-Rav1dIntraPredDSPContext-defaults branch 2 times, most recently from ca53d47 to f2c5e8f Compare November 29, 2023 07:41
@kkysen kkysen requested a review from rinon November 29, 2023 07:42
@kkysen kkysen force-pushed the kkysen/mod-ipred-neon branch from 3aa1661 to 348b7db Compare November 30, 2023 07:04
@kkysen kkysen force-pushed the kkysen/struct-Rav1dIntraPredDSPContext-defaults branch from f2c5e8f to 7d0c2ce Compare November 30, 2023 07:05
src/decode.rs Outdated Show resolved Hide resolved
src/ipred.rs Outdated Show resolved Hide resolved
Base automatically changed from kkysen/mod-ipred-neon to main December 2, 2023 00:00
… a `initialized: bool` field (on `struct Rav1dDSPContext`) as they are always `Some` even if `.is_none()` is checked.

`.is_none()` appears to be checked so that it can lazily initialize DSPs,
relying on things being zero-initialized to begin with.
Ideally we should move initialization to DSP allocation so its not lazy,
but for now (and the way closest to the C),
we can use a single initialized flag instead of `Option`s on everything.
…:cfl_pred` to defaults to avoid unitialized memory, as not all (4/6) elements are initialized.
@kkysen kkysen force-pushed the kkysen/struct-Rav1dIntraPredDSPContext-defaults branch from 7d0c2ce to 4609590 Compare December 2, 2023 05:04
@kkysen kkysen requested a review from rinon December 2, 2023 05:07
Copy link
Collaborator

@randomPoison randomPoison left a comment

Choose a reason for hiding this comment

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

The changes here look fine to me, but make sure you've addressed @rinon's requests before merging.

@kkysen
Copy link
Collaborator Author

kkysen commented Dec 6, 2023

The changes here look fine to me, but make sure you've addressed @rinon's requests before merging.

I addressed the last of @rinon's comments and was just waiting on approval, but it was a pretty minimal fix, so I'll go ahead and merge now.

@kkysen kkysen merged commit 036e55a into main Dec 6, 2023
18 checks passed
@kkysen kkysen deleted the kkysen/struct-Rav1dIntraPredDSPContext-defaults branch December 6, 2023 04:46
@rinon
Copy link
Collaborator

rinon commented Dec 6, 2023

I just hadn't gotten a chance to look at it, LGTM thanks 👍

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.

3 participants