This is an archive of the discontinued LLVM Phabricator instance.

[X86] Make _xgetbv/_xsetbv on non-windows platforms
ClosedPublic

Authored by craig.topper on Jan 14 2019, 3:58 PM.

Details

Summary

This patch attempts to redo what was tried in r278783, but was reverted.

These intrinsics should be available on non-windows platforms with "xsave" feature check. But on Windows platforms they shouldn't have feature check since that's how MSVC behaves.

To accomplish this I've added a MS builtin with no feature check. And a normal gcc builtin with a feature check. When _MSC_VER is not defined _xgetbv/_xsetbv will be macros pointing to the gcc builtin name.

I've moved the forward declarations from intrin.h to immintrin.h to match the MSDN documentation and used that as the header file for the MS builtin.

I'm not super happy with this implementation, and I'm open to suggestions for better ways to do it.

Diff Detail

Repository
rC Clang

Event Timeline

craig.topper created this revision.Jan 14 2019, 3:58 PM
rnk added inline comments.Jan 14 2019, 4:18 PM
lib/Headers/immintrin.h
381–394

I think we should try to simplify immintrin.h and push this complexity into xsaveintrin.h. Since it is small (i.e. not avx512intrin.h), we don't really need this !defined(_MSC_VER) || __has_feature(modules) check to improve compile time. If you rewrite it to:

#if defined(_MSC_VER) || defined(__XSAVE__)
#include <xsaveintrin.h>
#endif

Then xsaveintrin.h can do the XSAVE macro feature check internally.

test/Headers/ms-intrin.cpp
37

Surely __movsb and __readmsr should all be x86-only as well, at least according to MSDN?

Remove guard from include of xsaveintrin.h. We can't have any check because we need it to always include on non-windows platforms due to target attribute.

craig.topper marked an inline comment as done.Jan 14 2019, 5:05 PM
craig.topper added inline comments.
test/Headers/ms-intrin.cpp
37

I'm sure that's true, but I think thats a separate issue with the forward declarations in intrin.h

rnk accepted this revision.Jan 14 2019, 5:35 PM

lgtm

This revision is now accepted and ready to land.Jan 14 2019, 5:35 PM
This revision was automatically updated to reflect the committed changes.