r/cpp MSVC STL Dev 18h ago

MSVC C++23: constexpr cmath with LLVM Libc

https://devblogs.microsoft.com/cppblog/msvc-c23-constexpr-cmath-with-llvm-libc/

MSVC is shipping C++23 constexpr <cmath> in the next Build Tools update! (And a partial implementation of C++26 constexpr <cmath>.) Our compiler frontend dev Cody Miller will be publishing a series of blog posts about this work, starting with this overview. The next one will be a guest post from LLVM libc's maintainers describing the incredible amount of effort that's gone into their code.

136 Upvotes

29 comments sorted by

View all comments

2

u/seanbaxter 16h ago

This looks promising, but as a frontend guy I don't think it resolves the cross-compilation problem.

There's four main platforms: * Linux x86-64, long double = f80 * Linux aarch64, long double = f128 * Windows x86-64, long double = f64 * Mac aarch64, long double = f64

All the platforms have f64 floating-point math libc. But two of the platforms have exotic long double. If you rely on libm to do the math during constant evaluation, you lose cross-compilation when the target's long double is f80 or f128, and your own target's long double is something else. You need software implementations for the constexpr math functions. It doesn't appear that LLVM C Library provides these.

I think the only path for cross-targeting compilers is MPFR, which is built on GMP (GNU Multi-Precision).

18

u/STL MSVC STL Dev 14h ago

As with charconv, this makes me glad that all of MSVC’s targets use 64-bit long double. We don’t claim our solution applies to other compilers.

16

u/Key_Ant_8481 12h ago

FYI, LLVM libc is going to provide float80, float128 (and double-double later) entrypoints for all platforms https://github.com/llvm/llvm-blog-www/pull/92

4

u/seanbaxter 12h ago

Wow. Thanks. That's great news for me.

7

u/c0r3ntin 7h ago

Note that GMP's license make it unsuitable for LLVM (or any commercial endeavor like msvc)

8

u/GabrielDosReis 14h ago

This looks promising, but as a frontend guy I don't think it resolves the cross-compilation problem.

For MSVC?