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

Make various flags booleans #1266

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Make various flags booleans #1266

wants to merge 13 commits into from

Conversation

rinon
Copy link
Collaborator

@rinon rinon commented Jun 28, 2024

I did this while trying to improve performance. It doesn't seem like a large effect but it's also cleaner, so I figured I would upload the changes anyway.

@rinon rinon added the low priority Issues that we would like to address at some point in the future label Jun 28, 2024
@rinon rinon requested review from randomPoison and kkysen June 28, 2024 02:28
@kkysen kkysen self-assigned this Jun 28, 2024
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.

LGTM except for a few little things. I also wanted to ask why #[repr(C)] is removed for some structs that now have bools but not others. Is that based on perf measurements?

I was also wondering if it may help perf to combine a bunch of these bool flag fields into one bitflags! field if many of them are all accessed in hot fns, as that should presumably reduce the amount of loads and possibility of those loads not being cached.

@rinon rinon force-pushed the sjc/bool_flags branch 2 times, most recently from 158fae6 to 0923af0 Compare July 2, 2024 20:21
@rinon rinon force-pushed the sjc/bool_flags branch from 0923af0 to 5b3979e Compare July 2, 2024 20:23
@rinon rinon force-pushed the sjc/bool_flags branch from 5b3979e to 6370332 Compare July 2, 2024 20:26
@rinon rinon force-pushed the sjc/bool_flags branch from 6370332 to 19c475d Compare July 2, 2024 22:33
Comment on lines +3704 to +3705
let prev_mask = (sby - 1 >> !seq_hdr.sb128 as c_int) * f.sb128w;
let mask_offset = (sby >> !seq_hdr.sb128 as c_int) * f.sb128w;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
let prev_mask = (sby - 1 >> !seq_hdr.sb128 as c_int) * f.sb128w;
let mask_offset = (sby >> !seq_hdr.sb128 as c_int) * f.sb128w;
let prev_mask = (sby - 1 >> !seq_hdr.sb128 as u8) * f.sb128w;
let mask_offset = (sby >> !seq_hdr.sb128 as u8) * f.sb128w;

Comment on lines +416 to 417
ss_ver = false;
ss_hor = ss_ver;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
ss_ver = false;
ss_hor = ss_ver;
ss_ver = true;
ss_hor = true;

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you run the argon tests?

match profile {
Rav1dProfile::Main => {
layout = Rav1dPixelLayout::I420;
ss_ver = 1;
ss_ver = true;
ss_hor = ss_ver;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
ss_hor = ss_ver;
ss_hor = true;

ss_ver = gb.get_bit() as u8;
ss_hor = gb.get_bit();
if ss_hor {
ss_ver = gb.get_bit();
} else {
// Default initialization.
ss_ver = Default::default();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
ss_ver = Default::default();
ss_ver = false;

Comment on lines +1703 to 1705
let present =
(seqhdr.film_grain_present && (show_frame || showable_frame) && gb.get_bit()) as u8;
let update;
Copy link
Collaborator

Choose a reason for hiding this comment

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

present and update can both be bools, too.

for _ in 0..8 {
gb.get_bits(seqhdr.order_hint_n_bits.into());
}
}
frame_ref_short_signaling = (seqhdr.order_hint != 0 && gb.get_bit()) as u8;
frame_ref_short_signaling = (seqhdr.order_hint && gb.get_bit()) as u8;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can be a bool.

@@ -1522,17 +1520,17 @@ fn decode_b(
}

// delta-q/lf
let not_sb128 = (seq_hdr.sb128 == 0) as c_int;
let not_sb128 = !seq_hdr.sb128 as c_int;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
let not_sb128 = !seq_hdr.sb128 as c_int;
let not_sb128 = !seq_hdr.sb128 as u8;

@@ -1982,7 +1983,7 @@ fn decode_b(
case.set_disjoint(&dir.seg_pred, seg_pred.into());
case.set_disjoint(&dir.skip_mode, 0);
case.set_disjoint(&dir.intra, 1);
case.set_disjoint(&dir.skip, b.skip);
case.set_disjoint(&dir.skip, b.skip as u8);
Copy link
Collaborator

Choose a reason for hiding this comment

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

dir.skip can be made bools.

@@ -3137,9 +3134,9 @@ fn decode_b(
[by4 as usize, bx4 as usize],
|case, (dir, dir_index)| {
case.set_disjoint(&dir.seg_pred, seg_pred.into());
case.set_disjoint(&dir.skip_mode, b.skip_mode);
case.set_disjoint(&dir.skip_mode, b.skip_mode as u8);
Copy link
Collaborator

Choose a reason for hiding this comment

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

dir.skip_mode can be made bools.

@@ -3137,9 +3134,9 @@ fn decode_b(
[by4 as usize, bx4 as usize],
|case, (dir, dir_index)| {
case.set_disjoint(&dir.seg_pred, seg_pred.into());
case.set_disjoint(&dir.skip_mode, b.skip_mode);
case.set_disjoint(&dir.skip_mode, b.skip_mode as u8);
case.set_disjoint(&dir.intra, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

dir.intra can be made bools, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
low priority Issues that we would like to address at some point in the future performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants