-
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
Merged
DanielKristofKiss
merged 9 commits into
llvm:main
from
DanielKristofKiss:compilrt-rt-win
Nov 13, 2024
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
889175d
Add cpu model init for Windows.
DanielKristofKiss ab19081
Add more features, refactor
DanielKristofKiss df55f29
clang-format
DanielKristofKiss eda3898
Address review comments
DanielKristofKiss 7670641
fix spelling
DanielKristofKiss 56ccce4
Use SDK values for even when they are not defined
DanielKristofKiss 6ee8463
Merge remote-tracking branch 'origin/main' into HEAD
DanielKristofKiss 8f784a5
address review comments
DanielKristofKiss 90ed73d
drop unused defines
DanielKristofKiss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
compiler-rt/lib/builtins/cpu_model/aarch64/fmv/windows.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| #define WIN32_LEAN_AND_MEAN | ||
| #include <windows.h> | ||
| #include <processthreadsapi.h> | ||
| #include <stdint.h> | ||
|
|
||
| #ifndef PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE | ||
| #define PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE 43 | ||
| #endif | ||
| #ifndef PF_ARM_V83_JSCVT_INSTRUCTIONS_AVAILABLE | ||
| #define PF_ARM_V83_JSCVT_INSTRUCTIONS_AVAILABLE 44 | ||
| #endif | ||
| #ifndef PF_ARM_V83_LRCPC_INSTRUCTIONS_AVAILABLE | ||
| #define PF_ARM_V83_LRCPC_INSTRUCTIONS_AVAILABLE 45 | ||
| #endif | ||
| #ifndef PF_ARM_SVE_INSTRUCTIONS_AVAILABLE | ||
| #define PF_ARM_SVE_INSTRUCTIONS_AVAILABLE 46 | ||
| #endif | ||
| #ifndef PF_ARM_SVE2_INSTRUCTIONS_AVAILABLE | ||
| #define PF_ARM_SVE2_INSTRUCTIONS_AVAILABLE 47 | ||
| #endif | ||
| #ifndef PF_ARM_SVE_AES_INSTRUCTIONS_AVAILABLE | ||
| #define PF_ARM_SVE_AES_INSTRUCTIONS_AVAILABLE 49 | ||
| #endif | ||
| #ifndef PF_ARM_SVE_PMULL128_INSTRUCTIONS_AVAILABLE | ||
| #define PF_ARM_SVE_PMULL128_INSTRUCTIONS_AVAILABLE 50 | ||
| #endif | ||
| #ifndef PF_ARM_SVE_BITPERM_INSTRUCTIONS_AVAILABLE | ||
| #define PF_ARM_SVE_BITPERM_INSTRUCTIONS_AVAILABLE 51 | ||
| #endif | ||
| #ifndef PF_ARM_SVE_BF16_INSTRUCTIONS_AVAILABLE | ||
| #define PF_ARM_SVE_BF16_INSTRUCTIONS_AVAILABLE 52 | ||
| #endif | ||
| #ifndef PF_ARM_SVE_EBF16_INSTRUCTIONS_AVAILABLE | ||
| #define PF_ARM_SVE_EBF16_INSTRUCTIONS_AVAILABLE 53 | ||
| #endif | ||
| #ifndef PF_ARM_SVE_SHA3_INSTRUCTIONS_AVAILABLE | ||
| #define PF_ARM_SVE_SHA3_INSTRUCTIONS_AVAILABLE 55 | ||
| #endif | ||
| #ifndef PF_ARM_SVE_SM4_INSTRUCTIONS_AVAILABLE | ||
| #define PF_ARM_SVE_SM4_INSTRUCTIONS_AVAILABLE 56 | ||
| #endif | ||
| #ifndef PF_ARM_SVE_I8MM_INSTRUCTIONS_AVAILABLE | ||
| #define PF_ARM_SVE_I8MM_INSTRUCTIONS_AVAILABLE 57 | ||
| #endif | ||
| #ifndef PF_ARM_SVE_F32MM_INSTRUCTIONS_AVAILABLE | ||
| #define PF_ARM_SVE_F32MM_INSTRUCTIONS_AVAILABLE 58 | ||
| #endif | ||
| #ifndef PF_ARM_SVE_F64MM_INSTRUCTIONS_AVAILABLE | ||
| #define PF_ARM_SVE_F64MM_INSTRUCTIONS_AVAILABLE 59 | ||
| #endif | ||
|
|
||
| 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_CRYPTO_INSTRUCTIONS_AVAILABLE)) { | ||
| setCPUFeature(FEAT_AES); | ||
| setCPUFeature(FEAT_SHA2); | ||
| setCPUFeature(FEAT_PMULL); | ||
| } | ||
|
|
||
| static const struct ProcessFeatureToFeatMap_t { | ||
| int WinApiFeature; | ||
| enum CPUFeatures CPUFeature; | ||
| } FeatMap[] = { | ||
| {PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE, FEAT_CRC}, | ||
| {PF_ARM_V81_ATOMIC_INSTRUCTIONS_AVAILABLE, FEAT_LSE}, | ||
| {PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE, FEAT_DOTPROD}, | ||
| {PF_ARM_V83_JSCVT_INSTRUCTIONS_AVAILABLE, FEAT_JSCVT}, | ||
| {PF_ARM_V83_LRCPC_INSTRUCTIONS_AVAILABLE, FEAT_RCPC}, | ||
| {PF_ARM_SVE_INSTRUCTIONS_AVAILABLE, FEAT_SVE}, | ||
| {PF_ARM_SVE2_INSTRUCTIONS_AVAILABLE, FEAT_SVE2}, | ||
| {PF_ARM_SVE_AES_INSTRUCTIONS_AVAILABLE, FEAT_SVE_AES}, | ||
labrinea marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| {PF_ARM_SVE_BF16_INSTRUCTIONS_AVAILABLE, FEAT_SVE_BF16}, | ||
| {PF_ARM_SVE_EBF16_INSTRUCTIONS_AVAILABLE, FEAT_SVE_EBF16}, | ||
DanielKristofKiss marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| {PF_ARM_SVE_SHA3_INSTRUCTIONS_AVAILABLE, FEAT_SVE_SHA3}, | ||
| {PF_ARM_SVE_SM4_INSTRUCTIONS_AVAILABLE, FEAT_SVE_SM4}, | ||
| {PF_ARM_SVE_F32MM_INSTRUCTIONS_AVAILABLE, FEAT_SVE_F32MM}, | ||
| {PF_ARM_SVE_F64MM_INSTRUCTIONS_AVAILABLE, FEAT_SVE_F64MM}, | ||
| }; | ||
|
|
||
| for (size_t I = 0, E = sizeof(FeatMap) / sizeof(FeatMap[0]); I != E; ++I) | ||
| if (IsProcessorFeaturePresent(FeatMap[I].WinApiFeature)) | ||
| setCPUFeature(FeatMap[I].CPUFeature); | ||
|
|
||
| __atomic_store(&__aarch64_cpu_features.features, &features, __ATOMIC_RELAXED); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 _WIN32 | ||
| // 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_PRIORITY 9 | ||
| #else | ||
| #define CONSTRUCTOR_PRIORITY 90 | ||
| #endif | ||
| #define CONSTRUCTOR_ATTRIBUTE __attribute__((constructor(CONSTRUCTOR_PRIORITY))) | ||
| #else | ||
| // FIXME: For MSVC, we should make a function pointer global in .CRT$X?? so that | ||
| // this runs during initialization. | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.