-
Notifications
You must be signed in to change notification settings - Fork 13.9k
[builtins][arm64] Implement __init_cpu_features_resolver on Apple platforms #75636
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
jroelofs
merged 16 commits into
main
from
users/jroelofs/spr/builtinsarm64-implement-__init_cpu_features_resolver-on-apple-platforms
Dec 19, 2023
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9abeecb
[𝘀𝗽𝗿] changes to main this commit is based on
jroelofs 7d00dcb
[𝘀𝗽𝗿] initial version
jroelofs a5126b2
[𝘀𝗽𝗿] changes introduced through rebase
jroelofs 0199cdc
fix budwq
jroelofs e25a473
[𝘀𝗽𝗿] changes introduced through rebase
jroelofs f04459f
rebase
jroelofs c6f2687
[𝘀𝗽𝗿] changes introduced through rebase
jroelofs 953802d
rebase
jroelofs 7201b09
[𝘀𝗽𝗿] changes introduced through rebase
jroelofs 8b7f086
rebase
jroelofs a430f9d
[𝘀𝗽𝗿] changes introduced through rebase
jroelofs c405058
rebase
jroelofs 4617179
[𝘀𝗽𝗿] changes introduced through rebase
jroelofs 9afe176
rebase
jroelofs 620c9a2
[𝘀𝗽𝗿] changes introduced through rebase
jroelofs d9e5376
rebase
jroelofs 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
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,69 @@ | ||
#include <TargetConditionals.h> | ||
#if TARGET_OS_OSX || TARGET_OS_IPHONE | ||
#include <dispatch/dispatch.h> | ||
#include <sys/sysctl.h> | ||
|
||
static bool isKnownAndSupported(const char *name) { | ||
int32_t val = 0; | ||
size_t size = sizeof(val); | ||
if (sysctlbyname(name, &val, &size, NULL, 0)) | ||
return false; | ||
return val; | ||
} | ||
|
||
void __init_cpu_features_resolver(void) { | ||
// On Darwin platforms, this may be called concurrently by multiple threads | ||
// because the resolvers that use it are called lazily at runtime (unlike on | ||
// ELF platforms, where IFuncs are resolved serially at load time). This | ||
// function's effect on __aarch64_cpu_features should be idempotent, but even | ||
// so we need dispatch_once to resolve the race condition. Dispatch is | ||
// available through libSystem, which we need anyway for the sysctl, so this | ||
// does not add a new dependency. | ||
|
||
static dispatch_once_t onceToken = 0; | ||
dispatch_once(&onceToken, ^{ | ||
// https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics | ||
static struct { | ||
const char *sysctl_name; | ||
enum CPUFeatures feature; | ||
} features[] = { | ||
{"hw.optional.arm.FEAT_FlagM", FEAT_FLAGM}, | ||
{"hw.optional.arm.FEAT_FlagM2", FEAT_FLAGM2}, | ||
{"hw.optional.arm.FEAT_FHM", FEAT_FP16FML}, | ||
{"hw.optional.arm.FEAT_DotProd", FEAT_DOTPROD}, | ||
{"hw.optional.arm.FEAT_RDM", FEAT_RDM}, | ||
{"hw.optional.arm.FEAT_LSE", FEAT_LSE}, | ||
{"hw.optional.floatingpoint", FEAT_FP}, | ||
{"hw.optional.AdvSIMD", FEAT_SIMD}, | ||
{"hw.optional.armv8_crc32", FEAT_CRC}, | ||
{"hw.optional.arm.FEAT_SHA1", FEAT_SHA1}, | ||
{"hw.optional.arm.FEAT_SHA256", FEAT_SHA2}, | ||
{"hw.optional.arm.FEAT_SHA3", FEAT_SHA3}, | ||
{"hw.optional.arm.FEAT_AES", FEAT_AES}, | ||
{"hw.optional.arm.FEAT_PMULL", FEAT_PMULL}, | ||
{"hw.optional.arm.FEAT_FP16", FEAT_FP16}, | ||
{"hw.optional.arm.FEAT_DIT", FEAT_DIT}, | ||
{"hw.optional.arm.FEAT_DPB", FEAT_DPB}, | ||
{"hw.optional.arm.FEAT_DPB2", FEAT_DPB2}, | ||
{"hw.optional.arm.FEAT_JSCVT", FEAT_JSCVT}, | ||
{"hw.optional.arm.FEAT_FCMA", FEAT_FCMA}, | ||
{"hw.optional.arm.FEAT_LRCPC", FEAT_RCPC}, | ||
{"hw.optional.arm.FEAT_LRCPC2", FEAT_RCPC2}, | ||
{"hw.optional.arm.FEAT_FRINTTS", FEAT_FRINTTS}, | ||
{"hw.optional.arm.FEAT_I8MM", FEAT_I8MM}, | ||
{"hw.optional.arm.FEAT_BF16", FEAT_BF16}, | ||
{"hw.optional.arm.FEAT_SB", FEAT_SB}, | ||
{"hw.optional.arm.FEAT_SPECRES", FEAT_PREDRES}, | ||
{"hw.optional.arm.FEAT_SSBS", FEAT_SSBS2}, | ||
{"hw.optional.arm.FEAT_BTI", FEAT_BTI}, | ||
}; | ||
|
||
for (size_t I = 0, E = sizeof(features) / sizeof(features[0]); I != E; ++I) | ||
if (isKnownAndSupported(features[I].sysctl_name)) | ||
__aarch64_cpu_features.features |= (1ULL << features[I].feature); | ||
|
||
__aarch64_cpu_features.features |= (1ULL << FEAT_INIT); | ||
}); | ||
} | ||
|
||
#endif // TARGET_OS_OSX || TARGET_OS_IPHONE |
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.
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.
Do you need support for AdvSIMD_HPFPCvt, FEAT_LSE2, FEAT_SHA512 or for other feature in Function Multi Versioning? Specification is not final yet and open to proposals.
Uh oh!
There was an error while loading. Please reload this page.
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.
Sure, I can add entries for those. Looks like I missed them in my manual intersection of the sysctl docs with theFEAT_*
table.edit: I see you're asking a different question than I thought. Yeah, those three would probably be useful.
Any word on when FMV might come out of beta?
Uh oh!
There was an error while loading. Please reload this page.
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.
Looks like we're just about out of bits in
__aarch64_cpu_features.features
.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.
Another thing that came up when discussing the frontend attributes for these: we may want to have user-selectable overrides for the priorities for (hypothetical) cases where the prescribed numbers in the table don't match the selection behavior we need at runtime. I don't have a concrete example in mind yet.
Uh oh!
There was an error while loading. Please reload this page.
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.
Next field features2 can be added to __aarch64_cpu_features with setting FEAT_EXT bit to 1 and changing initialization condition to if (__aarch64_cpu_features.features & (1ULL << FEAT_INIT) )
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.
There's no specific deadline right now, possibly within a year or half - we want to collect and address all feedback on FMV from partners and compilers communities.