public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgcc/113155] New: large overhead for cast float to uint64_t. Arm cortex-m4 (ARMv7E-M, fpv4-sp-d16, ieee 754). Compiler: arm-none-eabi-gcc
@ 2023-12-27  7:03 kirdyankinsp at gmail dot com
  2023-12-27  7:17 ` [Bug target/113155] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: kirdyankinsp at gmail dot com @ 2023-12-27  7:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113155

            Bug ID: 113155
           Summary: large overhead for cast float to uint64_t. Arm
                    cortex-m4 (ARMv7E-M, fpv4-sp-d16, ieee 754). Compiler:
                    arm-none-eabi-gcc
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libgcc
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kirdyankinsp at gmail dot com
  Target Milestone: ---

To cast float to uint64 the initial value first converted to double. Cortex-M4
does not have hardware support for "double". Therefore, such an implementation
adds several kilobytes of code, which is unacceptable for embeded systems with
limited resources. In addition, increasing the code size is, of course, low
performance.
I think it is necessary to separate the softfloat functions for platforms that
have hardware "float" support and do not have a hardware "double". The current
version cannot be used for embedded systems. Additional functions need to be
written.
Below is the __aeabi_f2ulz code for fpv4-sp-d16 (ieee 754):

uint64_t __aeabi_f2ulz(float f)
{
  uint32_t result = *((uint32_t*) &f);
  uint32_t exp;
  result &= (~0x80000000);
  exp = result >> 23;
  result &= 0x7FFFFF;
  result |= 0x800000;
#if CHECK_UB
  if (exp == 0xFF) // if NaN or inf
  {
    return 0x8000000000000000; // ????????
  }
  if(exp > (0x96 + 40)) // if the variable value is too large
  {
    return 0x8000000000000000; // ????????
  }
#endif
  if (exp < 0x7F)
  {
    return 0;
  }
  if (exp <= 0x96U)
  {
    exp = 0x96 - exp;
    result >>= exp;
    return (uint64_t) result;
  }
  exp -= 0x96U;
  return (uint64_t) result << exp;
}

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

* [Bug target/113155] large overhead for cast float to uint64_t. Arm cortex-m4 (ARMv7E-M, fpv4-sp-d16, ieee 754). Compiler: arm-none-eabi-gcc
  2023-12-27  7:03 [Bug libgcc/113155] New: large overhead for cast float to uint64_t. Arm cortex-m4 (ARMv7E-M, fpv4-sp-d16, ieee 754). Compiler: arm-none-eabi-gcc kirdyankinsp at gmail dot com
@ 2023-12-27  7:17 ` pinskia at gcc dot gnu.org
  2023-12-27  7:23 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-27  7:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113155

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
           Keywords|                            |missed-optimization
          Component|libgcc                      |target

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

* [Bug target/113155] large overhead for cast float to uint64_t. Arm cortex-m4 (ARMv7E-M, fpv4-sp-d16, ieee 754). Compiler: arm-none-eabi-gcc
  2023-12-27  7:03 [Bug libgcc/113155] New: large overhead for cast float to uint64_t. Arm cortex-m4 (ARMv7E-M, fpv4-sp-d16, ieee 754). Compiler: arm-none-eabi-gcc kirdyankinsp at gmail dot com
  2023-12-27  7:17 ` [Bug target/113155] " pinskia at gcc dot gnu.org
@ 2023-12-27  7:23 ` pinskia at gcc dot gnu.org
  2023-12-27  7:24 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-27  7:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113155

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I looked into the sources of libgcc, __aeabi_f2ulz is defined as __fixunssfdi
which is defined in soft-fp/fixunssfdi.c and that does:
```
UDItype
__fixunssfdi (SFtype a)
{
  FP_DECL_EX;
  FP_DECL_S (A);
  UDItype r;

  FP_INIT_EXCEPTIONS;
  FP_UNPACK_RAW_S (A, a);
  FP_TO_INT_S (r, A, DI_BITS, 0);
  FP_HANDLE_EXCEPTIONS;

  return r;
}
```

FP_TO_INT_S is defined to _FP_TO_INT which basically does what you want except
it can handle FP exceptions.

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

* [Bug target/113155] large overhead for cast float to uint64_t. Arm cortex-m4 (ARMv7E-M, fpv4-sp-d16, ieee 754). Compiler: arm-none-eabi-gcc
  2023-12-27  7:03 [Bug libgcc/113155] New: large overhead for cast float to uint64_t. Arm cortex-m4 (ARMv7E-M, fpv4-sp-d16, ieee 754). Compiler: arm-none-eabi-gcc kirdyankinsp at gmail dot com
  2023-12-27  7:17 ` [Bug target/113155] " pinskia at gcc dot gnu.org
  2023-12-27  7:23 ` pinskia at gcc dot gnu.org
