blob: 0c809f00c8b98023a339242200114c9b2c28efd2 [file] [log] [blame]
dalecurtis@chromium.orgaa3c6d32012-06-12 17:29:32 +09001// Copyright (c) 2012 The Chromium Authors. All rights reserved.
maruel@google.com8178de22008-09-26 07:08:44 +09002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef BASE_CPU_H_
6#define BASE_CPU_H_
7
8#include <string>
9
darin@chromium.orge585bed2011-08-06 00:34:00 +090010#include "base/base_export.h"
rvargas@google.com4891e7d2011-03-26 03:46:38 +090011
maruel@google.com8178de22008-09-26 07:08:44 +090012namespace base {
13
14// Query information about the processor.
darin@chromium.orge585bed2011-08-06 00:34:00 +090015class BASE_EXPORT CPU {
maruel@google.com8178de22008-09-26 07:08:44 +090016 public:
17 // Constructor
18 CPU();
19
whunt@chromium.orga5dbde42013-02-02 10:10:02 +090020 enum IntelMicroArchitecture {
21 PENTIUM,
22 SSE,
23 SSE2,
24 SSE3,
25 SSSE3,
26 SSE41,
27 SSE42,
28 AVX,
29 MAX_INTEL_MICRO_ARCHITECTURE
30 };
31
maruel@google.com8178de22008-09-26 07:08:44 +090032 // Accessors for CPU information.
33 const std::string& vendor_name() const { return cpu_vendor_; }
simonjam@chromium.org7bf2f7b2013-07-18 20:13:28 +090034 int signature() const { return signature_; }
maruel@google.com8178de22008-09-26 07:08:44 +090035 int stepping() const { return stepping_; }
36 int model() const { return model_; }
37 int family() const { return family_; }
38 int type() const { return type_; }
39 int extended_model() const { return ext_model_; }
40 int extended_family() const { return ext_family_; }
dalecurtis@chromium.orgaa3c6d32012-06-12 17:29:32 +090041 bool has_mmx() const { return has_mmx_; }
42 bool has_sse() const { return has_sse_; }
43 bool has_sse2() const { return has_sse2_; }
44 bool has_sse3() const { return has_sse3_; }
45 bool has_ssse3() const { return has_ssse3_; }
46 bool has_sse41() const { return has_sse41_; }
47 bool has_sse42() const { return has_sse42_; }
whunt@chromium.orga5dbde42013-02-02 10:10:02 +090048 bool has_avx() const { return has_avx_; }
agl@chromium.orga3f13f52013-11-23 03:35:03 +090049 // has_avx_hardware returns true when AVX is present in the CPU. This might
50 // differ from the value of |has_avx()| because |has_avx()| also tests for
51 // operating system support needed to actually call AVX instuctions.
52 // Note: you should never need to call this function. It was added in order
53 // to workaround a bug in NSS but |has_avx()| is what you want.
54 bool has_avx_hardware() const { return has_avx_hardware_; }
agl@chromium.orgabda8512013-12-03 01:15:03 +090055 bool has_aesni() const { return has_aesni_; }
simonjam@chromium.orge50c7cb2013-05-01 04:46:05 +090056 bool has_non_stop_time_stamp_counter() const {
57 return has_non_stop_time_stamp_counter_;
58 }
agl@chromium.org41be0792014-08-08 17:45:24 +090059 // has_broken_neon is only valid on ARM chips. If true, it indicates that we
60 // believe that the NEON unit on the current CPU is flawed and cannot execute
61 // some code. See https://code.google.com/p/chromium/issues/detail?id=341598
62 bool has_broken_neon() const { return has_broken_neon_; }
63
whunt@chromium.orga5dbde42013-02-02 10:10:02 +090064 IntelMicroArchitecture GetIntelMicroArchitecture() const;
chunyang.dai@intel.com94d8f282012-10-05 06:05:23 +090065 const std::string& cpu_brand() const { return cpu_brand_; }
maruel@google.com8178de22008-09-26 07:08:44 +090066
67 private:
68 // Query the processor for CPUID information.
69 void Initialize();
70
simonjam@chromium.org7bf2f7b2013-07-18 20:13:28 +090071 int signature_; // raw form of type, family, model, and stepping
maruel@google.com8178de22008-09-26 07:08:44 +090072 int type_; // process type
73 int family_; // family of the processor
74 int model_; // model of processor
75 int stepping_; // processor revision number
76 int ext_model_;
77 int ext_family_;
jiesun@chromium.orgc8420402011-02-17 03:51:58 +090078 bool has_mmx_;
79 bool has_sse_;
80 bool has_sse2_;
81 bool has_sse3_;
82 bool has_ssse3_;
83 bool has_sse41_;
84 bool has_sse42_;
whunt@chromium.orga5dbde42013-02-02 10:10:02 +090085 bool has_avx_;
agl@chromium.orga3f13f52013-11-23 03:35:03 +090086 bool has_avx_hardware_;
agl@chromium.orgabda8512013-12-03 01:15:03 +090087 bool has_aesni_;
simonjam@chromium.orge50c7cb2013-05-01 04:46:05 +090088 bool has_non_stop_time_stamp_counter_;
agl@chromium.org41be0792014-08-08 17:45:24 +090089 bool has_broken_neon_;
maruel@google.com8178de22008-09-26 07:08:44 +090090 std::string cpu_vendor_;
chunyang.dai@intel.com94d8f282012-10-05 06:05:23 +090091 std::string cpu_brand_;
maruel@google.com8178de22008-09-26 07:08:44 +090092};
93
94} // namespace base
95
96#endif // BASE_CPU_H_