brew/Library/Homebrew/hardware.rb

159 lines
2.9 KiB
Ruby
Raw Normal View History

2016-04-25 18:00:01 +01:00
module Hardware
class CPU
INTEL_32BIT_ARCHS = [:i386].freeze
INTEL_64BIT_ARCHS = [:x86_64].freeze
2018-04-14 03:01:33 +02:00
PPC_32BIT_ARCHS = [:ppc, :ppc32, :ppc7400, :ppc7450, :ppc970].freeze
PPC_64BIT_ARCHS = [:ppc64].freeze
2016-04-25 18:00:01 +01:00
class << self
OPTIMIZATION_FLAGS = {
native: "-march=native",
nehalem: "-march=nehalem",
core2: "-march=core2",
core: "-march=prescott",
armv6: "-march=armv6",
armv8: "-march=armv8-a",
}.freeze
def optimization_flags
OPTIMIZATION_FLAGS
end
def arch_32_bit
if arm?
:arm
elsif intel?
:i386
elsif ppc?
:ppc32
else
:dunno
end
end
def arch_64_bit
if arm?
:arm64
elsif intel?
:x86_64
elsif ppc?
:ppc64
else
:dunno
end
end
def arch
case bits
when 32
arch_32_bit
when 64
arch_64_bit
else
:dunno
end
end
def universal_archs
[arch].extend ArchitectureListExtension
end
2016-04-25 18:00:01 +01:00
def type
case RUBY_PLATFORM
when /x86_64/, /i\d86/ then :intel
2019-02-21 21:14:04 -08:00
when /arm/, /aarch64/ then :arm
when /ppc\d+/ then :ppc
else :dunno
end
2016-04-25 18:00:01 +01:00
end
2016-04-25 18:00:01 +01:00
def family
:dunno
end
2016-04-25 18:00:01 +01:00
def cores
return @cores if @cores
2018-09-17 02:45:00 +02:00
@cores = Utils.popen_read("getconf", "_NPROCESSORS_ONLN").chomp.to_i
@cores = 1 unless $CHILD_STATUS.success?
@cores
2016-04-25 18:00:01 +01:00
end
2016-04-25 18:00:01 +01:00
def bits
@bits ||= case RUBY_PLATFORM
when /x86_64/, /ppc64/, /aarch64|arm64/ then 64
when /i\d86/, /ppc/, /arm/ then 32
end
end
def sse4?
RUBY_PLATFORM.to_s.include?("x86_64")
2016-04-25 18:00:01 +01:00
end
2016-04-25 18:00:01 +01:00
def is_32_bit?
bits == 32
end
2016-04-25 18:00:01 +01:00
def is_64_bit?
bits == 64
end
2016-04-25 18:00:01 +01:00
def intel?
type == :intel
end
2016-04-25 18:00:01 +01:00
def ppc?
type == :ppc
end
def arm?
type == :arm
end
2016-04-25 18:00:01 +01:00
def features
[]
end
2015-02-23 21:38:36 -05:00
2016-04-25 18:00:01 +01:00
def feature?(name)
features.include?(name)
end
2015-02-23 21:38:36 -05:00
end
end
class << self
def cores_as_words
case Hardware::CPU.cores
when 1 then "single"
when 2 then "dual"
when 4 then "quad"
when 6 then "hexa"
when 8 then "octa"
when 12 then "dodeca"
2013-06-06 16:02:27 -05:00
else
Hardware::CPU.cores
2013-06-06 16:02:27 -05:00
end
end
def oldest_cpu(_version = nil)
if Hardware::CPU.intel?
if Hardware::CPU.is_64_bit?
:core2
else
:core
end
elsif Hardware::CPU.arm?
if Hardware::CPU.is_64_bit?
:armv8
else
:armv6
end
else
Hardware::CPU.family
end
2013-06-06 16:02:27 -05:00
end
alias generic_oldest_cpu oldest_cpu
2013-06-06 16:02:27 -05:00
end
end
2016-04-25 18:00:01 +01:00
require "extend/os/hardware"