Skip to content

Long double macros#19242

Merged
acassis merged 3 commits into
apache:masterfrom
Cynerd:long-double-macros
Jul 2, 2026
Merged

Long double macros#19242
acassis merged 3 commits into
apache:masterfrom
Cynerd:long-double-macros

Conversation

@Cynerd

@Cynerd Cynerd commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

This fixes the issue discovered with a new versions of GCC:

  libm/lib_truncl.c: In function 'truncl':
  libm/lib_truncl.c:68:14: error: 'u.i.se' is used uninitialized [-Werror=uninitialized]
     68 |   int e = u.i.se & 0x7fff;
        |           ~~~^~~
  libm/lib_truncl.c:63:17: note: 'u' declared here
     63 |   union ldshape u =
        |                 ^
  libm/lib_truncl.c:69:14: error: 'u.i.se' is used uninitialized [-Werror=uninitialized]
     69 |   int s = u.i.se >> 15;
        |           ~~~^~~
  libm/lib_truncl.c:63:17: note: 'u' declared here
     63 |   union ldshape u =
        |                 ^
  libm/lib_truncl.c:63:17: error: 'u.i.se' is used uninitialized [-Werror=uninitialized]

This was originally submitted in #18480, but that failed to approach the missing long double definitions.

Impact

The changes were only covered for GCC and Clang. I haven't add definition for other compilers. Thus this will break compilers that have CONFIG_HAVE_LONG_DOUBLE defined. I put toggether the following list:

  • GCC and Clang
  • SDCC (undefines CONFIG_HAVE_LONG_DOUBLE)
  • Zilog (undefines CONFIG_HAVE_LONG_DOUBLE)
  • ICCARM
  • MSVC (I am not sure if the provided definiton is always correct)
  • TASKING

Please, can anyone deduce the correct definitions for these compilers?

The second impact is that I added limits_check.c to verify that we have correct constants set by comparing that against the definitions the compiler provides. This can trip on some platforms, of course.

Lastly, I am not sure whether I covered all possible long double types that could occur in NuttX. One notable omission I know about is IBM float, but as far as I can see, it wasn't covered for double either.

Testing

I tried to compile these changes on sim:nsh, same70-xplained:nsh, and rv-virt:nsh with gcc. No warnings or errors were introduced and in case of same70 the referenced warnigs are gone.

@github-actions github-actions Bot added Area: OS Components OS Components issues Size: M The size of the change in this PR is medium labels Jun 30, 2026
@Cynerd
Cynerd force-pushed the long-double-macros branch from be6341f to 2668466 Compare June 30, 2026 09:45
@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@Cynerd

Cynerd commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

Can someone confirm that MSVC always treats long double as double? Multiple sources on the internet hint at that, but I am not running Windows anywhere to check.

@Cynerd
Cynerd force-pushed the long-double-macros branch from 18be687 to deec17f Compare June 30, 2026 11:57
Comment thread libs/libc/limits_check.c Outdated
@Cynerd
Cynerd requested a review from xiaoxiang781216 June 30, 2026 13:37
@Cynerd
Cynerd force-pushed the long-double-macros branch from deec17f to f2f4182 Compare July 1, 2026 07:56
Comment thread libs/libc/limits_check.c Outdated
@Cynerd
Cynerd force-pushed the long-double-macros branch from f2f4182 to 24b28a6 Compare July 1, 2026 08:15
@Cynerd
Cynerd requested a review from xiaoxiang781216 July 1, 2026 08:16
@xiaoxiang781216

Copy link
Copy Markdown
Contributor

@Cynerd flash can't hold the final image:

====================================================================================
Configuration/Tool: stm32l0538-disco/nsh,CONFIG_ARM_TOOLCHAIN_GNU_EABI
2026-07-01 10:35:28
------------------------------------------------------------------------------------
  Cleaning...
  Configuring...
  Disabling CONFIG_ARM_TOOLCHAIN_GNU_EABI
  Enabling CONFIG_ARM_TOOLCHAIN_GNU_EABI
  Building NuttX...
