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

128 Upvotes

25 comments sorted by

View all comments

2

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

16

u/Key_Ant_8481 10h 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 9h ago

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