Some compilers can't do the proper optimization of the code, which this PR modifies.
At least GCC and Clang produces div_mod operation twice - for value / status->base and digit = value % status->base.
In order to help compiler generate better code we need keep div and mod code sections close to each other.
Of course we don't need to do the optimization instead of the compilers but maybe they thinks that status->base can be modified in between div and mod sections.
Please take it into account.
The heavy-handed macro magic in _PDCLIB_print.c has been bugging me for a while. I am thinking about replacing the whole thing with something else, possibly making use of lldiv().
Some compilers can't do the proper optimization of the code, which this PR modifies. At least GCC and Clang produces
div_mod
operation twice - forvalue / status->base
anddigit = value % status->base
. In order to help compiler generate better code we need keepdiv
andmod
code sections close to each other.Poor output example: https://godbolt.org/z/cEMx41 Better output example: https://godbolt.org/z/o3fc13
Of course we don't need to do the optimization instead of the compilers but maybe they thinks that
status->base
can be modified in betweendiv
andmod
sections. Please take it into account.