[bug #57071] Fix math.h and function names that block 64-bit double

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

[bug #57071] Fix math.h and function names that block 64-bit double

Kevin Cuzner-2
URL:
  <https://savannah.nongnu.org/bugs/?57071>

                 Summary: Fix math.h and function names that block 64-bit
double
                 Project: AVR C Runtime Library
            Submitted by: gjlayde
            Submitted on: Thu 17 Oct 2019 07:10:37 AM UTC
                Category: None
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: None
                  Status: None
        Percent Complete: 0%
             Assigned to: None
        Originator Email:
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 2.0.0
           Fixed Release: None

    _______________________________________________________

Details:

Implementation of math.h / libm currently blocks 64-bit double, namely:

1) Function names are wrong, e.g. 32-bit implementation of sine is named
"sin", not "sinf".

2) There are "aliases" in math.h (macros actually) that define the float
version (like "sinf") to the double version (like "sin").  Problem is that
this:

2a) This is the wrong way round ("sin" should be alias of "sinf").

2b) There are no proper prototypes.

2c) Macros are bad, e.g. in C++ when some class implements a method for which
math.h defines a macro, C++ functions / methods are silently renamed.

3) math.h is unconditional, i.e. treats double != float just like double =
float.






    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?57071>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


_______________________________________________
AVR-libc-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev
Reply | Threaded
Open this post in threaded view
|

