-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[compiler-rt] Add cpu model init for Windows. #111961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
889175d
ab19081
df55f29
eda3898
7670641
56ccce4
6ee8463
8f784a5
90ed73d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #ifndef _ARM64_ | ||
| #define _ARM64_ | ||
| #endif | ||
| #include <processthreadsapi.h> | ||
| #include <stdint.h> | ||
|
|
||
| void __init_cpu_features_resolver(unsigned long hwcap, | ||
| const __ifunc_arg_t *arg) {} | ||
|
|
||
| void CONSTRUCTOR_ATTRIBUTE __init_cpu_features(void) { | ||
| if (__atomic_load_n(&__aarch64_cpu_features.features, __ATOMIC_RELAXED)) | ||
| return; | ||
|
|
||
| #define setCPUFeature(F) features |= 1ULL << F | ||
|
|
||
| uint64_t features = 0; | ||
|
|
||
| setCPUFeature(FEAT_INIT); | ||
| setCPUFeature(FEAT_FP); | ||
|
|
||
| // https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-isprocessorfeaturepresent | ||
| if (IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE)) | ||
| setCPUFeature(FEAT_CRC); | ||
| if (IsProcessorFeaturePresent(PF_ARM_V81_ATOMIC_INSTRUCTIONS_AVAILABLE)) | ||
| setCPUFeature(FEAT_LSE); | ||
| if (IsProcessorFeaturePresent(PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE)) | ||
| setCPUFeature(FEAT_DOTPROD); | ||
|
|
||
| if (IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE)) { | ||
| setCPUFeature(FEAT_AES); | ||
DanielKristofKiss marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| setCPUFeature(FEAT_SHA2); | ||
| setCPUFeature(FEAT_PMULL); | ||
| } | ||
| if (IsProcessorFeaturePresent(PF_ARM_V83_JSCVT_INSTRUCTIONS_AVAILABLE)) | ||
| setCPUFeature(FEAT_JSCVT); | ||
|
|
||
| if (IsProcessorFeaturePresent(PF_ARM_V83_LRCPC_INSTRUCTIONS_AVAILABLE)) | ||
| setCPUFeature(FEAT_RCPC); | ||
|
||
|
|
||
| __atomic_store(&__aarch64_cpu_features.features, &features, | ||
| __ATOMIC_RELAXED); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,15 @@ | |
| // We're choosing init priority 90 to force our constructors to run before any | ||
| // constructors in the end user application (starting at priority 101). This | ||
| // value matches the libgcc choice for the same functions. | ||
| #define CONSTRUCTOR_ATTRIBUTE __attribute__((constructor(90))) | ||
| #ifdef _WIN64 | ||
|
||
| // Contructor that replaces the ifunc runs currently with prio 10, see | ||
| // the LowerIFuncPass. The resolver of FMV depends on the cpu features so set | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wondered what this was about, if it was some feature in the compiler I was unaware of - but then I saw the other PR filed at the same time :-) |
||
| // the priority to 9. | ||
| #define CONSTRUCTOR_PRIOTITY 9 | ||
DanielKristofKiss marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #else | ||
| #define CONSTRUCTOR_PRIOTITY 90 | ||
| #endif | ||
| #define CONSTRUCTOR_ATTRIBUTE __attribute__((constructor(CONSTRUCTOR_PRIOTITY))) | ||
| #else | ||
| // FIXME: For MSVC, we should make a function pointer global in .CRT$X?? so that | ||
| // this runs during initialization. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this define here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
winnt.h complains about it if not defined and clang doesn't define it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's interesting - I would generally expect it to work to include those headers as is, with the compiler default defines.
Can you boil that down to a standalone repro, with a file that just includes
<windows.h>or similar (I guess the relevant one here is<processthreadsapi.h>)? Or is the case that<processthreadsapi.h>is one of the Windows headers that you can't include directly unless you've included<windows.h>first? In that case, I'd prefer including that first, rather than adding our own extra defines. (If you want to, you can defineWIN32_LEAN_AND_MEANto reduce the overhead of including the whole<windows.h>.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
windows.hdefines it so let's do that.