<commit_before># frozen_string_literal: true

module Hardware
  class CPU
    class << self
      native_arch = (ENV["HOMEBREW_ARCH"] || "native").freeze
      OPTIMIZATION_FLAGS_LINUX = {
        native:  "-march=#{native_arch}",
        nehalem: "-march=nehalem",
        core2:   "-march=core2",
        core:    "-march=prescott",
        armv6:   "-march=armv6",
        armv8:   "-march=armv8-a",
      }.freeze

      def optimization_flags
        OPTIMIZATION_FLAGS_LINUX
      end

      def cpuinfo
        @cpuinfo ||= File.read("/proc/cpuinfo")
      end

      def family
        return :arm if arm?
        return :ppc if ppc?
        return :dunno unless intel?

        # See https://software.intel.com/en-us/articles/intel-architecture-and-processor-identification-with-cpuid-model-and-family-numbers
        # and https://github.com/llvm-mirror/llvm/blob/master/lib/Support/Host.cpp
        # and https://en.wikipedia.org/wiki/List_of_Intel_CPU_microarchitectures#Roadmap
        cpu_family = cpuinfo[/^cpu family\s*: ([0-9]+)/, 1].to_i
        cpu_model = cpuinfo[/^model\s*: ([0-9]+)/, 1].to_i
        unknown = :"unknown_0x#{cpu_family.to_s(16)}_0x#{cpu_model.to_s(16)}"
        case cpu_family
        when 0x06
          case cpu_model
          when 0x3a, 0x3e
            :ivybridge
          when 0x2a, 0x2d
            :sandybridge
          when 0x25, 0x2c, 0x2f
            :westmere
          when 0x1e, 0x1a, 0x2e
            :nehalem
          when 0x17, 0x1d
            :penryn
          when 0x0f, 0x16
            :merom
          when 0x0d
            :dothan
          when 0x36, 0x26, 0x1c
            :atom
          when 0x3c, 0x3f, 0x46
            :haswell
          when 0x3d, 0x47, 0x4f, 0x56
            :broadwell
          when 0x4e, 0x55, 0x5e, 0x8e, 0x9e
            :skylake
          else
            unknown
          end
        when 0x0f
          case cpu_model
          when 0x06
            :presler<commit_msg>cpu: add new Intel names<commit_after># frozen_string_literal: true

module Hardware
  class CPU
    class << self
      native_arch = (ENV["HOMEBREW_ARCH"] || "native").freeze
      OPTIMIZATION_FLAGS_LINUX = {
        native:  "-march=#{native_arch}",
        nehalem: "-march=nehalem",
        core2:   "-march=core2",
        core:    "-march=prescott",
        armv6:   "-march=armv6",
        armv8:   "-march=armv8-a",
      }.freeze

      def optimization_flags
        OPTIMIZATION_FLAGS_LINUX
      end

      def cpuinfo
        @cpuinfo ||= File.read("/proc/cpuinfo")
      end

      def family
        return :arm if arm?
        return :ppc if ppc?
        return :dunno unless intel?

        # See https://software.intel.com/en-us/articles/intel-architecture-and-processor-identification-with-cpuid-model-and-family-numbers
        # and https://github.com/llvm-mirror/llvm/blob/master/lib/Support/Host.cpp
        # and https://en.wikipedia.org/wiki/List_of_Intel_CPU_microarchitectures#Roadmap
        cpu_family = cpuinfo[/^cpu family\s*: ([0-9]+)/, 1].to_i
        cpu_model = cpuinfo[/^model\s*: ([0-9]+)/, 1].to_i
        unknown = :"unknown_0x#{cpu_family.to_s(16)}_0x#{cpu_model.to_s(16)}"
        case cpu_family
        when 0x06
          case cpu_model
          when 0x3a, 0x3e
            :ivybridge
          when 0x2a, 0x2d
            :sandybridge
          when 0x25, 0x2c, 0x2f
            :westmere
          when 0x1e, 0x1a, 0x2e
            :nehalem
          when 0x17, 0x1d
            :penryn
          when 0x0f, 0x16
            :merom
          when 0x0d
            :dothan
          when 0x1c, 0x26, 0x27, 0x35, 0x36
            :atom
          when 0x3c, 0x3f, 0x45, 0x46
            :haswell
          when 0x3d, 0x47, 0x4f, 0x56
            :broadwell
          when 0x4e, 0x55, 0x5e, 0x8e, 0x9e
            :skylake
          when 0x66
            :cannonlake
          when 0x6a, 0x6c, 0x7d, 0x7e
            :icelake
          else
            unknown
          end
        when 0x0f
          case cpu_model
          when 0x06
            :presler
{'fraction_non_alphanumeric': 0.10235640648011782, 'fraction_numerical': 0.05154639175257732, 'mean_word_length': 1.6105060858424087, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6073758', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1443, 'n_words': 283}