arm-none-eabi-ld: /github/workspace/sources/nuttx/nuttx section `.data' will not fit in region `flash'
arm-none-eabi-ld: region `flash' overflowed by 20 bytes
make[1]: *** [Makefile:230: nuttx] Error 1
make: *** [tools/Unix.mk:569: nuttx] Error 2
make: Target 'all' not remade because of errors.
/github/workspace/sources/nuttx/tools/testbuild.sh: line 397: /github/workspace/sources/nuttx/../nuttx/nuttx.manifest: No such file or directory

@Cynerd

Cynerd commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@Cynerd flash can't hold the final image:

====================================================================================
Configuration/Tool: stm32l0538-disco/nsh,CONFIG_ARM_TOOLCHAIN_GNU_EABI
2026-07-01 10:35:28
------------------------------------------------------------------------------------
  Cleaning...
  Configuring...
  Disabling CONFIG_ARM_TOOLCHAIN_GNU_EABI
  Enabling CONFIG_ARM_TOOLCHAIN_GNU_EABI
  Building NuttX...
arm-none-eabi-ld: /github/workspace/sources/nuttx/nuttx section `.data' will not fit in region `flash'
arm-none-eabi-ld: region `flash' overflowed by 20 bytes
make[1]: *** [Makefile:230: nuttx] Error 1
make: *** [tools/Unix.mk:569: nuttx] Error 2
make: Target 'all' not remade because of errors.
/github/workspace/sources/nuttx/tools/testbuild.sh: line 397: /github/workspace/sources/nuttx/../nuttx/nuttx.manifest: No such file or directory

I have noticed. I will look into it, but this is most likely because some code is now correctly compiled in for long double compared to the previous invalid implementation (just for double such as scalbnl). I will look into it if that is the case or if something else is in play, but if that is true, then I am unsure how to resolve it except by disabling some options in the affected configurations to reduce the size.

@Cynerd

Cynerd commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@xiaoxiang781216 this MR is not the fault. I just checked build and this is without this commit:

Memory region         Used Size  Region Size  %age Used
           flash:       62668 B        64 KB     95.62%
            sram:        3548 B         8 KB     43.31%

and this is with this commit:

Memory region         Used Size  Region Size  %age Used
           flash:       62664 B        64 KB     95.62%
            sram:        3548 B         8 KB     43.31%

That is what I expected to see. Pretty much the same size because the code for 64-bit float was just replaced with 128-bit float.

But once I pull the latest apps I have the same issue as reported by CI:

Memory region         Used Size  Region Size  %age Used
           flash:       65780 B        64 KB    100.37%
            sram:        3548 B         8 KB     43.31%

@Cynerd

Cynerd commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@xiaoxiang781216 I did apps bisect and funily enough it was your commit that tipped the scale apache/nuttx-apps@5ead824. hanzhijian's changes also added some space as it seems (flash: 64860 B 64 KB 98.97%).

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

@xiaoxiang781216 I did apps bisect and funily enough it was your commit that tipped the scale apache/nuttx-apps@5ead824. hanzhijian's changes also added some space as it seems (flash: 64860 B 64 KB 98.97%).

let' optimize the defconfig to reduce the code size.

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

@xiaoxiang781216 I did apps bisect and funily enough it was your commit that tipped the scale apache/nuttx-apps@5ead824. hanzhijian's changes also added some space as it seems (flash: 64860 B 64 KB 98.97%).

let' optimize the defconfig to reduce the code size.

fix here: #19247

This addresses "FIX ME" definitions for the long double. These might not
be all long double format supported by NuttX.

The support was also added only for GCC alike compilers. Other compilers
that have CONFIG_HAVE_LONG_DOUBLE defined will fail with error that
mantisage digits have to be defined for that compiler.

Signed-off-by: Karel Kočí <kkoci@elektroline.cz>
Cynerd added 2 commits July 1, 2026 21:43
NuttX defines constants for the sizes of types just as constants
directly in the code. The real values depend on compiler and target
platform. It is possible that value declared by NuttX header is wrong
compared to the compiler configuration. This is more likely in case of
floating points.

Not all compilers supported by NuttX provide required info through
defines and thus it is more generic to specify limits as constants, but
in case compiler provides them then it is a good idea to compare. This
commit adds such set of comparisons for limits.h and float.h constants.

The comparisons were tested with GCC and Clang. They will be ignored in
case compiler doesn't provide them.

Signed-off-by: Karel Kočí <kkoci@elektroline.cz>
This reuses implementation of trunc in case long double has same size as
double.

The previous implementation is used only in case x87 80-bit float point
is the long double. In other cases the logic is intentionally replaced
with panic to not provide a wrong result.

Signed-off-by: Karel Kočí <kkoci@elektroline.cz>
@Cynerd
Cynerd force-pushed the long-double-macros branch from 24b28a6 to 4e21440 Compare July 1, 2026 19:44
@acassis
acassis merged commit d61242c into apache:master Jul 2, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: OS Components OS Components issues Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants