Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 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 Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_INSTRUCTION_SET_H_ |
| 18 | #define ART_RUNTIME_INSTRUCTION_SET_H_ |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 19 | |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 20 | #include <iosfwd> |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 21 | #include <string> |
| 22 | |
| 23 | #include "base/macros.h" |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 24 | |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 25 | namespace art { |
| 26 | |
| 27 | enum InstructionSet { |
| 28 | kNone, |
| 29 | kArm, |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 30 | kArm64, |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 31 | kThumb2, |
Shih-wei Liao | 6edfde4 | 2012-03-01 15:49:12 -0800 | [diff] [blame] | 32 | kX86, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 33 | kX86_64, |
Shih-wei Liao | 6edfde4 | 2012-03-01 15:49:12 -0800 | [diff] [blame] | 34 | kMips |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 35 | }; |
Ian Rogers | 8afeb85 | 2014-04-02 14:55:49 -0700 | [diff] [blame] | 36 | std::ostream& operator<<(std::ostream& os, const InstructionSet& rhs); |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 37 | |
Andreas Gampe | af13ad9 | 2014-04-11 12:07:48 -0700 | [diff] [blame] | 38 | size_t GetInstructionSetPointerSize(InstructionSet isa); |
| 39 | size_t GetInstructionSetAlignment(InstructionSet isa); |
| 40 | bool Is64BitInstructionSet(InstructionSet isa); |
| 41 | |
Andreas Gampe | 91268c1 | 2014-04-03 17:50:24 -0700 | [diff] [blame] | 42 | #if defined(__arm__) |
| 43 | static constexpr InstructionSet kRuntimeISA = kArm; |
| 44 | #elif defined(__aarch64__) |
| 45 | static constexpr InstructionSet kRuntimeISA = kArm64; |
| 46 | #elif defined(__mips__) |
| 47 | static constexpr InstructionSet kRuntimeISA = kMips; |
| 48 | #elif defined(__i386__) |
| 49 | static constexpr InstructionSet kRuntimeISA = kX86; |
| 50 | #elif defined(__x86_64__) |
| 51 | static constexpr InstructionSet kRuntimeISA = kX86_64; |
| 52 | #else |
| 53 | static constexpr InstructionSet kRuntimeISA = kNone; |
| 54 | #endif |
| 55 | |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 56 | enum InstructionFeatures { |
| 57 | kHwDiv = 1 // Supports hardware divide. |
| 58 | }; |
| 59 | |
| 60 | // This is a bitmask of supported features per architecture. |
| 61 | class PACKED(4) InstructionSetFeatures { |
| 62 | public: |
| 63 | InstructionSetFeatures() : mask_(0) {} |
| 64 | explicit InstructionSetFeatures(uint32_t mask) : mask_(mask) {} |
| 65 | |
Ian Rogers | 8afeb85 | 2014-04-02 14:55:49 -0700 | [diff] [blame] | 66 | static InstructionSetFeatures GuessInstructionSetFeatures(); |
| 67 | |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 68 | bool HasDivideInstruction() const { |
| 69 | return (mask_ & kHwDiv) != 0; |
| 70 | } |
| 71 | |
| 72 | void SetHasDivideInstruction(bool v) { |
| 73 | mask_ = (mask_ & ~kHwDiv) | (v ? kHwDiv : 0); |
| 74 | } |
| 75 | |
Ian Rogers | 8afeb85 | 2014-04-02 14:55:49 -0700 | [diff] [blame] | 76 | std::string GetFeatureString() const; |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 77 | |
| 78 | // Other features in here. |
| 79 | |
| 80 | bool operator==(const InstructionSetFeatures &peer) const { |
| 81 | return mask_ == peer.mask_; |
| 82 | } |
| 83 | |
| 84 | bool operator!=(const InstructionSetFeatures &peer) const { |
| 85 | return mask_ != peer.mask_; |
| 86 | } |
| 87 | |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 88 | bool operator<=(const InstructionSetFeatures &peer) const { |
| 89 | return (mask_ & peer.mask_) == mask_; |
| 90 | } |
| 91 | |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 92 | private: |
| 93 | uint32_t mask_; |
| 94 | }; |
| 95 | |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 96 | } // namespace art |
| 97 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 98 | #endif // ART_RUNTIME_INSTRUCTION_SET_H_ |