@ 2023-12-27  7:24 ` pinskia at gcc dot gnu.org
  2023-12-27  7:34 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-27  7:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113155

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-12-27

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>The current version cannot be used for embedded systems.

I am thinking you don't have the multilibs set up correctly.

How did you configure GCC here?

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

* [Bug target/113155] large overhead for cast float to uint64_t. Arm cortex-m4 (ARMv7E-M, fpv4-sp-d16, ieee 754). Compiler: arm-none-eabi-gcc
  2023-12-27  7:03 [Bug libgcc/113155] New: large overhead for cast float to uint64_t. Arm cortex-m4 (ARMv7E-M, fpv4-sp-d16, ieee 754). Compiler: arm-none-eabi-gcc kirdyankinsp at gmail dot com
                   ` (2 preceding siblings ...)
  2023-12-27  7:24 ` pinskia at gcc dot gnu.org
@ 2023-12-27  7:34 ` pinskia at gcc dot gnu.org
  2023-12-28  5:07 ` kirdyankinsp at gmail dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-27  7:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113155

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Can you provide the following:
* How you configured/built GCC?
* What command line options that you pass to GCC for building your application?

I am suspecting you are not using the correct options to get the  __aeabi_f2ulz
that does not convert to double first.

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

* [Bug target/113155] large overhead for cast float to uint64_t. Arm cortex-m4 (ARMv7E-M, fpv4-sp-d16, ieee 754). Compiler: arm-none-eabi-gcc
  2023-12-27  7:03 [Bug libgcc/113155] New: large overhead for cast float to uint64_t. Arm cortex-m4 (ARMv7E-M, fpv4-sp-d16, ieee 754). Compiler: arm-none-eabi-gcc kirdyankinsp at gmail dot com
                   ` (3 preceding siblings ...)
  2023-12-27  7:34 ` pinskia at gcc dot gnu.org
@ 2023-12-28  5:07 ` kirdyankinsp at gmail dot com
  2023-12-28  6:22 ` pinskia at gcc dot gnu.org
  2023-12-28  6:48 ` kirdyankinsp at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: kirdyankinsp at gmail dot com @ 2023-12-28  5:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113155

--- Comment #4 from Sergey Kirdyankin <kirdyankinsp at gmail dot com> ---
Compiler command line (platform configure):
arm-none-eabi-gcc -march=armv7e-m -mcpu=cortex-m4 -mfloat-abi=hard
-mfpu=fpv4-sp-d16 -mthumb ...

Disassembler:
080016c0 <__aeabi_f2ulz>:
 80016c0:       b5d0            push    {r4, r6, r7, lr}
 80016c2:       f7ff ff3f       bl      8001544 <__aeabi_f2d> !!!!!!!!!!!!
 80016c6:       4b0c            ldr     r3, [pc, #48]   @ (80016f8
<__aeabi_f2ulz+0x38>)
 80016c8:       2200            movs    r2, #0
 80016ca:       4606            mov     r6, r0
 80016cc:       460f            mov     r7, r1
 80016ce:       f7ff fcab       bl      8001028 <__aeabi_dmul>
 80016d2:       f7ff ff8f       bl      80015f4 <__aeabi_d2uiz>
 80016d6:       4604            mov     r4, r0
 80016d8:       f7ff ff12       bl      8001500 <__aeabi_ui2d>
 80016dc:       4b07            ldr     r3, [pc, #28]   @ (80016fc
<__aeabi_f2ulz+0x3c>)
 80016de:       2200            movs    r2, #0
 80016e0:       f7ff fca2       bl      8001028 <__aeabi_dmul>
 80016e4:       4602            mov     r2, r0
 80016e6:       460b            mov     r3, r1
 80016e8:       4630            mov     r0, r6
 80016ea:       4639            mov     r1, r7
 80016ec:       f7ff fdca       bl      8001284 <__aeabi_dsub>
 80016f0:       f7ff ff80       bl      80015f4 <__aeabi_d2uiz>
 80016f4:       4621            mov     r1, r4
 80016f6:       bdd0            pop     {r4, r6, r7, pc}
 80016f8:       3df00000        .word   0x3df00000
 80016fc:       41f00000        .word   0x41f00000

I think this is a libgcc problem. Newlib has nothing to do with it

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

