Skip to content

Commit d94c647

Browse files
committed
[CPUID] Simplify collection of full set of features for architecture
1 parent 2703058 commit d94c647

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

base/cpuid.jl

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,20 @@ function normalize_arch(arch::String)
8989
return arch
9090
end
9191

92-
const ALL_FEATURES = let
93-
get_features(prefix::String) =
94-
getfield.(Ref(@__MODULE__), filter(n -> startswith(String(n), prefix), (names(@__MODULE__; all=true))))
95-
Dict(
96-
"i686" => get_features("JL_X86"),
97-
"x86_64" => get_features("JL_X86"),
98-
"armv6l" => get_features("JL_AArch32"),
99-
"armv7l" => get_features("JL_AArch32"),
100-
"aarch64" => get_features("JL_AArch64"),
101-
"powerpc64le" => UInt32[],
102-
)
103-
end
92+
let
93+
# Collect all relevant features for the current architecture, if any.
94+
FEATURES = UInt32[]
95+
arch = normalize_arch(String(Sys.ARCH))
96+
if arch in keys(ISAs_by_family)
97+
for isa in ISAs_by_family[arch]
98+
unique!(append!(FEATURES, last(isa).features))
99+
end
100+
end
104101

105-
# Use `@eval` to statically determine the list of features for the current architecture.
106-
@eval function cpu_isa()
107-
return ISA(Set{UInt32}(feat for feat in $(ALL_FEATURES[normalize_arch(String(Sys.ARCH))]) if test_cpu_feature(feat)))
102+
# Use `@eval` to inline the list of features.
103+
@eval function cpu_isa()
104+
return ISA(Set{UInt32}(feat for feat in $(FEATURES) if test_cpu_feature(feat)))
105+
end
108106
end
109107

110108
"""

0 commit comments

Comments
 (0)