Class: Hardware::CPU Private
- Defined in:
- hardware.rb,
extend/os/mac/hardware/cpu/hardware.rb
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Helper module for querying CPU information.
Constant Summary collapse
- INTEL_32BIT_ARCHS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
[:i386].freeze
- INTEL_64BIT_ARCHS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
[:x86_64].freeze
- INTEL_ARCHS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
T.let((INTEL_32BIT_ARCHS + INTEL_64BIT_ARCHS).freeze, T::Array[Symbol])
- PPC_32BIT_ARCHS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
[:ppc, :ppc32, :ppc7400, :ppc7450, :ppc970].freeze
- PPC_64BIT_ARCHS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
[:ppc64, :ppc64le, :ppc970].freeze
- PPC_ARCHS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
T.let((PPC_32BIT_ARCHS + PPC_64BIT_ARCHS).freeze, T::Array[Symbol])
- ARM_64BIT_ARCHS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
[:arm64, :aarch64].freeze
- ARM_ARCHS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
ARM_64BIT_ARCHS- ALL_ARCHS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
T.let([ *INTEL_ARCHS, *PPC_ARCHS, *ARM_ARCHS, ].freeze, T::Array[Symbol])
- INTEL_64BIT_OLDEST_CPU =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
:core2- ROSETTA_RUNTIME_PATH =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
"/Library/Apple/usr/libexec/oah/libRosettaRuntime"
Class Method Summary collapse
- .aes? ⇒ Boolean private
- .altivec? ⇒ Boolean private
- .arch ⇒ Symbol private
- .arch_32_bit ⇒ Symbol private
- .arch_64_bit ⇒ Symbol private
- .arch_flag(arch) ⇒ String private
-
.arm64? ⇒ Boolean
private
Check whether the CPU architecture is 64-bit ARM.
-
.arm? ⇒ Boolean
internal
Check whether the CPU architecture is ARM.
- .arm_family ⇒ Symbol private
- .avx2? ⇒ Boolean private
- .avx? ⇒ Boolean private
- .big_endian? ⇒ Boolean private
- .bits ⇒ Integer? private
- .cores ⇒ Integer private
- .extmodel ⇒ Integer private
- .family ⇒ Symbol private
- .feature?(name) ⇒ Boolean private
- .features ⇒ Array<Symbol> private
- .in_rosetta2? ⇒ Boolean private
- .intel? ⇒ Boolean private
- .intel_family(_family = T.unsafe(nil), _cpu_model = T.unsafe(nil)) ⇒ Symbol private
- .is_32_bit? ⇒ Boolean private
- .is_64_bit? ⇒ Boolean private
- .little_endian? ⇒ Boolean private
- .optimization_flags ⇒ Hash{Symbol => String} private
- .physical_cpu_arm64? ⇒ Boolean private
- .ppc32? ⇒ Boolean private
- .ppc64? ⇒ Boolean private
- .ppc64le? ⇒ Boolean private
- .ppc? ⇒ Boolean private
- .rosetta_installed? ⇒ Boolean private
- .sse3? ⇒ Boolean private
- .sse4? ⇒ Boolean private
- .sse4_2? ⇒ Boolean private
- .ssse3? ⇒ Boolean private
- .sysctl_bool!(key) ⇒ Boolean private
- .sysctl_int(key) ⇒ Integer private
- .sysctl_n(*keys) ⇒ String private
- .type ⇒ Symbol private
- .virtualized? ⇒ Boolean private
Class Method Details
.aes? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
13 14 15 |
# File 'extend/os/mac/hardware/cpu/hardware.rb', line 13 def aes? sysctl_bool!("hw.optional.aes") end |
.altivec? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
18 19 20 |
# File 'extend/os/mac/hardware/cpu/hardware.rb', line 18 def altivec? sysctl_bool!("hw.optional.altivec") end |
.arch ⇒ Symbol
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
76 77 78 79 80 81 82 83 84 85 |
# File 'hardware.rb', line 76 def arch case bits when 32 arch_32_bit when 64 arch_64_bit else :dunno end end |
.arch_32_bit ⇒ Symbol
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'hardware.rb', line 48 def arch_32_bit if arm? :arm elsif intel? :i386 elsif ppc32? :ppc32 else :dunno end end |
.arch_64_bit ⇒ Symbol
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'hardware.rb', line 61 def arch_64_bit if arm? :arm64 elsif intel? :x86_64 elsif ppc64le? :ppc64le elsif ppc64? :ppc64 else :dunno end end |
.arch_flag(arch) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
201 202 203 204 205 |
# File 'hardware.rb', line 201 def arch_flag(arch) return "-mcpu=#{arch}" if ppc? "-march=#{arch}" end |
.arm64? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Check whether the CPU architecture is 64-bit ARM.
171 172 173 |
# File 'hardware.rb', line 171 def arm64? arm? && is_64_bit? end |
.arm? ⇒ Boolean
This method is part of an internal API. This method may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Check whether the CPU architecture is ARM.
165 166 167 |
# File 'hardware.rb', line 165 def arm? type == :arm end |
.arm_family ⇒ Symbol
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'extend/os/mac/hardware/cpu/hardware.rb', line 60 def arm_family case sysctl_int("hw.cpufamily") when 0x2c91a47e # ARMv8.0-A (Typhoon) :arm_typhoon when 0x92fb37c8 # ARMv8.0-A (Twister) :arm_twister when 0x67ceee93 # ARMv8.1-A (Hurricane, Zephyr) :arm_hurricane_zephyr when 0xe81e7ef6 # ARMv8.2-A (Monsoon, Mistral) :arm_monsoon_mistral when 0x07d34b9f # ARMv8.3-A (Vortex, Tempest) :arm_vortex_tempest when 0x462504d2 # ARMv8.4-A (Lightning, Thunder) :arm_lightning_thunder when 0x573b5eec, 0x1b588bb3 # ARMv8.4-A (Firestorm, Icestorm) :arm_firestorm_icestorm when 0xda33d83d # ARMv8.5-A (Blizzard, Avalanche) :arm_blizzard_avalanche when 0xfa33415e # ARMv8.6-A (M3, Ibiza) :arm_ibiza when 0x5f4dea93 # ARMv8.6-A (M3 Pro, Lobos) :arm_lobos when 0x72015832 # ARMv8.6-A (M3 Max, Palma) :arm_palma when 0x6f5129ac # ARMv9.2-A (M4, Donan) :arm_donan when 0x17d5b93a # ARMv9.2-A (M4 Pro / M4 Max, Brava) :arm_brava when 0x1d5a87e8 # ARMv9.2-A (M5, Hidra) :arm_hidra when 0xf76c5b1a # ARMv9.2-A (M5 Pro / M5 Max, Sotra) :arm_sotra else # When adding new ARM CPU families, please also update # test/hardware/cpu_spec.rb to include the new families. :dunno end end |
.avx2? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
28 29 30 |
# File 'extend/os/mac/hardware/cpu/hardware.rb', line 28 def avx2? sysctl_bool!("hw.optional.avx2_0") end |
.avx? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
23 24 25 |
# File 'extend/os/mac/hardware/cpu/hardware.rb', line 23 def avx? sysctl_bool!("hw.optional.avx1_0") end |
.big_endian? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
181 182 183 |
# File 'hardware.rb', line 181 def big_endian? [1].pack("I") == [1].pack("N") end |
.bits ⇒ Integer?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
114 115 116 117 118 119 |
# File 'hardware.rb', line 114 def bits @bits ||= T.let(case RUBY_PLATFORM when /x86_64/, /ppc64|powerpc64/, /aarch64|arm64/ then 64 when /i\d86/, /ppc/, /arm/ then 32 end, T.nilable(Integer)) end |
.cores ⇒ Integer
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
103 104 105 106 107 108 109 110 111 |
# File 'hardware.rb', line 103 def cores @cores ||= T.let( begin cores = Utils.popen_read("getconf", "_NPROCESSORS_ONLN").chomp.to_i $CHILD_STATUS.success? ? cores : 1 end, T.nilable(Integer), ) end |
.extmodel ⇒ Integer
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
8 9 10 |
# File 'extend/os/mac/hardware/cpu/hardware.rb', line 8 def extmodel sysctl_int("machdep.cpu.extmodel") end |
.family ⇒ Symbol
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
98 99 100 |
# File 'hardware.rb', line 98 def family :dunno end |
.feature?(name) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
196 197 198 |
# File 'hardware.rb', line 196 def feature?(name) features.include?(name) end |
.features ⇒ Array<Symbol>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
191 192 193 |
# File 'hardware.rb', line 191 def features [] end |
.in_rosetta2? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
208 209 210 |
# File 'hardware.rb', line 208 def in_rosetta2? false end |
.intel? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
137 138 139 |
# File 'hardware.rb', line 137 def intel? type == :intel end |
.intel_family(_family = T.unsafe(nil), _cpu_model = T.unsafe(nil)) ⇒ Symbol
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'extend/os/mac/hardware/cpu/hardware.rb', line 100 def intel_family(_family = T.unsafe(nil), _cpu_model = T.unsafe(nil)) case sysctl_int("hw.cpufamily") when 0x73d67300 # Yonah: Core Solo/Duo :core when 0x426f69ef # Merom: Core 2 Duo :core2 when 0x78ea4fbc # Penryn :penryn when 0x6b5a4cd2 # Nehalem :nehalem when 0x573b5eec # Westmere :westmere when 0x5490b78c # Sandy Bridge :sandybridge when 0x1f65e835 # Ivy Bridge :ivybridge when 0x10b282dc # Haswell :haswell when 0x582ed09c # Broadwell :broadwell when 0x37fc219f # Skylake :skylake when 0x0f817246 # Kaby Lake :kabylake when 0x38435547 # Ice Lake :icelake when 0x1cf8a03e # Comet Lake :cometlake else :dunno end end |
.is_32_bit? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
127 128 129 |
# File 'hardware.rb', line 127 def is_32_bit? bits == 32 end |
.is_64_bit? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
132 133 134 |
# File 'hardware.rb', line 132 def is_64_bit? bits == 64 end |
.little_endian? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
176 177 178 |
# File 'hardware.rb', line 176 def little_endian? !big_endian? end |
.optimization_flags ⇒ Hash{Symbol => String}
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'hardware.rb', line 29 def optimization_flags @optimization_flags ||= T.let({ dunno: "", native: arch_flag("native"), ivybridge: "-march=ivybridge", sandybridge: "-march=sandybridge", westmere: "-march=westmere", nehalem: "-march=nehalem", core2: "-march=core2", core: "-march=prescott", arm_vortex_tempest: "", # TODO: -mcpu=apple-m1 when we've patched all our GCCs to support it armv6: "-march=armv6", armv8: "-march=armv8-a", ppc64: "-mcpu=powerpc64", ppc64le: "-mcpu=powerpc64le", }.freeze, T.nilable(T::Hash[Symbol, String])) end |
.physical_cpu_arm64? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This is more reliable than checking uname. sysctl returns
the right answer even when running in Rosetta 2.
50 51 52 |
# File 'extend/os/mac/hardware/cpu/hardware.rb', line 50 def physical_cpu_arm64? sysctl_bool!("hw.optional.arm64") end |
.ppc32? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
147 148 149 |
# File 'hardware.rb', line 147 def ppc32? ppc? && is_32_bit? end |
.ppc64? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
157 158 159 |
# File 'hardware.rb', line 157 def ppc64? ppc? && is_64_bit? && big_endian? end |
.ppc64le? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
152 153 154 |
# File 'hardware.rb', line 152 def ppc64le? ppc? && is_64_bit? && little_endian? end |
.ppc? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
142 143 144 |
# File 'hardware.rb', line 142 def ppc? type == :ppc end |
.rosetta_installed? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
213 214 215 |
# File 'hardware.rb', line 213 def rosetta_installed? false end |
.sse3? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
33 34 35 |
# File 'extend/os/mac/hardware/cpu/hardware.rb', line 33 def sse3? sysctl_bool!("hw.optional.sse3") end |
.sse4? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
122 123 124 |
# File 'hardware.rb', line 122 def sse4? RUBY_PLATFORM.to_s.include?("x86_64") end |
.sse4_2? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
43 44 45 |
# File 'extend/os/mac/hardware/cpu/hardware.rb', line 43 def sse4_2? sysctl_bool!("hw.optional.sse4_2") end |
.ssse3? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
38 39 40 |
# File 'extend/os/mac/hardware/cpu/hardware.rb', line 38 def ssse3? sysctl_bool!("hw.optional.supplementalsse3") end |
.sysctl_bool!(key) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
134 135 136 |
# File 'extend/os/mac/hardware/cpu/hardware.rb', line 134 def sysctl_bool!(key) sysctl_int(key) == 1 end |
.sysctl_int(key) ⇒ Integer
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
139 140 141 |
# File 'extend/os/mac/hardware/cpu/hardware.rb', line 139 def sysctl_int(key) sysctl_n(key).to_i & 0xffffffff end |
.sysctl_n(*keys) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
144 145 146 147 148 |
# File 'extend/os/mac/hardware/cpu/hardware.rb', line 144 def sysctl_n(*keys) (@properties ||= T.let({}, T.nilable(T::Hash[T::Array[String], String]))).fetch(keys) do @properties[keys] = Utils.popen_read("/usr/sbin/sysctl", "-n", *keys) end end |
.type ⇒ Symbol
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
88 89 90 91 92 93 94 95 |
# File 'hardware.rb', line 88 def type case RUBY_PLATFORM when /x86_64/, /i\d86/ then :intel when /arm/, /aarch64/ then :arm when /ppc|powerpc/ then :ppc else :dunno end end |
.virtualized? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
55 56 57 |
# File 'extend/os/mac/hardware/cpu/hardware.rb', line 55 def virtualized? sysctl_bool!("kern.hv_vmm_present") end |