blob: b2e9f7da7ee539581965f7e7991951ee420678b5 [file] [log] [blame]
jkummerow@chromium.org1e8da742013-08-26 17:13:35 +00001// Copyright 2006-2013 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28// This module contains the architecture-specific code. This make the rest of
29// the code less dependent on differences between different processor
30// architecture.
31// The classes have the same definition for all architectures. The
32// implementation for a particular architecture is put in cpu_<arch>.cc.
33// The build system then uses the implementation for the target architecture.
34//
35
36#ifndef V8_CPU_H_
37#define V8_CPU_H_
38
lrn@chromium.org1c092762011-05-09 09:42:16 +000039#include "allocation.h"
40
kasperl@chromium.org71affb52009-05-26 05:44:31 +000041namespace v8 {
42namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000043
44// ----------------------------------------------------------------------------
45// CPU
46//
jkummerow@chromium.org1e8da742013-08-26 17:13:35 +000047// Query information about the processor.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000048//
jkummerow@chromium.org1e8da742013-08-26 17:13:35 +000049// This class also has static methods for the architecture specific functions.
50// Add methods here to cope with differences between the supported
51// architectures. For each architecture the file cpu_<arch>.cc contains the
52// implementation of these static functions.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000053
jkummerow@chromium.org1e8da742013-08-26 17:13:35 +000054class CPU V8_FINAL BASE_EMBEDDED {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000055 public:
jkummerow@chromium.org1e8da742013-08-26 17:13:35 +000056 CPU();
57
58 // x86 CPUID information
59 const char* vendor() const { return vendor_; }
60 int stepping() const { return stepping_; }
61 int model() const { return model_; }
62 int ext_model() const { return ext_model_; }
63 int family() const { return family_; }
64 int ext_family() const { return ext_family_; }
65 int type() const { return type_; }
66
67 // arm implementer/part information
68 int implementer() const { return implementer_; }
69 static const int ARM = 0x41;
70 static const int QUALCOMM = 0x51;
71 int architecture() const { return architecture_; }
72 int part() const { return part_; }
73 static const int ARM_CORTEX_A5 = 0xc05;
74 static const int ARM_CORTEX_A7 = 0xc07;
75 static const int ARM_CORTEX_A8 = 0xc08;
76 static const int ARM_CORTEX_A9 = 0xc09;
77 static const int ARM_CORTEX_A12 = 0xc0c;
78 static const int ARM_CORTEX_A15 = 0xc0f;
79
80 // General features
81 bool has_fpu() const { return has_fpu_; }
82
83 // x86 features
84 bool has_cmov() const { return has_cmov_; }
85 bool has_sahf() const { return has_sahf_; }
86 bool has_mmx() const { return has_mmx_; }
87 bool has_sse() const { return has_sse_; }
88 bool has_sse2() const { return has_sse2_; }
89 bool has_sse3() const { return has_sse3_; }
90 bool has_ssse3() const { return has_ssse3_; }
91 bool has_sse41() const { return has_sse41_; }
92 bool has_sse42() const { return has_sse42_; }
93
94 // arm features
95 bool has_idiva() const { return has_idiva_; }
96 bool has_neon() const { return has_neon_; }
97 bool has_thumbee() const { return has_thumbee_; }
98 bool has_vfp() const { return has_vfp_; }
99 bool has_vfp3() const { return has_vfp3_; }
100 bool has_vfp3_d32() const { return has_vfp3_d32_; }
101
mstarzinger@chromium.org1f410f92013-08-29 08:13:16 +0000102 // Returns the number of processors online.
hpayer@chromium.orgc5d49712013-09-11 08:25:48 +0000103 static int NumberOfProcessorsOnline();
mstarzinger@chromium.org1f410f92013-08-29 08:13:16 +0000104
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000105 // Initializes the cpu architecture support. Called once at VM startup.
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000106 static void SetUp();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000107
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +0000108 static bool SupportsCrankshaft();
109
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000110 // Flush instruction cache.
111 static void FlushICache(void* start, size_t size);
jkummerow@chromium.org1e8da742013-08-26 17:13:35 +0000112
113 private:
114 char vendor_[13];
115 int stepping_;
116 int model_;
117 int ext_model_;
118 int family_;
119 int ext_family_;
120 int type_;
121 int implementer_;
122 int architecture_;
123 int part_;
124 bool has_fpu_;
125 bool has_cmov_;
126 bool has_sahf_;
127 bool has_mmx_;
128 bool has_sse_;
129 bool has_sse2_;
130 bool has_sse3_;
131 bool has_ssse3_;
132 bool has_sse41_;
133 bool has_sse42_;
134 bool has_idiva_;
135 bool has_neon_;
136 bool has_thumbee_;
137 bool has_vfp_;
138 bool has_vfp3_;
139 bool has_vfp3_d32_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000140};
141
142} } // namespace v8::internal
143
144#endif // V8_CPU_H_