[PATCH] libm/math: Use __math_xflow in obsolete math code
Keith Packard
keithp@keithp.com
Sat Aug 1 22:40:28 GMT 2020
Szabolcs Nagy <szabolcs.nagy@arm.com> writes:
> this looks good.
Thanks.
> note1: i used c99 code when i wrote the
> new math code and currently the old math
> code can be compiled with older compilers,
> this change might prevent that.
I don't really have any way to test that as I'm using current compilers
for this work.
> note2: xflow may also try to set errno,
> depending on the WANT_ERRNO setting (which
> is on by default).
I've got a separate patch ready which sets WANT_ERRNO based on
_IEEE_LIBM so that both halves of the math library agree on whether
errno should be set. That's sufficient for my uses (where I always set
_IEEE_LIBM, and so never set errno) but not going to support the
old distinction between the __ieee754 functions and the posix functions.
I hadn't considered that issue. In my environment, I'm not enabling
errno support. I can think of a couple of possible fixes:
1) Copy the __math_xflow functions to libm/math and remove errno
handling so that the existing wrapper functions control how
errno is managed.
2) Remove the __ieee754 entry points from the library so that the
old library only offers the regular API, and the _IEEE_LIBM
configuration changes those functions to not modify errno. Linking
the new math code so that it also used the same configuration value
would keep everyone in sync and offer matching errno behavior.
Because the new math code uses double-precision arithmetic, I'm using
the old math code on devices without double-precision hardware, like ARM
processors that don't have __ARM_FP & 0x8. This includes pretty much all
of the processors I build products out of.
> in that case note that some compilers may model math functions as pure
> (no sideeffect) and apply optimizations accrodingly, this may create
> unexpected errno clobbers if math functions actually set errno.
> (-fno-math-errno behaviour in gcc) but this affects other libm
> implementations too and so far we haven't run into issues.
It would be kinda cool if we could drive all of the errno support based
on this compiler flag and eliminate the library configuration
setting. We'd want this to take effect while building the application
instead of at runtime.
> i think e.g. return __math_uflowf(s == -1.0f)
> would work better (but it's better to set a
> sign flag where s is set).
You're right -- here's an updated patch which uses (s < 0) as that
doesn't require an extra constant.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-libm-math-Use-__math_xflow-in-obsolete-math-code-v2.patch
Type: text/x-diff
Size: 10233 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20200801/8fc84c35/attachment.bin>
-------------- next part --------------
--
-keith
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20200801/8fc84c35/attachment.sig>
More information about the Newlib
mailing list