mailing list of musl libc
 help / color / mirror / code / Atom feed
* math_errhandling definition
@ 2013-11-17 21:54 Bobby Bingham
  2013-11-17 23:13 ` Szabolcs Nagy
  0 siblings, 1 reply; 5+ messages in thread
From: Bobby Bingham @ 2013-11-17 21:54 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 768 bytes --]

I think the definition of math_errhandling is wrong on a couple
architectures.  C99 (7.12) says:

    If the expression math_errhandling & MATH_ERREXCEPT can be nonzero,
    the implementation shall define the macros FE_DIVBYZERO, FE_INVALID,
    and FE_OVERFLOW in <fenv.h>.

math.h always defines math_errhandling as 2 (MATH_ERREXCEPT), but
whether those FE_* macros are defined or not is architecture-dependent.
In particular, ARM only defines them if __ARM_PCS_VFP is defined, and
microblaze does not define them.

It looks like if the architecture doesn't support floating point
exceptions, math_errhandling must be MATH_ERRNO. This in turn requires
that the various math functions set errno appropriately, which it
doesn't look like musl's do.

--
Bobby Bingham

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: math_errhandling definition
  2013-11-17 21:54 math_errhandling definition Bobby Bingham
@ 2013-11-17 23:13 ` Szabolcs Nagy
  2013-11-18 19:59   ` Rich Felker
  0 siblings, 1 reply; 5+ messages in thread
From: Szabolcs Nagy @ 2013-11-17 23:13 UTC (permalink / raw)
  To: musl

* Bobby Bingham <koorogi@koorogi.info> [2013-11-17 15:54:54 -0600]:
> I think the definition of math_errhandling is wrong on a couple
> architectures.  C99 (7.12) says:
> 
>     If the expression math_errhandling & MATH_ERREXCEPT can be nonzero,
>     the implementation shall define the macros FE_DIVBYZERO, FE_INVALID,
>     and FE_OVERFLOW in <fenv.h>.
> 
> math.h always defines math_errhandling as 2 (MATH_ERREXCEPT), but
> whether those FE_* macros are defined or not is architecture-dependent.
> In particular, ARM only defines them if __ARM_PCS_VFP is defined, and
> microblaze does not define them.
> 
> It looks like if the architecture doesn't support floating point
> exceptions, math_errhandling must be MATH_ERRNO. This in turn requires
> that the various math functions set errno appropriately, which it
> doesn't look like musl's do.

yes, but..

musl aims to support annex f

annex f requires math_errhandling & MATH_ERREXCEPT to be true
ie math errors are reported as floating-point exceptions
according to ieee 754 semantics

annex f also requires all five ieee status flags to be defined
FE_OVERFLOW, FE_UNDERFLOW, FE_DIVBYZERO, FE_INVALID, FE_INEXACT

(c99 requires that unsupported flags are not defined and has
weaker requirements without annex f as you quoted)

unfortunately c99 made it (nearly) impossible to implement
floating-point with ieee exception semantics in software and
indeed gcc does not provide exceptions for fpu-less archs
(unless the underlying arch has hw registers for it)

this is fixed in c11 which changed signal handler semantics wrt
the floating-point environment and introduced thread storage
duration (however libgcc does not implement fp status flags with
thread storage duration just yet)

musl can only support annex f if the underlying hardware
(or on fpu-less archs the compiler or kernel fp emulation)
support ieee754

in short this should be reported against libgcc

in theory we could support MATH_ERRNO on such platforms, but
it would be a significant effort and still would not give useful
fp semantics other than slightly stricter c99 conformance


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: math_errhandling definition
  2013-11-17 23:13 ` Szabolcs Nagy
@ 2013-11-18 19:59   ` Rich Felker
  2013-11-20  5:27     ` Bobby Bingham
  0 siblings, 1 reply; 5+ messages in thread
From: Rich Felker @ 2013-11-18 19:59 UTC (permalink / raw)
  To: musl

