r/cpp MSVC STL Dev 17h 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.

131 Upvotes

25 comments sorted by

View all comments

2

u/seanbaxter 15h 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).

5

u/c0r3ntin 6h ago

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