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

Use only fixed-width uints in the C itoa functions #702

Merged
merged 2 commits into from
Jan 1, 2025

Conversation

clyring
Copy link
Member

@clyring clyring commented Dec 31, 2024

See commit messages.

The existing logic for decimal encoding of signed ints was a bit
more complicated than necessary in its handling for negative numbers,
mostly because of negation overflowing for INT_MIN.

But the absolute value of the smallest signed Int16 does fit into
an unsigned Word16 without overflowing, allowing some simplification.

Additionally, on hardware with slow integer division instructions,
fast division-by-known-divisor is typically faster for unsigned types,
so this change may lead to a slight speed-up on such platforms.

(We could almost certainly produce slightly better code still for
these platforms by hand, for example by exploiting the fact that
after the first division the numbers are small enough that a quotient
by ten can be extracted with a single mulhi and no shift.)
If the absolute value of the input is small enough to enter this
branch, then it fits in an Int and takes the very first branch instead.
@Bodigrim Bodigrim merged commit aca65b3 into haskell:master Jan 1, 2025
26 of 28 checks passed
@Bodigrim
Copy link
Contributor

Bodigrim commented Jan 1, 2025

Cool!

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