Skip to content

Commit 0d9373c

Browse files
[TargetParser][AArch64] Split crypto feature detection into AES & SHA2
1 parent fcd62f6 commit 0d9373c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

llvm/lib/TargetParser/Host.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -1898,7 +1898,8 @@ const StringMap<bool> sys::getHostCPUFeatures() {
18981898
}
18991899

19001900
#if defined(__aarch64__)
1901-
// Keep track of which crypto features we have seen
1901+
// All of these are "crypto" features, but we must sift out actual features
1902+
// as the former meaning of "crypto" as a single feature is no more.
19021903
enum { CAP_AES = 0x1, CAP_PMULL = 0x2, CAP_SHA1 = 0x4, CAP_SHA2 = 0x8 };
19031904
uint32_t crypto = 0;
19041905
#endif
@@ -1944,7 +1945,10 @@ const StringMap<bool> sys::getHostCPUFeatures() {
19441945
// LLVM has decided some AArch64 CPUs have all the instructions they _may_
19451946
// have, as opposed to all the instructions they _must_ have, so allow runtime
19461947
// information to correct us on that.
1947-
Features["crypto"] = (crypto == (CAP_AES | CAP_PMULL | CAP_SHA1 | CAP_SHA2));
1948+
uint32_t Aes = CAP_AES | CAP_PMULL;
1949+
uint32_t Sha2 = CAP_SHA1 | CAP_SHA2;
1950+
Features["aes"] = (crypto & Aes) == Aes;
1951+
Features["sha2"] = (crypto & Sha2) == Sha2;
19481952
#endif
19491953

19501954
return Features;
@@ -1958,8 +1962,12 @@ const StringMap<bool> sys::getHostCPUFeatures() {
19581962
IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE);
19591963
Features["crc"] =
19601964
IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE);
1961-
Features["crypto"] =
1965+
1966+
// Avoid inferring "crypto" means more than the traditional AES + SHA2
1967+
bool TradCrypto =
19621968
IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE);
1969+
Features["aes"] = TradCrypto;
1970+
Features["sha2"] = TradCrypto;
19631971

19641972
return Features;
19651973
}

0 commit comments

Comments
 (0)