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

GCC if (thing - 12 < 3U) pattern #193

Open
zbanks opened this issue Dec 14, 2021 · 0 comments
Open

GCC if (thing - 12 < 3U) pattern #193

zbanks opened this issue Dec 14, 2021 · 0 comments

Comments

@zbanks
Copy link
Collaborator

zbanks commented Dec 14, 2021

From @ethteck

but just another thing I remembered: if you're doing an or check for consecutive values of thing like 12, 13, 14, gcc will optimize it as (thing - 12 < 3U)

if (thing - 12 < 3U) expands to if (thing == 12 || thing == 13 || thing == 14). Although they're both equivalent, usually the latter is more natural for smallish numbers of cases.

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

No branches or pull requests

1 participant