* [Bug target/113155] large overhead for cast float to uint64_t. Arm cortex-m4 (ARMv7E-M, fpv4-sp-d16, ieee 754). Compiler: arm-none-eabi-gcc
  2023-12-27  7:03 [Bug libgcc/113155] New: large overhead for cast float to uint64_t. Arm cortex-m4 (ARMv7E-M, fpv4-sp-d16, ieee 754). Compiler: arm-none-eabi-gcc kirdyankinsp at gmail dot com
                   ` (4 preceding siblings ...)
  2023-12-28  5:07 ` kirdyankinsp at gmail dot com
@ 2023-12-28  6:22 ` pinskia at gcc dot gnu.org
  2023-12-28  6:48 ` kirdyankinsp at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-28  6:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113155

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Again how did you configure gcc because that changes which libgcc is being used
and with what options?


Also I suspect you should just be using -march=armv7e-m+fp instead.

Provide the output of:
`arm-none-eabi-gcc -v` should be enough.

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

* [Bug target/113155] large overhead for cast float to uint64_t. Arm cortex-m4 (ARMv7E-M, fpv4-sp-d16, ieee 754). Compiler: arm-none-eabi-gcc
  2023-12-27  7:03 [Bug libgcc/113155] New: large overhead for cast float to uint64_t. Arm cortex-m4 (ARMv7E-M, fpv4-sp-d16, ieee 754). Compiler: arm-none-eabi-gcc kirdyankinsp at gmail dot com
                   ` (5 preceding siblings ...)
  2023-12-28  6:22 ` pinskia at gcc dot gnu.org
@ 2023-12-28  6:48 ` kirdyankinsp at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: kirdyankinsp at gmail dot com @ 2023-12-28  6:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113155

--- Comment #6 from Sergey Kirdyankin <kirdyankinsp at gmail dot com> ---
bin>arm-none-eabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-none-eabi-gcc
COLLECT_LTO_WRAPPER=C:/work/distributiv/arm-gnu-toolchain-13.2/bin/../libexec/gcc/arm-none-eabi/13.2.1/lto-wrapper.exe
Target: arm-none-eabi
Configured with: /data/jenkins/workspace/GNU-toolchain/arm-13/src/gcc/configure
--target=arm-none-eabi
--prefix=/data/jenkins/workspace/GNU-toolchain/arm-13/build-mingw-arm-none-eabi/install
--with-gmp=/data/jenkins/workspace/GNU-toolchain/arm-13/build-mingw-arm-none-eabi/host-tools
--with-mpfr=/data/jenkins/workspace/GNU-toolchain/arm-13/build-mingw-arm-none-eabi/host-tools
--with-mpc=/data/jenkins/workspace/GNU-toolchain/arm-13/build-mingw-arm-none-eabi/host-tools
--with-isl=/data/jenkins/workspace/GNU-toolchain/arm-13/build-mingw-arm-none-eabi/host-tools
--disable-shared --disable-nls --disable-threads --disable-tls
--enable-checking=release --enable-languages=c,c++,fortran --with-newlib
--with-gnu-as --with-headers=yes --with-gnu-ld
--with-native-system-header-dir=/include
--with-sysroot=/data/jenkins/workspace/GNU-toolchain/arm-13/build-mingw-arm-none-eabi/install/arm-none-eabi
--with-multilib-list=aprofile,rmprofile
--with-libiconv-prefix=/data/jenkins/workspace/GNU-toolchain/arm-13/build-mingw-arm-none-eabi/host-tools
--host=i686-w64-mingw32 --with-pkgversion='Arm GNU Toolchain 13.2.rel1 (Build
arm-13.7)' --with-bugurl=https://bugs.linaro.org/
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 13.2.1 20231009 (Arm GNU Toolchain 13.2.rel1 (Build arm-13.7))

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

end of thread, other threads:[~2023-12-28  6:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-27  7:03 [Bug libgcc/113155] New: large overhead for cast float to uint64_t. Arm cortex-m4 (ARMv7E-M, fpv4-sp-d16, ieee 754). Compiler: arm-none-eabi-gcc kirdyankinsp at gmail dot com
2023-12-27  7:17 ` [Bug target/113155] " pinskia at gcc dot gnu.org
2023-12-27  7:23 ` pinskia at gcc dot gnu.org
2023-12-27  7:24 ` pinskia at gcc dot gnu.org
2023-12-27  7:34 ` pinskia at gcc dot gnu.org
2023-12-28  5:07 ` kirdyankinsp at gmail dot com
2023-12-28  6:22 ` pinskia at gcc dot gnu.org
2023-12-28  6:48 ` kirdyankinsp at gmail dot com

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).