aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/os/linux
diff options
context:
space:
mode:
authorShaun Jackman2014-06-05 11:05:48 +0200
committerMike McQuaid2014-06-06 19:47:16 +0100
commit94a0b26fec3e640bc7f0d132a4bd36c2507f3fc8 (patch)
tree9340d2a6c99666d6efdd6f40ec2268dec90f7cc0 /Library/Homebrew/os/linux
parent98e5bd8198cc3ac42173eb755b0780e477e36a1c (diff)
downloadbrew-94a0b26fec3e640bc7f0d132a4bd36c2507f3fc8.tar.bz2
Linuxbrew: Read CPU flags from /proc/cpuinfo
Closes Homebrew/homebrew#29895. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
Diffstat (limited to 'Library/Homebrew/os/linux')
-rw-r--r--Library/Homebrew/os/linux/hardware.rb33
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