clang-cl and _Interlocked* intrinsics

Hello,

I am working on porting CPython to build with clang-cl on Windows, since I expect things like labels as values and other optimizations could provide a significant speedup. I am currently running into a strange issue, and was directed here from IRC. When I have, for example,

#include <intrin.h>
#include <immintrin.h>

int main() {
_InterlockedCompareExchange64_HLEAcquire(4L, 5L, 6L);
}

building with cl is fine (minus obvious warnings about long to pointer conversion). However, if I build with clang-cl, I get “unresolved external symbol _InterlockedCompareExchange64_HLEAcquire referenced in function main”. When I build this in a Visual Studio solution I also get that _InterlockedCompareExchange64_HLEAcquire is implicitly declared, and the same link error.

Any advice on something I am doing wrong or ways to fix this would be appreciated. For the curious, full branch of CPython is https://github.com/ethanhs/cpython/tree/clang-cl . The usage of these intrinsics is in pyatomic.h.

Thanks so much!

Hi Ethan,

I am working on porting CPython to build with clang-cl on Windows, since I
expect things like labels as values and other optimizations could provide a
significant speedup. I am currently running into a strange issue, and was
directed here from IRC. When I have, for example,

#include <intrin.h>
#include <immintrin.h>

int main() {
    _InterlockedCompareExchange64_HLEAcquire(4L, 5L, 6L);
}

building with cl is fine (minus obvious warnings about long to pointer
conversion). However, if I build with clang-cl, I get "unresolved external
symbol _InterlockedCompareExchange64_HLEAcquire referenced in function
main". When I build this in a Visual Studio solution I also get that
_InterlockedCompareExchange64_HLEAcquire is implicitly declared, and the
same link error.

Any advice on something I am doing wrong or ways to fix this would be
appreciated. For the curious, full branch of CPython is
https://github.com/ethanhs/cpython/tree/clang-cl . The usage of these
intrinsics is in pyatomic.h.

You're not doing anything wrong. It's we who haven't implemented those
intrinsics yet.

If you want to work around this until we fix it, you can probably just
use the InterlockedCompareExchange variants without the _HLE* part in
pyatomic.h.

(And if you want to consider contributing a patch for this, it should
be fairly simple to add support based on grepping for
InterlockedCompareExchange64 :slight_smile:

Thanks,
Hans

For anyone following along, Ethan submitted a patch here:
https://reviews.llvm.org/D47672