OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_MIPS_CONSTANTS_H_ | 5 #ifndef V8_MIPS_CONSTANTS_H_ |
6 #define V8_MIPS_CONSTANTS_H_ | 6 #define V8_MIPS_CONSTANTS_H_ |
7 #include "src/globals.h" | 7 #include "src/globals.h" |
8 // UNIMPLEMENTED_ macro for MIPS. | 8 // UNIMPLEMENTED_ macro for MIPS. |
9 #ifdef DEBUG | 9 #ifdef DEBUG |
10 #define UNIMPLEMENTED_MIPS() \ | 10 #define UNIMPLEMENTED_MIPS() \ |
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 | 891 |
892 // Read one particular bit out of the instruction bits. | 892 // Read one particular bit out of the instruction bits. |
893 inline int Bit(int nr) const { | 893 inline int Bit(int nr) const { |
894 return (InstructionBits() >> nr) & 1; | 894 return (InstructionBits() >> nr) & 1; |
895 } | 895 } |
896 | 896 |
897 // Read a bit field out of the instruction bits. | 897 // Read a bit field out of the instruction bits. |
898 inline int Bits(int hi, int lo) const { | 898 inline int Bits(int hi, int lo) const { |
899 return (InstructionBits() >> lo) & ((2U << (hi - lo)) - 1); | 899 return (InstructionBits() >> lo) & ((2U << (hi - lo)) - 1); |
900 } | 900 } |
901 enum TypeChecks { NORMAL, EXTRA }; | |
902 | 901 |
903 | 902 |
904 static constexpr uint64_t kOpcodeImmediateTypeMask = | 903 static constexpr uint64_t kOpcodeImmediateTypeMask = |
905 OpcodeToBitNumber(REGIMM) | OpcodeToBitNumber(BEQ) | | 904 OpcodeToBitNumber(REGIMM) | OpcodeToBitNumber(BEQ) | |
906 OpcodeToBitNumber(BNE) | OpcodeToBitNumber(BLEZ) | | 905 OpcodeToBitNumber(BNE) | OpcodeToBitNumber(BLEZ) | |
907 OpcodeToBitNumber(BGTZ) | OpcodeToBitNumber(ADDI) | | 906 OpcodeToBitNumber(BGTZ) | OpcodeToBitNumber(ADDI) | |
908 OpcodeToBitNumber(DADDI) | OpcodeToBitNumber(ADDIU) | | 907 OpcodeToBitNumber(DADDI) | OpcodeToBitNumber(ADDIU) | |
909 OpcodeToBitNumber(SLTI) | OpcodeToBitNumber(SLTIU) | | 908 OpcodeToBitNumber(SLTI) | OpcodeToBitNumber(SLTIU) | |
910 OpcodeToBitNumber(ANDI) | OpcodeToBitNumber(ORI) | | 909 OpcodeToBitNumber(ANDI) | OpcodeToBitNumber(ORI) | |
911 OpcodeToBitNumber(XORI) | OpcodeToBitNumber(LUI) | | 910 OpcodeToBitNumber(XORI) | OpcodeToBitNumber(LUI) | |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 } | 959 } |
961 | 960 |
962 // Safe to call within InstructionType(). | 961 // Safe to call within InstructionType(). |
963 inline int RsFieldRawNoAssert() const { | 962 inline int RsFieldRawNoAssert() const { |
964 return InstructionBits() & kRsFieldMask; | 963 return InstructionBits() & kRsFieldMask; |
965 } | 964 } |
966 | 965 |
967 inline int SaFieldRaw() const { return InstructionBits() & kSaFieldMask; } | 966 inline int SaFieldRaw() const { return InstructionBits() & kSaFieldMask; } |
968 | 967 |
969 // Get the encoding type of the instruction. | 968 // Get the encoding type of the instruction. |
970 inline Type InstructionType(TypeChecks checks = NORMAL) const; | 969 inline Type InstructionType() const; |
971 | 970 |
972 protected: | 971 protected: |
973 InstructionBase() {} | 972 InstructionBase() {} |
974 }; | 973 }; |
975 | 974 |
976 template <class T> | 975 template <class T> |
977 class InstructionGetters : public T { | 976 class InstructionGetters : public T { |
978 public: | 977 public: |
979 inline int RsValue() const { | 978 inline int RsValue() const { |
980 DCHECK(this->InstructionType() == InstructionBase::kRegisterType || | 979 DCHECK(this->InstructionType() == InstructionBase::kRegisterType || |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1135 } | 1134 } |
1136 | 1135 |
1137 // Say if the instruction 'links'. e.g. jal, bal. | 1136 // Say if the instruction 'links'. e.g. jal, bal. |
1138 bool IsLinkingInstruction() const; | 1137 bool IsLinkingInstruction() const; |
1139 // Say if the instruction is a break or a trap. | 1138 // Say if the instruction is a break or a trap. |
1140 bool IsTrap() const; | 1139 bool IsTrap() const; |
1141 }; | 1140 }; |
1142 | 1141 |
1143 class Instruction : public InstructionGetters<InstructionBase> { | 1142 class Instruction : public InstructionGetters<InstructionBase> { |
1144 public: | 1143 public: |
| 1144 // Instructions are read of out a code stream. The only way to get a |
| 1145 // reference to an instruction is to convert a pointer. There is no way |
| 1146 // to allocate or create instances of class Instruction. |
| 1147 // Use the At(pc) function to create references to Instruction. |
1145 static Instruction* At(byte* pc) { | 1148 static Instruction* At(byte* pc) { |
1146 return reinterpret_cast<Instruction*>(pc); | 1149 return reinterpret_cast<Instruction*>(pc); |
1147 } | 1150 } |
1148 | 1151 |
1149 private: | 1152 private: |
| 1153 // We need to prevent the creation of instances of class Instruction. |
1150 DISALLOW_IMPLICIT_CONSTRUCTORS(Instruction); | 1154 DISALLOW_IMPLICIT_CONSTRUCTORS(Instruction); |
1151 }; | 1155 }; |
1152 | 1156 |
1153 | 1157 |
1154 // ----------------------------------------------------------------------------- | 1158 // ----------------------------------------------------------------------------- |
1155 // MIPS assembly various constants. | 1159 // MIPS assembly various constants. |
1156 | 1160 |
1157 // C/C++ argument slots size. | 1161 // C/C++ argument slots size. |
1158 const int kCArgSlotCount = 4; | 1162 const int kCArgSlotCount = 4; |
1159 const int kCArgsSlotsSize = kCArgSlotCount * Instruction::kInstrSize; | 1163 const int kCArgsSlotsSize = kCArgSlotCount * Instruction::kInstrSize; |
1160 const int kInvalidStackOffset = -1; | 1164 const int kInvalidStackOffset = -1; |
1161 // JS argument slots size. | 1165 // JS argument slots size. |
1162 const int kJSArgsSlotsSize = 0 * Instruction::kInstrSize; | 1166 const int kJSArgsSlotsSize = 0 * Instruction::kInstrSize; |
1163 // Assembly builtins argument slots size. | 1167 // Assembly builtins argument slots size. |
1164 const int kBArgsSlotsSize = 0 * Instruction::kInstrSize; | 1168 const int kBArgsSlotsSize = 0 * Instruction::kInstrSize; |
1165 | 1169 |
1166 const int kBranchReturnOffset = 2 * Instruction::kInstrSize; | 1170 const int kBranchReturnOffset = 2 * Instruction::kInstrSize; |
1167 | 1171 |
1168 InstructionBase::Type InstructionBase::InstructionType( | 1172 InstructionBase::Type InstructionBase::InstructionType() const { |
1169 TypeChecks checks) const { | |
1170 if (checks == EXTRA) { | |
1171 if (OpcodeToBitNumber(OpcodeFieldRaw()) & kOpcodeImmediateTypeMask) { | |
1172 return kImmediateType; | |
1173 } | |
1174 } | |
1175 switch (OpcodeFieldRaw()) { | 1173 switch (OpcodeFieldRaw()) { |
1176 case SPECIAL: | 1174 case SPECIAL: |
1177 if (checks == EXTRA) { | 1175 if (FunctionFieldToBitNumber(FunctionFieldRaw()) & |
1178 if (FunctionFieldToBitNumber(FunctionFieldRaw()) & | 1176 kFunctionFieldRegisterTypeMask) { |
1179 kFunctionFieldRegisterTypeMask) { | |
1180 return kRegisterType; | |
1181 } else { | |
1182 return kUnsupported; | |
1183 } | |
1184 } else { | |
1185 return kRegisterType; | 1177 return kRegisterType; |
1186 } | 1178 } |
1187 break; | 1179 return kUnsupported; |
1188 case SPECIAL2: | 1180 case SPECIAL2: |
1189 switch (FunctionFieldRaw()) { | 1181 switch (FunctionFieldRaw()) { |
1190 case MUL: | 1182 case MUL: |
1191 case CLZ: | 1183 case CLZ: |
1192 return kRegisterType; | 1184 return kRegisterType; |
1193 default: | 1185 default: |
1194 return kUnsupported; | 1186 return kUnsupported; |
1195 } | 1187 } |
1196 break; | 1188 break; |
1197 case SPECIAL3: | 1189 case SPECIAL3: |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1232 break; | 1224 break; |
1233 case COP1X: | 1225 case COP1X: |
1234 return kRegisterType; | 1226 return kRegisterType; |
1235 | 1227 |
1236 // 26 bits immediate type instructions. e.g.: j imm26. | 1228 // 26 bits immediate type instructions. e.g.: j imm26. |
1237 case J: | 1229 case J: |
1238 case JAL: | 1230 case JAL: |
1239 return kJumpType; | 1231 return kJumpType; |
1240 | 1232 |
1241 default: | 1233 default: |
1242 if (checks == NORMAL) { | |
1243 return kImmediateType; | 1234 return kImmediateType; |
1244 } else { | |
1245 return kUnsupported; | |
1246 } | |
1247 } | 1235 } |
1248 } | 1236 } |
1249 | 1237 |
1250 #undef OpcodeToBitNumber | 1238 #undef OpcodeToBitNumber |
1251 #undef FunctionFieldToBitNumber | 1239 #undef FunctionFieldToBitNumber |
1252 | 1240 |
1253 // ----------------------------------------------------------------------------- | 1241 // ----------------------------------------------------------------------------- |
1254 // Instructions. | 1242 // Instructions. |
1255 | 1243 |
1256 template <class P> | 1244 template <class P> |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1358 } | 1346 } |
1359 break; | 1347 break; |
1360 default: | 1348 default: |
1361 return false; | 1349 return false; |
1362 } | 1350 } |
1363 } | 1351 } |
1364 } // namespace internal | 1352 } // namespace internal |
1365 } // namespace v8 | 1353 } // namespace v8 |
1366 | 1354 |
1367 #endif // #ifndef V8_MIPS_CONSTANTS_H_ | 1355 #endif // #ifndef V8_MIPS_CONSTANTS_H_ |
OLD | NEW |