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

optimize branch logic #58

Merged
merged 2 commits into from
Feb 21, 2024
Merged

optimize branch logic #58

merged 2 commits into from
Feb 21, 2024

Conversation

mcroomp
Copy link
Collaborator

@mcroomp mcroomp commented Feb 18, 2024

based on feedback from #49 from @Melirius

Analysing the code I got to conclusion that corner case even if present in the initial code of Lepton, does not affect its behaviour. Citing https://github.com/microsoft/lepton_jpeg_rust/blob/main/src/structs/branch.rs

The only corner case is that in the case of 255 true and 1
false, the C++ version decides to set the probability to 0 for the next
true value, which is different than the formula ((a << 8) / ( a + b )).
The formula produces 1 here, and this does not affect neither https://github.com/microsoft/lepton_jpeg_rust/blob/main/src/structs/vpx_bool_reader.rs#L147 nor https://github.com/microsoft/lepton_jpeg_rust/blob/main/src/structs/vpx_bool_writer.rs#L159 as from VP8 spec range of tmp_range is [128,255], so that both bugged and formula version give split = 1.

@mcroomp
Copy link
Collaborator Author

mcroomp commented Feb 19, 2024

@danielrh @Melirius found a way to make this even faster

@mcroomp mcroomp merged commit 99aeec3 into main Feb 21, 2024
3 checks passed
@mcroomp mcroomp deleted the branchopt branch February 21, 2024 05:18
@danielrh
Copy link

This is so cool! After all these years you found a nice win in the inner loop :-)

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.

4 participants