| Summary: | Clang 11 fails to compile a CMake build with conflicting types for _m_prefetchw | ||
|---|---|---|---|
| Product: | SDL | Reporter: | vladius <vturbanov> |
| Component: | build | Assignee: | Sam Lantinga <slouken> |
| Status: | RESPONDED --- | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | ||
| Version: | HG 2.0 | ||
| Hardware: | x86_64 | ||
| OS: | Windows 10 | ||
| Attachments: |
Clang compilation on Windows with support for intrinsics
Use CPU id intrinsic in Clang Linker warning fix for Clang Compose using stringification when Clang is used |
||
|
Description
vladius
2021-02-09 12:11:15 UTC
In SDL_cpuinfo.h it seems like <intrin.h> is not included when __clang__ is defined, as the comment in the file explicitly reads: "Many of the intrinsics SDL uses are not implemented by clang with Visual Studio" However, the SDL_endian.h header does include <intrin.h> without any precautions like: >#ifdef _MSC_VER >#include <intrin.h> >#endif Maybe it should be changed to something like: >#ifdef _MSC_VER >#ifndef __clang__ >#include <intrin.h> >#endif >#endif Does this fix the bug? https://hg.libsdl.org/SDL/rev/d8f0192cb8a4 I've already tested the fix myself and apparently it introduces other errors like: >[build] ../src/libs/sdl/src/video/SDL_blit_A.c:594:5: error: use of undeclared identifier '__m64' >[build] __m64 src1, dst1, mm_alpha, mm_zero, mm_alpha2; Seems like the whole blitting functionality is highly dependent on those intrinsics. I have actually managed to compile in that scenario with adding one more #undef __SSE3__ to SDL_cpuinfo.h like so: >/* Many of the intrinsics SDL uses are not implemented by clang with Visual Studio */ >#undef __MMX__ >#undef __SSE__ >#undef __SSE2__ >#undef __SSE3__ It was a bit upsetting, however, that we miss so much optimization potential on a pretty common scenario of Clang + Windows. There are good news however is that I've managed to successfully Clang-compile and launch the test SDL application by simply renaming that pesky _m_prefetchw in the 'winnt.h' header. As of now it seems like the only conflicting intrinsic for my scenario and I suppose we could get rid of all of the #if !defined(__clang__) #include <intrin.h> Hurray! After some time and hiccups, I was now able to produce (compile) an SDL build with intrinsics included, including 3dNOW functionality. I'm now both in SDL_cpuinfo.h and SDL_endian.h is using a special code snippet, based on Clang's declaration of the needed '_m_prefetch' function. The snippet is enclosed in the same __PRFCHWINTRIN_H macro testing, so that the conflicting header won't be included and won't override the winnt.h's version of the '_m_prefetchw' declaration. That is of course a hack, but the current behavior is also quite hacky and disables the useful functionality which is quite bad. I will add a patch soon. Created attachment 4790 [details]
Clang compilation on Windows with support for intrinsics
This now makes it possible to compile SDL with Clang 11 under Windows 10, at least using the CMake pipeline (but possible even the classic way).
The intrinsics are now available and not turned off.
Created attachment 4794 [details]
Use CPU id intrinsic in Clang
With the help of the former patches, it is now possible to use intrinsics even in Clang. Thereby I have removed the additional check for __clang__. This patch also fixes at least one test (testmultiaudio.c) when compiled with Clang.
Created attachment 4796 [details]
Linker warning fix for Clang
Added one more patch for better Clang compatibility. The warning is generated if the linker is invoked with --no-undefined flag. The patches adds an additional condition to suppress that.
Created attachment 4797 [details]
Compose using stringification when Clang is used
Added a patch to stringify __FUNCTION__ under Windows, when using Clang.
|