Single-precision float version of matherr

Jozef Lawrynowicz <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <20181129151355.7a3ab7c8@jozef-Aspire-VN7-793G>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.