public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* Re: Single-precision float version of matherr
@ 2018-12-03 14:56 Wilco Dijkstra
  2018-12-03 18:59 ` Jozef Lawrynowicz
  0 siblings, 1 reply; 5+ messages in thread
From: Wilco Dijkstra @ 2018-12-03 14:56 UTC (permalink / raw)
  To: newlib, jozef.l; +Cc: nd

Hi,

Rather than keeping it, consider just removing all support for matherr since it is
obsolete (http://man7.org/linux/man-pages/man3/matherr.3.html):

       "Note: the mechanism described in this page is no longer supported by
       glibc.  Before glibc 2.27, it had been marked as obsolete.  Since
       glibc 2.27, the mechanism has been removed altogether.  New
       applications should use the techniques described in math_error(7) and
       fenv(3).  This page documents the matherr() mechanism as an aid for
       maintaining and porting older applications."

I'm sure no embedded application uses matherr since it is a historical
System V oddity, so nobody will ever miss it. Note that the recently rewritten
math functions in newlib do not use matherr at all.

Wilco

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

* Re: Single-precision float version of matherr
  2018-12-03 14:56 Single-precision float version of matherr Wilco Dijkstra
@ 2018-12-03 18:59 ` Jozef Lawrynowicz
  2018-12-04  6:46   ` Wilco Dijkstra
  0 siblings, 1 reply; 5+ messages in thread
From: Jozef Lawrynowicz @ 2018-12-03 18:59 UTC (permalink / raw)
  To: Wilco Dijkstra; +Cc: newlib, nd

On Mon, 3 Dec 2018 12:22:38 +0000
Wilco Dijkstra <Wilco.Dijkstra@arm.com> wrote:

> Hi,
> 
> Rather than keeping it, consider just removing all support for matherr since it is
> obsolete (http://man7.org/linux/man-pages/man3/matherr.3.html):
> 
>        "Note: the mechanism described in this page is no longer supported by
>        glibc.  Before glibc 2.27, it had been marked as obsolete.  Since
>        glibc 2.27, the mechanism has been removed altogether.  New
>        applications should use the techniques described in math_error(7) and
>        fenv(3).  This page documents the matherr() mechanism as an aid for
>        maintaining and porting older applications."
> 
> I'm sure no embedded application uses matherr since it is a historical
> System V oddity, so nobody will ever miss it. Note that the recently rewritten
> math functions in newlib do not use matherr at all.
> 
> Wilco

Hi Wilco,

Thanks for the tip.
I also noticed that other embedded toolchains (for MSP430 at least) do not have
a similar concept to matherr and instead just rely on errno. Good to hear it
can be removed altogether.

I presume it's not even worth keeping the old code available through a macro
such as __OBSOLETE_MATHERR?

Jozef

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

* Re: Single-precision float version of matherr
  2018-12-03 18:59 ` Jozef Lawrynowicz
@ 2018-12-04  6:46   ` Wilco Dijkstra
  0 siblings, 0 replies; 5+ messages in thread
From: Wilco Dijkstra @ 2018-12-04  6:46 UTC (permalink / raw)
  To: Jozef Lawrynowicz; +Cc: newlib, nd

Hi Jozef,

> Thanks for the tip.
> I also noticed that other embedded toolchains (for MSP430 at least) do not have
> a similar concept to matherr and instead just rely on errno. Good to hear it
> can be removed altogether.

Well errno is almost as obsolete after C99...

> I presume it's not even worth keeping the old code available through a macro
> such as __OBSOLETE_MATHERR?

Indeed, it won't be missed.

Wilco
    

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

* Re: Single-precision float version of matherr
  2018-11-30 12:42 Jozef Lawrynowicz
@ 2018-12-03 12:22 ` Jozef Lawrynowicz
  0 siblings, 0 replies; 5+ messages in thread
From: Jozef Lawrynowicz @ 2018-12-03 12:22 UTC (permalink / raw)
  To: newlib

On Thu, 29 Nov 2018 15:13:55 +0000
Jozef Lawrynowicz <jozef.l@mittosystems.com> wrote:

> I implemented <<sf_matherr>> (i.e. a single-precision float matherr), and
> <<sf_exception>> (i.e. single-precision float exception), and patched 
> sqrtf in wf_sqrt.c to use the new constructs.

Actually, I think it would be better for the user if there weren't these new
"sf_*" constructs, and instead the exception structure was modified to have
both a double and float version of arg1, arg2 and retval, each within a union
inside the struct.
This way <<matherr>> can still be used to handle errors for both float and
double math functions.

The union with the float and double version of these fields would only be used
when this behaviour is explicitly selected, so the default
behaviour would remain unchanged.

Jozef

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

* Single-precision float version of matherr
@ 2018-11-30 12:42 Jozef Lawrynowicz
  2018-12-03 12:22 ` Jozef Lawrynowicz
  0 siblings, 1 reply; 5+ messages in thread
From: Jozef Lawrynowicz @ 2018-11-30 12:42 UTC (permalink / raw)
  To: newlib

The float version of floating point math functions, such as <<sqrtf>>, call the
<<matherr>> function when an error occurs.

<<matherr>> takes the <<exception>> structure (defined in math.h) as an
argument. <<exception>> is reproduced below:
  struct exception
  {
    int type;
    char *name;
    double arg1;
    double arg2;
    double retval;
    int err;
  };

Note that arg1, arg2, and retval are doubles, so conversions from the float
value in the math function to double will require some double arithmeric
routines.

I implemented <<sf_matherr>> (i.e. a single-precision float matherr), and
<<sf_exception>> (i.e. single-precision float exception), and patched 
sqrtf in wf_sqrt.c to use the new constructs.
For msp430-elf this saves 1.5k bytes in a simple program which calls sqrtf,
compared to the current double-precision <<matherr>> and <<exception>>
implementation.
The reduced code size comes from some math functions which are no longer
needed:
  __ashldi3 = 128 bytes
  __extendsfdf2 = 86 bytes
  __make_dp = 52 bytes
  __make_fp = 58 bytes
  __pack_d = 688 bytes
  __truncdfsf2 = 108 bytes
  __unpack_d = 358 bytes

Before I go ahead and fixup the other floating point math functions to use
sf_matherr and sf_exception, is there anything I should be aware of, e.g. any
standards I am breaking by doing this, or any reason the double-precision
arg1, arg2 and retval are useful for single-precision float operations?

My plan for is for the out-of-the-box behaviour to remain the same, but if
the "_SF_MATHERR" symbol is defined, then the alternative implementation will
be used.

Thanks,
Jozef

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

end of thread, other threads:[~2018-12-03 18:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-03 14:56 Single-precision float version of matherr Wilco Dijkstra
2018-12-03 18:59 ` Jozef Lawrynowicz
2018-12-04  6:46   ` Wilco Dijkstra
  -- strict thread matches above, loose matches on Subject: below --
2018-11-30 12:42 Jozef Lawrynowicz
2018-12-03 12:22 ` Jozef Lawrynowicz

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 read-only IMAP folder(s) and NNTP newsgroup(s).