[PATCH] D115441: [X86][MS] Add 80bit long double support for Windows

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 12 13:15:29 PST 2021


mstorsjo added a comment.

In D115441#3187009 <https://reviews.llvm.org/D115441#3187009>, @rnk wrote:

> I seem to recall assuming that Windows `long double` was 64-bits in many, many places. Unfortunately, I have no idea where that could've happened.

Nothing comes to mind for me about that - in _most_ cases, Windows is kinda oblivious to `long double`, as nothing in Windows public API uses that type.

However outside of the core OS, any function in the CRT, that uses long doubles, is going to be wrong; in the C99 runtime, there's plenty of `long double` functions - a separate `-l` suffixed version of most math functions, but also more important conversion functions like `strtold`.

> Something that comes to mind immediately is the MSVC name mangler. I don't think that's a blocking issue, but it's something you should be aware of if you want to promote this flag's usage.

Oh, right, I have no familiarity with those aspects and what might break there.

> @mstorsjo, can you advise what GCC does here? I've forgotten how this is supposed to work.

In GCC on Windows (and clang in mingw mode), `long double` is always 80 bit on x86. (On i386, `sizeof(long double) == 12`, while on x86_64 it's 16.)

Regarding the initial FPU state, I think the statically linked CRT startup bits differ from MSVC in this aspect, so the x87 state is initialized in 80 bit mode.

Then for runtime functions, mingw handles this by providing their own (statically linked) reimplementation of essentially all functions that touch long doubles. For math and similar, it's pretty straightforward, but for printf, it's a bit of a mess since we'd otherwise want to use UCRT's (otherwise standards compliant) printfs, but whenever long doubles are involved (very rarely in practice, but libc++'s testsuite do exercise them) the mingw provided version has to be used.

For mingw on arm (32 and 64) I haven't wanted to introduce any further deviance from MSVC, so there it's all identical to plain double.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115441/new/

https://reviews.llvm.org/D115441



More information about the llvm-commits mailing list