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 instruction size #14

Merged
merged 3 commits into from
Sep 7, 2022
Merged

Optimize instruction size #14

merged 3 commits into from
Sep 7, 2022

Conversation

gilescope
Copy link
Contributor

If you look in the std lib we do these tricks in to_digit.

Smaller wasm is a good thing... (godbolt: https://godbolt.org/z/vocdaKW9x )

I know speed is not the prime reason for the crate, but bench showed a 20% speedup of hex::encode when I ran them.
(The rest of the benches looked no different.)

@aurexav
Copy link
Member

aurexav commented Sep 7, 2022

Smaller wasm is a good thing... (godbolt: godbolt.org/z/vocdaKW9x )

Hey! Thanks for the PR!

I found this also makes the instructions smaller.
Same instructions, same speed but more readable.

fn is_hex_ascii(byte: &u8) -> bool {
	// Convert to lowercase.
	let byte = byte | 0b10_0000;
	
	matches!(byte, b'0'..=b'9' | b'a'..=b'f')
}

@gilescope
Copy link
Contributor Author

Short and sweet, I like it.

@aurexav aurexav changed the title 1/3rd less instructions than match Optimize Instructions Sep 7, 2022
@aurexav aurexav merged commit 1e4c742 into hack-ink:main Sep 7, 2022
@aurexav aurexav changed the title Optimize Instructions Optimize instruction size Sep 7, 2022
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.

2 participants