Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: src/compiler/machine-type.h

Issue 1498833002: Move machine-type.h from src/compiler to src/. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/machine-operator.h ('k') | src/compiler/machine-type.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_COMPILER_MACHINE_TYPE_H_
6 #define V8_COMPILER_MACHINE_TYPE_H_
7
8 #include <iosfwd>
9
10 #include "src/base/bits.h"
11 #include "src/globals.h"
12 #include "src/signature.h"
13 #include "src/zone.h"
14
15 namespace v8 {
16 namespace internal {
17 namespace compiler {
18
19 // Machine-level types and representations.
20 // TODO(titzer): Use the real type system instead of MachineType.
21 enum MachineType : uint16_t {
22 // Representations.
23 kRepBit = 1u << 0,
24 kRepWord8 = 1u << 1,
25 kRepWord16 = 1u << 2,
26 kRepWord32 = 1u << 3,
27 kRepWord64 = 1u << 4,
28 kRepFloat32 = 1u << 5,
29 kRepFloat64 = 1u << 6,
30 kRepTagged = 1u << 7,
31
32 // Types.
33 kTypeBool = 1u << 8,
34 kTypeInt32 = 1u << 9,
35 kTypeUint32 = 1u << 10,
36 kTypeInt64 = 1u << 11,
37 kTypeUint64 = 1u << 12,
38 kTypeNumber = 1u << 13,
39 kTypeAny = 1u << 14,
40
41 // Machine types.
42 kMachNone = 0u,
43 kMachBool = kRepBit | kTypeBool,
44 kMachFloat32 = kRepFloat32 | kTypeNumber,
45 kMachFloat64 = kRepFloat64 | kTypeNumber,
46 kMachInt8 = kRepWord8 | kTypeInt32,
47 kMachUint8 = kRepWord8 | kTypeUint32,
48 kMachInt16 = kRepWord16 | kTypeInt32,
49 kMachUint16 = kRepWord16 | kTypeUint32,
50 kMachInt32 = kRepWord32 | kTypeInt32,
51 kMachUint32 = kRepWord32 | kTypeUint32,
52 kMachInt64 = kRepWord64 | kTypeInt64,
53 kMachUint64 = kRepWord64 | kTypeUint64,
54 kMachIntPtr = (kPointerSize == 4) ? kMachInt32 : kMachInt64,
55 kMachUintPtr = (kPointerSize == 4) ? kMachUint32 : kMachUint64,
56 kMachPtr = (kPointerSize == 4) ? kRepWord32 : kRepWord64,
57 kMachAnyTagged = kRepTagged | kTypeAny
58 };
59
60 V8_INLINE size_t hash_value(MachineType type) {
61 return static_cast<size_t>(type);
62 }
63
64 std::ostream& operator<<(std::ostream& os, const MachineType& type);
65
66 typedef uint16_t MachineTypeUnion;
67
68 // Globally useful machine types and constants.
69 const MachineTypeUnion kRepMask = kRepBit | kRepWord8 | kRepWord16 |
70 kRepWord32 | kRepWord64 | kRepFloat32 |
71 kRepFloat64 | kRepTagged;
72 const MachineTypeUnion kTypeMask = kTypeBool | kTypeInt32 | kTypeUint32 |
73 kTypeInt64 | kTypeUint64 | kTypeNumber |
74 kTypeAny;
75
76 // Gets only the type of the given type.
77 inline MachineType TypeOf(MachineType machine_type) {
78 int result = machine_type & kTypeMask;
79 return static_cast<MachineType>(result);
80 }
81
82 // Gets only the representation of the given type.
83 inline MachineType RepresentationOf(MachineType machine_type) {
84 int result = machine_type & kRepMask;
85 CHECK(base::bits::IsPowerOfTwo32(result));
86 return static_cast<MachineType>(result);
87 }
88
89 // Gets the log2 of the element size in bytes of the machine type.
90 inline int ElementSizeLog2Of(MachineType machine_type) {
91 switch (RepresentationOf(machine_type)) {
92 case kRepBit:
93 case kRepWord8:
94 return 0;
95 case kRepWord16:
96 return 1;
97 case kRepWord32:
98 case kRepFloat32:
99 return 2;
100 case kRepWord64:
101 case kRepFloat64:
102 return 3;
103 case kRepTagged:
104 return kPointerSizeLog2;
105 default:
106 break;
107 }
108 UNREACHABLE();
109 return -1;
110 }
111
112 // Gets the element size in bytes of the machine type.
113 inline int ElementSizeOf(MachineType machine_type) {
114 const int shift = ElementSizeLog2Of(machine_type);
115 DCHECK_NE(-1, shift);
116 return 1 << shift;
117 }
118
119 inline bool IsFloatingPoint(MachineType type) {
120 MachineType rep = RepresentationOf(type);
121 return rep == kRepFloat32 || rep == kRepFloat64;
122 }
123
124 typedef Signature<MachineType> MachineSignature;
125
126 } // namespace compiler
127 } // namespace internal
128 } // namespace v8
129
130 #endif // V8_COMPILER_MACHINE_TYPE_H_
OLDNEW
« no previous file with comments | « src/compiler/machine-operator.h ('k') | src/compiler/machine-type.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698