2014-08-11 15:55:28 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-12-03 13:33:14 +00:00
|
|
|
#ifndef V8_MACHINE_TYPE_H_
|
|
|
|
#define V8_MACHINE_TYPE_H_
|
2014-08-11 15:55:28 +00:00
|
|
|
|
2014-09-30 10:29:32 +00:00
|
|
|
#include <iosfwd>
|
|
|
|
|
2014-09-02 13:36:35 +00:00
|
|
|
#include "src/base/bits.h"
|
2014-08-14 09:19:54 +00:00
|
|
|
#include "src/globals.h"
|
2015-05-04 10:11:50 +00:00
|
|
|
#include "src/signature.h"
|
2016-09-20 16:07:25 +00:00
|
|
|
#include "src/zone/zone.h"
|
2014-08-14 09:19:54 +00:00
|
|
|
|
2014-08-11 15:55:28 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2015-12-10 09:03:30 +00:00
|
|
|
enum class MachineRepresentation : uint8_t {
|
|
|
|
kNone,
|
|
|
|
kBit,
|
|
|
|
kWord8,
|
|
|
|
kWord16,
|
|
|
|
kWord32,
|
|
|
|
kWord64,
|
2016-08-16 12:41:13 +00:00
|
|
|
kTaggedSigned,
|
|
|
|
kTaggedPointer,
|
2016-10-03 21:39:25 +00:00
|
|
|
kTagged,
|
|
|
|
// FP representations must be last, and in order of increasing size.
|
|
|
|
kFloat32,
|
|
|
|
kFloat64,
|
|
|
|
kSimd128,
|
2016-11-09 18:48:53 +00:00
|
|
|
kFirstFPRepresentation = kFloat32,
|
|
|
|
kLastRepresentation = kSimd128
|
2014-08-11 15:55:28 +00:00
|
|
|
};
|
2014-08-14 09:19:54 +00:00
|
|
|
|
2016-11-09 18:48:53 +00:00
|
|
|
static_assert(static_cast<int>(MachineRepresentation::kLastRepresentation) <
|
|
|
|
kIntSize * kBitsPerByte,
|
|
|
|
"Bit masks of MachineRepresentation should fit in an int");
|
|
|
|
|
2016-06-29 09:26:40 +00:00
|
|
|
const char* MachineReprToString(MachineRepresentation);
|
|
|
|
|
2015-12-10 09:03:30 +00:00
|
|
|
enum class MachineSemantic : uint8_t {
|
|
|
|
kNone,
|
|
|
|
kBool,
|
|
|
|
kInt32,
|
|
|
|
kUint32,
|
|
|
|
kInt64,
|
|
|
|
kUint64,
|
|
|
|
kNumber,
|
|
|
|
kAny
|
|
|
|
};
|
|
|
|
|
|
|
|
class MachineType {
|
|
|
|
public:
|
|
|
|
MachineType()
|
|
|
|
: representation_(MachineRepresentation::kNone),
|
|
|
|
semantic_(MachineSemantic::kNone) {}
|
|
|
|
MachineType(MachineRepresentation representation, MachineSemantic semantic)
|
|
|
|
: representation_(representation), semantic_(semantic) {}
|
|
|
|
|
|
|
|
bool operator==(MachineType other) const {
|
|
|
|
return representation() == other.representation() &&
|
|
|
|
semantic() == other.semantic();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(MachineType other) const { return !(*this == other); }
|
2015-06-15 06:27:10 +00:00
|
|
|
|
2014-08-14 09:19:54 +00:00
|
|
|
|
2015-12-10 09:03:30 +00:00
|
|
|
MachineRepresentation representation() const { return representation_; }
|
|
|
|
MachineSemantic semantic() const { return semantic_; }
|
2014-08-14 09:19:54 +00:00
|
|
|
|
2016-09-08 13:02:32 +00:00
|
|
|
bool IsNone() { return representation() == MachineRepresentation::kNone; }
|
|
|
|
|
2015-12-10 09:03:30 +00:00
|
|
|
bool IsSigned() {
|
|
|
|
return semantic() == MachineSemantic::kInt32 ||
|
|
|
|
semantic() == MachineSemantic::kInt64;
|
|
|
|
}
|
|
|
|
bool IsUnsigned() {
|
|
|
|
return semantic() == MachineSemantic::kUint32 ||
|
|
|
|
semantic() == MachineSemantic::kUint64;
|
|
|
|
}
|
2014-08-14 09:19:54 +00:00
|
|
|
|
2015-12-10 09:03:30 +00:00
|
|
|
static MachineRepresentation PointerRepresentation() {
|
|
|
|
return (kPointerSize == 4) ? MachineRepresentation::kWord32
|
|
|
|
: MachineRepresentation::kWord64;
|
|
|
|
}
|
|
|
|
static MachineType Pointer() {
|
|
|
|
return MachineType(PointerRepresentation(), MachineSemantic::kNone);
|
|
|
|
}
|
|
|
|
static MachineType IntPtr() {
|
|
|
|
return (kPointerSize == 4) ? Int32() : Int64();
|
|
|
|
}
|
|
|
|
static MachineType Float32() {
|
|
|
|
return MachineType(MachineRepresentation::kFloat32,
|
|
|
|
MachineSemantic::kNumber);
|
|
|
|
}
|
|
|
|
static MachineType Float64() {
|
|
|
|
return MachineType(MachineRepresentation::kFloat64,
|
|
|
|
MachineSemantic::kNumber);
|
|
|
|
}
|
2016-02-17 19:03:43 +00:00
|
|
|
static MachineType Simd128() {
|
|
|
|
return MachineType(MachineRepresentation::kSimd128, MachineSemantic::kNone);
|
|
|
|
}
|
2015-12-10 09:03:30 +00:00
|
|
|
static MachineType Int8() {
|
|
|
|
return MachineType(MachineRepresentation::kWord8, MachineSemantic::kInt32);
|
|
|
|
}
|
|
|
|
static MachineType Uint8() {
|
|
|
|
return MachineType(MachineRepresentation::kWord8, MachineSemantic::kUint32);
|
|
|
|
}
|
|
|
|
static MachineType Int16() {
|
|
|
|
return MachineType(MachineRepresentation::kWord16, MachineSemantic::kInt32);
|
|
|
|
}
|
|
|
|
static MachineType Uint16() {
|
|
|
|
return MachineType(MachineRepresentation::kWord16,
|
|
|
|
MachineSemantic::kUint32);
|
|
|
|
}
|
|
|
|
static MachineType Int32() {
|
|
|
|
return MachineType(MachineRepresentation::kWord32, MachineSemantic::kInt32);
|
|
|
|
}
|
|
|
|
static MachineType Uint32() {
|
|
|
|
return MachineType(MachineRepresentation::kWord32,
|
|
|
|
MachineSemantic::kUint32);
|
|
|
|
}
|
|
|
|
static MachineType Int64() {
|
|
|
|
return MachineType(MachineRepresentation::kWord64, MachineSemantic::kInt64);
|
|
|
|
}
|
|
|
|
static MachineType Uint64() {
|
|
|
|
return MachineType(MachineRepresentation::kWord64,
|
|
|
|
MachineSemantic::kUint64);
|
|
|
|
}
|
2016-08-29 12:32:33 +00:00
|
|
|
static MachineType TaggedPointer() {
|
|
|
|
return MachineType(MachineRepresentation::kTaggedPointer,
|
|
|
|
MachineSemantic::kAny);
|
|
|
|
}
|
|
|
|
static MachineType TaggedSigned() {
|
|
|
|
return MachineType(MachineRepresentation::kTaggedSigned,
|
|
|
|
MachineSemantic::kInt32);
|
|
|
|
}
|
2015-12-10 09:03:30 +00:00
|
|
|
static MachineType AnyTagged() {
|
|
|
|
return MachineType(MachineRepresentation::kTagged, MachineSemantic::kAny);
|
|
|
|
}
|
|
|
|
static MachineType Bool() {
|
|
|
|
return MachineType(MachineRepresentation::kBit, MachineSemantic::kBool);
|
|
|
|
}
|
|
|
|
static MachineType TaggedBool() {
|
|
|
|
return MachineType(MachineRepresentation::kTagged, MachineSemantic::kBool);
|
|
|
|
}
|
|
|
|
static MachineType None() {
|
|
|
|
return MachineType(MachineRepresentation::kNone, MachineSemantic::kNone);
|
|
|
|
}
|
|
|
|
|
|
|
|
// These naked representations should eventually go away.
|
|
|
|
static MachineType RepWord8() {
|
|
|
|
return MachineType(MachineRepresentation::kWord8, MachineSemantic::kNone);
|
|
|
|
}
|
|
|
|
static MachineType RepWord16() {
|
|
|
|
return MachineType(MachineRepresentation::kWord16, MachineSemantic::kNone);
|
|
|
|
}
|
|
|
|
static MachineType RepWord32() {
|
|
|
|
return MachineType(MachineRepresentation::kWord32, MachineSemantic::kNone);
|
|
|
|
}
|
|
|
|
static MachineType RepWord64() {
|
|
|
|
return MachineType(MachineRepresentation::kWord64, MachineSemantic::kNone);
|
|
|
|
}
|
|
|
|
static MachineType RepFloat32() {
|
|
|
|
return MachineType(MachineRepresentation::kFloat32, MachineSemantic::kNone);
|
|
|
|
}
|
|
|
|
static MachineType RepFloat64() {
|
|
|
|
return MachineType(MachineRepresentation::kFloat64, MachineSemantic::kNone);
|
|
|
|
}
|
2016-02-17 19:03:43 +00:00
|
|
|
static MachineType RepSimd128() {
|
|
|
|
return MachineType(MachineRepresentation::kSimd128, MachineSemantic::kNone);
|
|
|
|
}
|
2015-12-10 09:03:30 +00:00
|
|
|
static MachineType RepTagged() {
|
|
|
|
return MachineType(MachineRepresentation::kTagged, MachineSemantic::kNone);
|
|
|
|
}
|
|
|
|
static MachineType RepBit() {
|
|
|
|
return MachineType(MachineRepresentation::kBit, MachineSemantic::kNone);
|
|
|
|
}
|
|
|
|
|
2016-08-30 19:25:08 +00:00
|
|
|
static MachineType TypeForRepresentation(const MachineRepresentation& rep,
|
2016-07-22 20:55:03 +00:00
|
|
|
bool isSigned = true) {
|
|
|
|
switch (rep) {
|
|
|
|
case MachineRepresentation::kNone:
|
|
|
|
return MachineType::None();
|
|
|
|
case MachineRepresentation::kBit:
|
|
|
|
return MachineType::Bool();
|
|
|
|
case MachineRepresentation::kWord8:
|
|
|
|
return isSigned ? MachineType::Int8() : MachineType::Uint8();
|
|
|
|
case MachineRepresentation::kWord16:
|
|
|
|
return isSigned ? MachineType::Int16() : MachineType::Uint16();
|
|
|
|
case MachineRepresentation::kWord32:
|
|
|
|
return isSigned ? MachineType::Int32() : MachineType::Uint32();
|
|
|
|
case MachineRepresentation::kWord64:
|
|
|
|
return isSigned ? MachineType::Int64() : MachineType::Uint64();
|
|
|
|
case MachineRepresentation::kFloat32:
|
|
|
|
return MachineType::Float32();
|
|
|
|
case MachineRepresentation::kFloat64:
|
|
|
|
return MachineType::Float64();
|
|
|
|
case MachineRepresentation::kSimd128:
|
|
|
|
return MachineType::Simd128();
|
|
|
|
case MachineRepresentation::kTagged:
|
|
|
|
return MachineType::AnyTagged();
|
2016-08-30 19:25:08 +00:00
|
|
|
case MachineRepresentation::kTaggedSigned:
|
|
|
|
return MachineType::TaggedSigned();
|
|
|
|
case MachineRepresentation::kTaggedPointer:
|
|
|
|
return MachineType::TaggedPointer();
|
2016-07-22 20:55:03 +00:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return MachineType::None();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-10 09:03:30 +00:00
|
|
|
private:
|
|
|
|
MachineRepresentation representation_;
|
|
|
|
MachineSemantic semantic_;
|
|
|
|
};
|
|
|
|
|
|
|
|
V8_INLINE size_t hash_value(MachineRepresentation rep) {
|
|
|
|
return static_cast<size_t>(rep);
|
2014-08-25 10:35:38 +00:00
|
|
|
}
|
|
|
|
|
2015-12-10 09:03:30 +00:00
|
|
|
V8_INLINE size_t hash_value(MachineType type) {
|
|
|
|
return static_cast<size_t>(type.representation()) +
|
|
|
|
static_cast<size_t>(type.semantic()) * 16;
|
|
|
|
}
|
|
|
|
|
2016-09-26 07:40:24 +00:00
|
|
|
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
|
|
|
|
MachineRepresentation rep);
|
2015-12-10 09:03:30 +00:00
|
|
|
std::ostream& operator<<(std::ostream& os, MachineSemantic type);
|
2016-10-17 10:01:42 +00:00
|
|
|
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, MachineType type);
|
2015-12-10 09:03:30 +00:00
|
|
|
|
|
|
|
inline bool IsFloatingPoint(MachineRepresentation rep) {
|
2016-10-03 21:39:25 +00:00
|
|
|
return rep >= MachineRepresentation::kFirstFPRepresentation;
|
2014-08-14 09:19:54 +00:00
|
|
|
}
|
|
|
|
|
2016-08-29 12:32:33 +00:00
|
|
|
inline bool CanBeTaggedPointer(MachineRepresentation rep) {
|
|
|
|
return rep == MachineRepresentation::kTagged ||
|
|
|
|
rep == MachineRepresentation::kTaggedPointer;
|
|
|
|
}
|
|
|
|
|
2016-11-03 12:52:11 +00:00
|
|
|
inline bool CanBeTaggedSigned(MachineRepresentation rep) {
|
|
|
|
return rep == MachineRepresentation::kTagged ||
|
|
|
|
rep == MachineRepresentation::kTaggedSigned;
|
|
|
|
}
|
|
|
|
|
2016-08-29 12:32:33 +00:00
|
|
|
inline bool IsAnyTagged(MachineRepresentation rep) {
|
|
|
|
return CanBeTaggedPointer(rep) || rep == MachineRepresentation::kTaggedSigned;
|
|
|
|
}
|
|
|
|
|
2014-10-31 06:41:07 +00:00
|
|
|
// Gets the log2 of the element size in bytes of the machine type.
|
2016-10-26 16:04:11 +00:00
|
|
|
V8_EXPORT_PRIVATE inline int ElementSizeLog2Of(MachineRepresentation rep) {
|
2015-12-10 09:03:30 +00:00
|
|
|
switch (rep) {
|
|
|
|
case MachineRepresentation::kBit:
|
|
|
|
case MachineRepresentation::kWord8:
|
2014-10-31 06:41:07 +00:00
|
|
|
return 0;
|
2015-12-10 09:03:30 +00:00
|
|
|
case MachineRepresentation::kWord16:
|
2014-10-31 06:41:07 +00:00
|
|
|
return 1;
|
2015-12-10 09:03:30 +00:00
|
|
|
case MachineRepresentation::kWord32:
|
|
|
|
case MachineRepresentation::kFloat32:
|
2014-10-31 06:41:07 +00:00
|
|
|
return 2;
|
2015-12-10 09:03:30 +00:00
|
|
|
case MachineRepresentation::kWord64:
|
|
|
|
case MachineRepresentation::kFloat64:
|
2014-10-31 06:41:07 +00:00
|
|
|
return 3;
|
2016-02-17 19:03:43 +00:00
|
|
|
case MachineRepresentation::kSimd128:
|
|
|
|
return 4;
|
2016-08-16 12:41:13 +00:00
|
|
|
case MachineRepresentation::kTaggedSigned:
|
|
|
|
case MachineRepresentation::kTaggedPointer:
|
2015-12-10 09:03:30 +00:00
|
|
|
case MachineRepresentation::kTagged:
|
2014-10-31 06:41:07 +00:00
|
|
|
return kPointerSizeLog2;
|
2014-08-14 09:19:54 +00:00
|
|
|
default:
|
2014-10-31 06:41:07 +00:00
|
|
|
break;
|
2014-08-14 09:19:54 +00:00
|
|
|
}
|
2014-10-31 06:41:07 +00:00
|
|
|
UNREACHABLE();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-09-03 10:13:21 +00:00
|
|
|
typedef Signature<MachineType> MachineSignature;
|
2015-05-05 09:42:59 +00:00
|
|
|
|
2014-08-25 10:35:38 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
2014-08-11 15:55:28 +00:00
|
|
|
|
2015-12-03 13:33:14 +00:00
|
|
|
#endif // V8_MACHINE_TYPE_H_
|