[bug #57071] Fix math.h and function names that block 64-bit double

Kevin Cuzner-2
Follow-up Comment #1, bug #57071 (project avr-libc):


        * include/math.h
        (cos, sin, tan, fmod, modf, sqrt, cbrt, hypot, square, floor, ceil)
        (frexp, ldexp, exp, cosh, sinh, tanh, asin, acos, atan, atan2)
        (log, log10, pow, isnan, isinf, signbit, fdim, fma, fmax, fmin)
        (trunc, round, lround, lrint) [double=64-bit]: Provide double
        prototypes.
        [double=32-bit]: Provide protos with assembler names which are
        the corresponding float function name.

        (cosf, sinf, tanf, fmodf, modff, sqrtf, cbrtf, hypotf, squaref)
        (floorf, ceilf, frexpf, ldexpf, expf, coshf, sinhf, tanhf, asinf)
        (acosf, atanf, atan2f, logf, log10f, powf, isnanf, isinff)
        (signbitf, fdimf, fmaf, fmaxf, fmin, truncf, roundf, lroundf)
        (lrintf):
        Turn from macro to proper prototype.
        (fabs, fabsf, isfinite, isfinitef, copysign, copysignf): Implement.

libm/fplib/
        * libm/fplib/acos.S: Use correct names for functions that deal
        with float, e.g. acosf instead of acos.  Adjust comments.
        * libm/fplib/asin.S: Same.
        * libm/fplib/atan.S: Same.
        * libm/fplib/atan2.S: Same.
        * libm/fplib/cbrt.S: Same.
        * libm/fplib/ceil.S: Same.
        * libm/fplib/copysign.S: Same.
        * libm/fplib/cos.S: Same.
        * libm/fplib/cosh.S: Same.
        * libm/fplib/exp.S: Same.
        * libm/fplib/fdim.S: Same.
        * libm/fplib/floor.S: Same.
        * libm/fplib/fma.S: Same.
        * libm/fplib/fmax.S: Same.
        * libm/fplib/fmin.S: Same.
        * libm/fplib/fmod.S: Same.
        * libm/fplib/fp_arccos.S: Same.
        * libm/fplib/frexp.S: Same.
        * libm/fplib/hypot.S: Same.
        * libm/fplib/isfinite.S: Same.
        * libm/fplib/isinf.S: Same.
        * libm/fplib/isnan.S: Same.
        * libm/fplib/ldexp.S: Same.
        * libm/fplib/log.S: Same.
        * libm/fplib/log10.S: Same.
        * libm/fplib/lrint.S: Same.
        * libm/fplib/lround.S: Same.
        * libm/fplib/modf.S: Same.
        * libm/fplib/pow.S: Same.
        * libm/fplib/round.S: Same.
        * libm/fplib/signbit.S: Same.
        * libm/fplib/sin.S: Same.
        * libm/fplib/sinh.S: Same.
        * libm/fplib/sqrt.S: Same.
        * libm/fplib/square.S: Same.
        * libm/fplib/tan.S: Same.
        * libm/fplib/tanh.S: Same.
        * libm/fplib/trunc.S: Same.


(file #47705)
    _______________________________________________________

Additional Item Attachment:

File name: math64.diff                    Size:53 KB
    <https://savannah.nongnu.org/file/math64.diff?file_id=47705>



    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?57071>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


_______________________________________________
AVR-libc-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev
Reply | Threaded
Open this post in threaded view
|

[bug #57071] Fix math.h and function names that block 64-bit double

Kevin Cuzner-2
Follow-up Comment #2, bug #57071 (project avr-libc):

Here is a version without __asm(symbol) that defines a symbol for double only
if sizeof(double) == sizeof(float).


        * include/math.h
        (cosf, sinf, tanf, fmodf, modff, sqrtf, cbrtf, hypotf, squaref)
        (floorf, ceilf, frexpf, ldexpf, expf, coshf, sinhf, tanhf, asinf)
        (acosf, atanf, atan2f, logf, log10f, powf, isnanf, isinff)
        (signbitf, fdimf, fmaf, fmaxf, fmin, truncf, roundf, lroundf)
        (lrintf): Turn from macro to proper prototype.
        (fabs, fabsf, isfinite, isfinitef, copysign, copysignf): Implement.

        * libm/fplib/asmdef.h (ALIAS_ENTRY): Remove.
        (ENTRY_DOUBLE32): New .macro that only defines the symbol
        if __SIZEOF_DOUBLE__ == __SIZEOF_FLOAT__.
        * libm/fplib/acos.S: Use correct names for functions that deal
        with float, e.g. acosf instead of acos.  Provide double symbol
        only if __SIZEOF_DOUBLE__ == __SIZEOF_FLOAT__.
        * libm/fplib/asin.S: Same.
        * libm/fplib/atan.S: Same.
        * libm/fplib/atan2.S: Same.
        * libm/fplib/cbrt.S: Same.
        * libm/fplib/ceil.S: Same.
        * libm/fplib/copysign.S: Same.
        * libm/fplib/cos.S: Same.
        * libm/fplib/cosh.S: Same.
        * libm/fplib/exp.S: Same.
        * libm/fplib/fdim.S: Same.
        * libm/fplib/floor.S: Same.
        * libm/fplib/fma.S: Same.
        * libm/fplib/fmax.S: Same.
        * libm/fplib/fmin.S: Same.
        * libm/fplib/fmod.S: Same.
        * libm/fplib/fp_arccos.S: Same.
        * libm/fplib/frexp.S: Same.
        * libm/fplib/hypot.S: Same.
        * libm/fplib/isfinite.S: Same.
        * libm/fplib/isinf.S: Same.
        * libm/fplib/isnan.S: Same.
        * libm/fplib/ldexp.S: Same.
        * libm/fplib/log.S: Same.
        * libm/fplib/log10.S: Same.
        * libm/fplib/lrint.S: Same.
        * libm/fplib/lround.S: Same.
        * libm/fplib/modf.S: Same.
        * libm/fplib/pow.S: Same.
        * libm/fplib/round.S: Same.
        * libm/fplib/signbit.S: Same.
        * libm/fplib/sin.S: Same.
        * libm/fplib/sinh.S: Same.
        * libm/fplib/sqrt.S: Same.
        * libm/fplib/square.S: Same.
        * libm/fplib/tan.S: Same.
        * libm/fplib/tanh.S: Same.
        * libm/fplib/trunc.S: Same.


(file #47711)
    _______________________________________________________

Additional Item Attachment:

File name: math64-syms.diff               Size:52 KB
    <https://savannah.nongnu.org/file/math64-syms.diff?file_id=47711>



    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?57071>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


_______________________________________________
AVR-libc-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev
Reply | Threaded
Open this post in threaded view
|

[bug #57071] Fix math.h and function names that block 64-bit double

Kevin Cuzner-2
Follow-up Comment #3, bug #57071 (project avr-libc):

Thanks, something "auto-configuring" like the second patch is much
appreciated.

Curious, what's the compiler switch to select 32- vs. 64-bit double? I'd like
to add a bit of documentation about the entire topic as well.

    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?57071>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57071] Fix math.h and function names that block 64-bit double

Kevin Cuzner-2
Follow-up Comment #4, bug #57071 (project avr-libc):

[comment #3 comment #3:]
> Curious, what's the compiler switch to select 32- vs. 64-bit double? I'd
like to add a bit of documentation about the entire topic as well.

I didn't settle on an interface yet, my preferred choice would be configure
options

--with-double=[32|64]
--with-long-double=[32|64]

where --with-double= triggers availability of, say, -mdouble64 and also sets
the default: --with-double=32 would make 64-bit double available, but the
default would still be double=float.

But the problem is not with the (configure) option(s), it's the extension of
the multilib space:

We currently have float/double/long-double = 32/32/32, and with the new
multilib variants we'd also have 32/32/64 and 32/64/64.  This would mean
blowing up the number of multilibs to 57 or beyond...

For libgcc I am using a hack to copy the [long-]double multilibs from the
traditional one so that the build-times don't go up.  This works because the
multilibs are the same: double=64 vs. double=32 is accomplished by referencing
__adddf3 instead of __addsf3, not by a different implementation of __adddf3.

For libc, there are only changes in a few places:

* How and if symbol aliases are provided (i.e. the topic of this issue).

* How printf et al. interprets %f, %lf, %g etc.

* For any functions that use open-coded [long-]double like dtostre (which is
ftostre actually).  We can implement this as ftostre and provide an alias or a
prototype with asm name depending on double layout.

* And of course the multilib structure.  I still have no clue how to integrate
`avr-gcc --print-multi-lib` into the configure process and how to make use of
`avr-gcc --print-multi-directory --mmcu=MMCU ...`.  This would be very much
appreciated in order to make avr-libc more independent of avr-gcc's version,
multilib-structure and multilib-options.  Ideas?


    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?57071>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57071] Fix math.h and function names that block 64-bit double

Kevin Cuzner-2
Follow-up Comment #5, bug #57071 (project avr-libc):

Thanks for the explanation.

I think I'll apply the patch then as is by now, and we might add some words
about the usage later on, when the configuration is settled.

    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?57071>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57071] Fix math.h and function names that block 64-bit double

Kevin Cuzner-2
Follow-up Comment #6, bug #57071 (project avr-libc):

[comment #5 comment #5:]
> Thanks for the explanation.
>
> I think I'll apply the patch then as is by now, and we might
> add some words about the usage later on, when the configuration
> is settled.

Great.  The current patch is supposed to be a no-op, so that no observable
effect should occur.

    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?57071>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57071] Fix math.h and function names that block 64-bit double

Kevin Cuzner-2
Follow-up Comment #7, bug #57071 (project avr-libc):


[comment #6 comment #6:]
> The current patch is supposed to be a no-op, so that
> no observable effect should occur.

There are observable effects actually:  The patch should also result in the
resolution of bug #49984.

    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?57071>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57071] Fix math.h and function names that block 64-bit double

Kevin Cuzner-2
Follow-up Comment #8, bug #57071 (project avr-libc):

FYI, there is the according GCC issue + patch

http://gcc.gnu.org/PR92055

From the doc of
https://gcc.gnu.org/bugzilla/attachment.cgi?id=47114&action=diff


+@item -mdouble=@var{bits}
+@opindex mdouble
+Set the size (in bits) of the @code{double} type.  Valid values for
+@var{bits} are 32 and 64. This option is only available if the compiler
+is configured with @code{--with-double=32} or with @code{--with-double=64},
+and the argument of @code{--with-double=} specifies the default layout of
+@code{double}.
+
+@item -mlong-double=@var{bits}
+@opindex mlong-double
+Set the size (in bits) of the @code{long double} type.  Valid values for
+@var{bits} are 32 and 64. This option is only available if the compiler
+is configured with @code{--with-long-double=32} or with
+@code{--with-long-double=64}, and the argument of @code{--with-long-double=}
+specifies the default layout of @code{long double}.




    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?57071>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57071] Fix math.h and function names that block 64-bit double

Kevin Cuzner-2
Follow-up Comment #9, bug #57071 (project avr-libc):

The GCC feature is upstream: https://gcc.gnu.org/r277908

The new configure options are:


--with-double={32|64|32,64|64,32}
--with-long-double={32|64|32,64|64,32|double}


For a documentation, see

https://gcc.gnu.org/install/configure.html#avr

Only 14 of the 20 combinations are valid, resulting in 12 different
configurations total.  Depending on the configuration, there will be up to 57
= 3*19 multilib variants.

The new compiler options are:


-mdouble={32|64}
-mlong-double={32|64}


For a documentation, see

https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html#index-mdouble

To display the mapping between option sets and multilib variants, use


avr-gcc -print-multi-lib


To show which multilib variant is actually picked for a specific set of
options, use


avr-gcc -print-multi-directory <options>


To factor out different floating-point layouts in a target program, you can
use -- like always -- the built-in defines


__SIZEOF_DOUBLE__
__SIZEOF_LONG_DOUBLE__


The libgcc build just copies the double64 and long-double64 multilib variants
from the vanilla one so that the build times won't go through the roof --
these variants would not contain any differences to the vanilla version,
anyway.

There is also the (undocumented, avr) configure option --with-fixed-point=no
which skips the build of the thousands of libgcc fixed-point modules.  You can
use this during development for sane build times.

    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?57071>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57071] Fix math.h and function names that block 64-bit double

Kevin Cuzner-2
Follow-up Comment #10, bug #57071 (project avr-libc):

Here is an updated version of the patch with the following changes:

* It also defines alias symbols for long double provided long double = float.
* It provides long double prototypes in math.h.
* Adds a new file common/alias.h which defines layout-dependent alias macros
(C + Asm).
* Turns double into float in the C-part of the lib (dtostr[ef], vfprintf,
atof, ...).
* vfprintf depends on sizeof ([long] double) and distinguishes between %lf and
%f if their layouts differ.  However, we are running out of flags (which are
currently 8 at most).
* It fixes abs / labs implementation so they do no more conflict with
stdlib.h.
* Fixes a bunch of unrelated build warnings so it can be built with
CFLAGS=-Werror


(file #47938)
    _______________________________________________________

Additional Item Attachment:

File name: math64-2.diff                  Size:71 KB
    <https://savannah.nongnu.org/file/math64-2.diff?file_id=47938>



    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?57071>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57071] Fix math.h and function names that block 64-bit double

Kevin Cuzner-2
Follow-up Comment #11, bug #57071 (project avr-libc):

Hi, here is an updated version of the patch.  Compared to the patch proposed
in comment #10, it fixes the vfprintf issues:

* Treat %f like %lf, same for other float printers.  If double is 64 bits, it
will only print "?".

* Support %Lf for long double, same for other float printers.  If long double
is 64 bits, it will only print "?".

(file #48029)
    _______________________________________________________

Additional Item Attachment:

File name: math64-3.diff                  Size:72 KB
    <https://savannah.nongnu.org/file/math64-3.diff?file_id=48029>



    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?57071>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57071] Fix math.h and function names that block 64-bit double

Kevin Cuzner-2
Follow-up Comment #12, bug #57071 (project avr-libc):

Here is a small addendum which fixes some problems that I ran into when
building avr-libc with avr-gcc v3.4.6:

1) The compiler might not recognize -Wno-sign-compare or
-Wno-maybe-uninitialized which are used to silence some build warnings.

2) Old GCC does not built-in define __SIZEOF_DOUBLE__ and
__SIZEOF_LONG_DOUBLE__, hence do it by hand.



(file #48240)
    _______________________________________________________

Additional Item Attachment:

File name: math64-addend1.diff            Size:2 KB
    <https://savannah.nongnu.org/file/math64-addend1.diff?file_id=48240>



    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?57071>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57071] Fix math.h and function names that block 64-bit double

Kevin Cuzner-2
Follow-up Comment #13, bug #57071 (project avr-libc):


[comment #12 comment #12:]
> Here is a small addendum which fixes some problems that I ran into when
building avr-libc with avr-gcc v3.4.6:

Note: Just the fact that current avr-libc can be built with avr-gcc v3.4.6
does not mean the result is usable in any way.  Modern avr-libc drags device
properties from avr-gcc's built-in macros like __AVR_HAVE_JMP_CALL__ which
archaic avr-gcc does not define.

    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?57071>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/