2013-03-17 13:30:12 -05:00
|
|
|
module MacCPUs
|
|
|
|
OPTIMIZATION_FLAGS = {
|
|
|
|
:penryn => '-march=core2 -msse4.1',
|
|
|
|
:core2 => '-march=core2',
|
|
|
|
:core => '-march=prescott',
|
|
|
|
:g3 => '-mcpu=750',
|
|
|
|
:g4 => '-mcpu=7400',
|
|
|
|
:g4e => '-mcpu=7450',
|
|
|
|
:g5 => '-mcpu=970'
|
2013-06-13 11:57:13 -05:00
|
|
|
}.freeze
|
|
|
|
def optimization_flags; OPTIMIZATION_FLAGS; end
|
2013-03-17 13:30:12 -05:00
|
|
|
|
2013-03-10 17:33:06 +00:00
|
|
|
# These methods use info spewed out by sysctl.
|
|
|
|
# Look in <mach/machine.h> for decoding info.
|
2013-03-17 13:30:12 -05:00
|
|
|
def type
|
|
|
|
@type ||= `/usr/sbin/sysctl -n hw.cputype`.to_i
|
|
|
|
case @type
|
2013-03-10 17:33:06 +00:00
|
|
|
when 7
|
|
|
|
:intel
|
|
|
|
when 18
|
|
|
|
:ppc
|
|
|
|
else
|
|
|
|
:dunno
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-17 13:30:12 -05:00
|
|
|
def family
|
|
|
|
if type == :intel
|
|
|
|
@intel_family ||= `/usr/sbin/sysctl -n hw.cpufamily`.to_i
|
|
|
|
case @intel_family
|
|
|
|
when 0x73d67300 # Yonah: Core Solo/Duo
|
|
|
|
:core
|
|
|
|
when 0x426f69ef # Merom: Core 2 Duo
|
|
|
|
:core2
|
|
|
|
when 0x78ea4fbc # Penryn
|
|
|
|
:penryn
|
|
|
|
when 0x6b5a4cd2 # Nehalem
|
|
|
|
:nehalem
|
|
|
|
when 0x573B5EEC # Arrandale
|
|
|
|
:arrandale
|
|
|
|
when 0x5490B78C # Sandy Bridge
|
|
|
|
:sandybridge
|
|
|
|
when 0x1F65E835 # Ivy Bridge
|
|
|
|
:ivybridge
|
2013-07-01 00:44:54 -05:00
|
|
|
when 0x10B282DC # Haswell
|
|
|
|
:haswell
|
2013-03-17 13:30:12 -05:00
|
|
|
else
|
|
|
|
:dunno
|
|
|
|
end
|
|
|
|
elsif type == :ppc
|
|
|
|
@ppc_family ||= `/usr/sbin/sysctl -n hw.cpusubtype`.to_i
|
|
|
|
case @ppc_family
|
|
|
|
when 9
|
|
|
|
:g3 # PowerPC 750
|
|
|
|
when 10
|
|
|
|
:g4 # PowerPC 7400
|
|
|
|
when 11
|
|
|
|
:g4e # PowerPC 7450
|
|
|
|
when 100
|
|
|
|
:g5 # PowerPC 970
|
|
|
|
else
|
|
|
|
:dunno
|
|
|
|
end
|
2013-03-10 17:33:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-17 13:30:12 -05:00
|
|
|
def cores
|
|
|
|
@cores ||= `/usr/sbin/sysctl -n hw.ncpu`.to_i
|
|
|
|
end
|
|
|
|
|
|
|
|
def bits
|
|
|
|
return @bits if defined? @bits
|
|
|
|
|
|
|
|
is_64_bit = sysctl_bool("hw.cpu64bit_capable")
|
|
|
|
@bits ||= is_64_bit ? 64 : 32
|
|
|
|
end
|
|
|
|
|
|
|
|
def altivec?
|
|
|
|
type == :ppc && family != :g3
|
2013-03-10 17:33:06 +00:00
|
|
|
end
|
|
|
|
|
2013-04-07 12:47:40 -05:00
|
|
|
def avx?
|
|
|
|
pre_sandy = [:core, :core2, :penryn, :nehalem, :arrandale].include? family
|
|
|
|
type == :intel && !pre_sandy
|
|
|
|
end
|
|
|
|
|
2013-03-17 13:30:12 -05:00
|
|
|
def sse3?
|
|
|
|
type == :intel
|
2013-03-10 17:33:06 +00:00
|
|
|
end
|
|
|
|
|
2013-03-17 13:30:12 -05:00
|
|
|
def sse4?
|
|
|
|
type == :intel && (family != :core && family != :core2)
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2013-03-10 17:33:06 +00:00
|
|
|
def sysctl_bool(property)
|
|
|
|
result = nil
|
|
|
|
IO.popen("/usr/sbin/sysctl -n #{property} 2>/dev/null") do |f|
|
|
|
|
result = f.gets.to_i # should be 0 or 1
|
|
|
|
end
|
|
|
|
$?.success? && result == 1 # sysctl call succeded and printed 1
|
|
|
|
end
|
|
|
|
end
|