在 2025-02-06 21:42, Martin Storsjö 写道:
Hmm, I'm not entirely sure here.For current implementations on mingw-w64 on UCRT, then yes, calling sin+cos separately is better than using sincos().I'm not really familiar with what the modern (non x87) implementations of sin/cos look like, but I would presume that it's possible to do sincos() faster than sin()+cos() separately still - if someone cares about that. E.g. on Linux platforms, GCC (and Clang) also still optimize separate calls into sincos(), and I would presume that what e.g. glibc provides is faster than two separate calls.Then again, as our target probably in general is to use more of the CRT and less of our own statically linked functions, and as the MS CRTs don't have sincos(), it's probably not plausible that we'll ever do that.But in any case - for UCRT, making Clang stop using sincos() wouldn't help all that much (we can still do what this patch does); for msvcrt.dll builds where we link in our x87 math, doing that would miss the possibly quicker sincos() implementation there.
The x87 FSINCOS instruction is slow because 1) it's implemented in microcode, and 2) it produces over-precise results in 64 bits then rounds them to 53 bits. A modern implementation with SSE, even with fewer registers than x86-64, is still faster.
On the aspect of an optimizer, I agree that it makes sense to assume `sincos()` should not be slower than a combination of `sin()` and `cos()`. If it's not the case then it's our bug and should be fixed.
-- Best regards, LIU Hao
OpenPGP_signature.asc
Description: OpenPGP digital signature
_______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public