[PATCH] Simplify integer output-related functions in libgfortran
FX
fxcoudert@gmail.com
Sat Dec 25 12:13:37 GMT 2021
Merry Christmas!
The code related to integer output in libgfortran has accumulated some… oddities over the years. I will soon post a finalized patch for faster integer-to-decimal conversion (see https://gcc.gnu.org/pipermail/fortran/2021-December/057201.html), but while working on that I found a couple of things we ought to fix, that are not directly related.
So this patch is a simplification patch, a no-op. It does the following things:
- gfc_itoa() is always called for nonnegative values, to make it take an unsigned arg. It allows us to simplify the code handling for negative signs (instead of doing it in two places).
- fix undefined behaviour on possible overflow when negating large negative values (-HUGE-1)
- all callers of write_decimal() always use gfc_itoa() as conversion function, so remove one layer of indirection: get rid of that argument, call gfc_itoa() directly inside write_decimal()
- gfc_xtoa() is only used in one file anymore, so move it there and rename it to xtoa()
- ztoa_big() is renamed to xtoa_big(), following the convention of other ?to_big() functions
- runtime/backtrace.c is the only user of gfc_itoa() outside the I/O system; add a comment so we remember in the future why we use gfc_itoa() there… and what are its limits
All this makes the code easier to understand, more consistent, probably marginally more efficient (the gfc_itoa pointer indirection), and will make the future work on speeding up gfc_itoa() easier.
Bootstrapped and regtested on x86_64-pc-linux-gnu.
OK to commit?
FX
-------------- next part --------------
A non-text attachment was scrubbed...
Name: itoa.patch
Type: application/octet-stream
Size: 10520 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20211225/a5034a2b/attachment.obj>
More information about the Gcc-patches
mailing list