diff options
| author | Shaun Jackman | 2014-06-05 11:05:48 +0200 |
|---|---|---|
| committer | Mike McQuaid | 2014-06-06 19:47:16 +0100 |
| commit | 58fcfcbd2d48dcc111dc32ec3606b7ef23c636b8 (patch) | |
| tree | 53e4c5fb65f5035426b216673bc7b6bf2f19edef | |
| parent | fe64927596d54cead7d84ac3f54702d803145d78 (diff) | |
| download | homebrew-58fcfcbd2d48dcc111dc32ec3606b7ef23c636b8.tar.bz2 | |
Linuxbrew: Read CPU flags from /proc/cpuinfo
Closes #29895.
Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
| -rw-r--r-- | Library/Homebrew/os/linux/hardware.rb | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/Library/Homebrew/os/linux/hardware.rb b/Library/Homebrew/os/linux/hardware.rb index d30ea7968..84a13cc03 100644 --- a/Library/Homebrew/os/linux/hardware.rb +++ b/Library/Homebrew/os/linux/hardware.rb @@ -11,30 +11,37 @@ module LinuxCPUs def arch_64_bit; :x86_64; end def universal_archs; [].extend ArchitectureListExtension; end + def cpuinfo + @cpuinfo ||= File.read("/proc/cpuinfo") + end + def type - @cpu_type ||= case `uname -m` - when /i[3-6]86/, /x86_64/ - :intel - else - :dunno - end + @type ||= if cpuinfo =~ /Intel|AMD/ + :intel + else + :dunno + end end def family - :dunno + cpuinfo[/^cpu family\s*: ([0-9]+)/, 1].to_i end alias_method :intel_family, :family def cores - `grep -c ^processor /proc/cpuinfo`.to_i + cpuinfo.scan(/^processor/).size end - def bits - is_64_bit? ? 64 : 32 + def flags + @flags ||= cpuinfo[/^flags.*/, 0].split end - def is_64_bit? - return @is_64_bit if defined? @is_64_bit - @is_64_bit = /64/ === `uname -m` + %w[aes altivec avx avx2 lm sse3 ssse3 sse4 sse4_2].each { |flag| + define_method(flag + "?") { flags.include? flag } + } + alias_method :is_64_bit?, :lm? + + def bits + is_64_bit? ? 64 : 32 end end |
