blob: 4eebaa6b164ebc78afca7b818853732a6c5613e3 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Ian Rogersb033c752011-07-20 12:22:35 -070016
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_INSTRUCTION_SET_H_
18#define ART_RUNTIME_INSTRUCTION_SET_H_
Ian Rogersb033c752011-07-20 12:22:35 -070019
Ian Rogersc8b306f2012-02-17 21:34:44 -080020#include <iosfwd>
Dave Allison70202782013-10-22 17:52:19 -070021#include <string>
22
23#include "base/macros.h"
Ian Rogersc8b306f2012-02-17 21:34:44 -080024
buzbeec143c552011-08-20 17:38:58 -070025namespace art {
26
27enum InstructionSet {
28 kNone,
29 kArm,
Serban Constantinescued8dd492014-02-11 14:15:10 +000030 kArm64,
buzbeec143c552011-08-20 17:38:58 -070031 kThumb2,
Shih-wei Liao6edfde42012-03-01 15:49:12 -080032 kX86,
Ian Rogersef7d42f2014-01-06 12:55:46 -080033 kX86_64,
Shih-wei Liao6edfde42012-03-01 15:49:12 -080034 kMips
buzbeec143c552011-08-20 17:38:58 -070035};
Ian Rogers8afeb852014-04-02 14:55:49 -070036std::ostream& operator<<(std::ostream& os, const InstructionSet& rhs);
buzbeec143c552011-08-20 17:38:58 -070037
Andreas Gampeaf13ad92014-04-11 12:07:48 -070038size_t GetInstructionSetPointerSize(InstructionSet isa);
39size_t GetInstructionSetAlignment(InstructionSet isa);
40bool Is64BitInstructionSet(InstructionSet isa);
41
Andreas Gampe91268c12014-04-03 17:50:24 -070042#if defined(__arm__)
43static constexpr InstructionSet kRuntimeISA = kArm;
Nicolas Geoffray5cb32832014-04-17 14:05:19 +010044static constexpr size_t kBytesPerGprSpillLocation = 4;
45static constexpr size_t kBytesPerFprSpillLocation = 4;
Andreas Gampe91268c12014-04-03 17:50:24 -070046#elif defined(__aarch64__)
47static constexpr InstructionSet kRuntimeISA = kArm64;
Nicolas Geoffray5cb32832014-04-17 14:05:19 +010048static constexpr size_t kBytesPerGprSpillLocation = 8;
49static constexpr size_t kBytesPerFprSpillLocation = 8;
Andreas Gampe91268c12014-04-03 17:50:24 -070050#elif defined(__mips__)
51static constexpr InstructionSet kRuntimeISA = kMips;
Nicolas Geoffray5cb32832014-04-17 14:05:19 +010052static constexpr size_t kBytesPerGprSpillLocation = 4;
53static constexpr size_t kBytesPerFprSpillLocation = 4;
Andreas Gampe91268c12014-04-03 17:50:24 -070054#elif defined(__i386__)
55static constexpr InstructionSet kRuntimeISA = kX86;
Nicolas Geoffray5cb32832014-04-17 14:05:19 +010056static constexpr size_t kBytesPerGprSpillLocation = 4;
57static constexpr size_t kBytesPerFprSpillLocation = 8;
Andreas Gampe91268c12014-04-03 17:50:24 -070058#elif defined(__x86_64__)
59static constexpr InstructionSet kRuntimeISA = kX86_64;
Nicolas Geoffray5cb32832014-04-17 14:05:19 +010060static constexpr size_t kBytesPerGprSpillLocation = 8;
61static constexpr size_t kBytesPerFprSpillLocation = 8;
Andreas Gampe91268c12014-04-03 17:50:24 -070062#else
63static constexpr InstructionSet kRuntimeISA = kNone;
64#endif
65
Dave Allison70202782013-10-22 17:52:19 -070066enum InstructionFeatures {
67 kHwDiv = 1 // Supports hardware divide.
68};
69
70// This is a bitmask of supported features per architecture.
71class PACKED(4) InstructionSetFeatures {
72 public:
73 InstructionSetFeatures() : mask_(0) {}
74 explicit InstructionSetFeatures(uint32_t mask) : mask_(mask) {}
75
Ian Rogers8afeb852014-04-02 14:55:49 -070076 static InstructionSetFeatures GuessInstructionSetFeatures();
77
Dave Allison70202782013-10-22 17:52:19 -070078 bool HasDivideInstruction() const {
79 return (mask_ & kHwDiv) != 0;
80 }
81
82 void SetHasDivideInstruction(bool v) {
83 mask_ = (mask_ & ~kHwDiv) | (v ? kHwDiv : 0);
84 }
85
Ian Rogers8afeb852014-04-02 14:55:49 -070086 std::string GetFeatureString() const;
Dave Allison70202782013-10-22 17:52:19 -070087
88 // Other features in here.
89
90 bool operator==(const InstructionSetFeatures &peer) const {
91 return mask_ == peer.mask_;
92 }
93
94 bool operator!=(const InstructionSetFeatures &peer) const {
95 return mask_ != peer.mask_;
96 }
97
Serban Constantinescu75b91132014-04-09 18:39:10 +010098 bool operator<=(const InstructionSetFeatures &peer) const {
99 return (mask_ & peer.mask_) == mask_;
100 }
101
Dave Allison70202782013-10-22 17:52:19 -0700102 private:
103 uint32_t mask_;
104};
105
buzbeec143c552011-08-20 17:38:58 -0700106} // namespace art
107
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700108#endif // ART_RUNTIME_INSTRUCTION_SET_H_