Hardware: add new .features method

This returns a list of symbols with the various CPU features supported
by the active hardware.
This commit is contained in:
Misty De Meo 2014-06-21 21:57:03 -07:00
parent d9e73c9d43
commit 07660bb7b6
2 changed files with 12 additions and 0 deletions

View File

@ -36,6 +36,12 @@ module LinuxCPUs
@flags ||= cpuinfo[/^flags.*/, 0].split
end
# Compatibility with Mac method, which returns lowercase symbols
# instead of strings
def features
@features ||= flags[1..-1].map(&:intern)
end
%w[aes altivec avx avx2 lm sse3 ssse3 sse4 sse4_2].each { |flag|
define_method(flag + "?") { flags.include? flag }
}

View File

@ -98,6 +98,12 @@ module MacCPUs
end
end
def features
@features ||= `/usr/sbin/sysctl -n machdep.cpu.features`.split(" ").map do |s|
s.downcase.intern
end
end
def aes?
sysctl_bool('hw.optional.aes')
end