On Mon, Nov 18, 2013 at 12:13:25AM +0100, Szabolcs Nagy wrote:
> * Bobby Bingham <koorogi@koorogi.info> [2013-11-17 15:54:54 -0600]:
> > I think the definition of math_errhandling is wrong on a couple
> > architectures.  C99 (7.12) says:
> > 
> >     If the expression math_errhandling & MATH_ERREXCEPT can be nonzero,
> >     the implementation shall define the macros FE_DIVBYZERO, FE_INVALID,
> >     and FE_OVERFLOW in <fenv.h>.
> > 
> > math.h always defines math_errhandling as 2 (MATH_ERREXCEPT), but
> > whether those FE_* macros are defined or not is architecture-dependent.
> > In particular, ARM only defines them if __ARM_PCS_VFP is defined, and
> > microblaze does not define them.
> > 
> > It looks like if the architecture doesn't support floating point
> > exceptions, math_errhandling must be MATH_ERRNO. This in turn requires
> > that the various math functions set errno appropriately, which it
> > doesn't look like musl's do.
> 
> yes, but..
> 
> musl aims to support annex f
> 
> annex f requires math_errhandling & MATH_ERREXCEPT to be true
> ie math errors are reported as floating-point exceptions
> according to ieee 754 semantics
> 
> annex f also requires all five ieee status flags to be defined
> FE_OVERFLOW, FE_UNDERFLOW, FE_DIVBYZERO, FE_INVALID, FE_INEXACT
> 
> (c99 requires that unsupported flags are not defined and has
> weaker requirements without annex f as you quoted)
> 
> unfortunately c99 made it (nearly) impossible to implement
> floating-point with ieee exception semantics in software and
> indeed gcc does not provide exceptions for fpu-less archs
> (unless the underlying arch has hw registers for it)
> 
> this is fixed in c11 which changed signal handler semantics wrt
> the floating-point environment and introduced thread storage
> duration (however libgcc does not implement fp status flags with
> thread storage duration just yet)
> 
> musl can only support annex f if the underlying hardware
> (or on fpu-less archs the compiler or kernel fp emulation)
> support ieee754
> 
> in short this should be reported against libgcc
> 
> in theory we could support MATH_ERRNO on such platforms, but
> it would be a significant effort and still would not give useful
> fp semantics other than slightly stricter c99 conformance

Yes, nsz summed this up very nicely. Bobby, is there a practical issue
you're hitting with the lack of math_errhandling on these archs, or
are you just concerned with conformance from a theoretical standpoint?
I ask mainly because this will help us consider how to deal with the
issue in the future and what to prioritize. My general feeling right
now is that ARM users should prefer the "armhf" ABI whenever possible,
and that using microblaze for floating point computation is just a bad
idea to begin with. But we'll have to consider other archs as they are
added (if others lack fp exceptions ABIs) and whether proper
soft-float with exceptions is on the way...

Rich


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: math_errhandling definition
  2013-11-18 19:59   ` Rich Felker
@ 2013-11-20  5:27     ` Bobby Bingham
  2013-11-20 20:50       ` Rich Felker
  0 siblings, 1 reply; 5+ messages in thread
From: Bobby Bingham @ 2013-11-20  5:27 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 851 bytes --]

On Mon, Nov 18, 2013 at 02:59:31PM -0500, Rich Felker wrote:
> [...]
> Yes, nsz summed this up very nicely. Bobby, is there a practical issue
> you're hitting with the lack of math_errhandling on these archs, or
> are you just concerned with conformance from a theoretical standpoint?

No practical issue. I just stumbled across this part of the spec while
trying to determine if some of gcc's output on SH4 was conforming or
not.

Is the differences in the level of conformance on the different
architectures documented anywhere?  The "Introduction to musl" page on
the website states that "minimal machine-specific code means less change
of breakage on minority architectures and better success with 'write
once run everywhere' C development".  It would probably be worthwhile to
document known exceptions to that when they exist.

--
Bobby Bingham

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: math_errhandling definition
  2013-11-20  5:27     ` Bobby Bingham
@ 2013-11-20 20:50       ` Rich Felker
  0 siblings, 0 replies; 5+ messages in thread
From: Rich Felker @ 2013-11-20 20:50 UTC (permalink / raw)
  To: musl

On Tue, Nov 19, 2013 at 11:27:15PM -0600, Bobby Bingham wrote:
> On Mon, Nov 18, 2013 at 02:59:31PM -0500, Rich Felker wrote:
> > [...]
> > Yes, nsz summed this up very nicely. Bobby, is there a practical issue
> > you're hitting with the lack of math_errhandling on these archs, or
> > are you just concerned with conformance from a theoretical standpoint?
> 
> No practical issue. I just stumbled across this part of the spec while
> trying to determine if some of gcc's output on SH4 was conforming or
> not.
> 
> Is the differences in the level of conformance on the different
> architectures documented anywhere?  The "Introduction to musl" page on
> the website states that "minimal machine-specific code means less change
> of breakage on minority architectures and better success with 'write
> once run everywhere' C development".  It would probably be worthwhile to
> document known exceptions to that when they exist.

Yes, I agree. That should go in the manual somewhere -- in fact I
think it merits a chapter/section on what aspects (at least in the
scope of what's visible to a conforming program) of the library vary
between supported archs.

Rich


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-11-20 20:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-17 21:54 math_errhandling definition Bobby Bingham
2013-11-17 23:13 ` Szabolcs Nagy
2013-11-18 19:59   ` Rich Felker
2013-11-20  5:27     ` Bobby Bingham
2013-11-20 20:50       ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).