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

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

Issue 470593002: Unify MachineType and RepType. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 months 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 | Annotate | Revision Log
« no previous file with comments | « src/compiler/machine-operator.h ('k') | src/compiler/representation-change.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 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 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_COMPILER_MACHINE_TYPE_H_ 5 #ifndef V8_COMPILER_MACHINE_TYPE_H_
6 #define V8_COMPILER_MACHINE_TYPE_H_ 6 #define V8_COMPILER_MACHINE_TYPE_H_
7 7
8 #include "src/ostreams.h"
9 #include "src/v8.h"
10
8 namespace v8 { 11 namespace v8 {
9 namespace internal { 12 namespace internal {
10 namespace compiler { 13 namespace compiler {
11 14
12 // An enumeration of the storage representations at the machine level. 15 // Machine-level types and representations.
13 // - Words are uninterpreted bits of a given fixed size that can be used 16 // TODO(titzer): Use the real type system instead of MachineType.
14 // to store integers and pointers. They are normally allocated to general
15 // purpose registers by the backend and are not tracked for GC.
16 // - Floats are bits of a given fixed size that are used to store floating
17 // point numbers. They are normally allocated to the floating point
18 // registers of the machine and are not tracked for the GC.
19 // - Tagged values are the size of a reference into the heap and can store
20 // small words or references into the heap using a language and potentially
21 // machine-dependent tagging scheme. These values are tracked by the code
22 // generator for precise GC.
23 enum MachineType { 17 enum MachineType {
24 kMachineWord8, 18 // Representations.
25 kMachineWord16, 19 rBit = 1 << 0,
Benedikt Meurer 2014/08/13 19:42:07 Urghs, WTF? Revival of the hungarian notation? Can
titzer 2014/08/14 07:50:19 I've changed the names to match the recommended k*
26 kMachineWord32, 20 rWord8 = 1 << 1,
27 kMachineWord64, 21 rWord16 = 1 << 2,
28 kMachineFloat64, 22 rWord32 = 1 << 3,
29 kMachineTagged, 23 rWord64 = 1 << 4,
30 kMachineLast 24 rFloat64 = 1 << 5,
25 rTagged = 1 << 6,
26
27 // Types.
28 tBool = 1 << 7,
29 tInt32 = 1 << 8,
30 tUint32 = 1 << 9,
31 tInt64 = 1 << 10,
32 tUint64 = 1 << 11,
33 tNumber = 1 << 12,
34 tAny = 1 << 13
31 }; 35 };
36
37 typedef uint16_t MachineTypeUnion;
38
39 #define PRINT(bit) \
40 if (type & bit) { \
41 if (before) os << "|"; \
42 os << #bit; \
43 before = true; \
44 }
45
46 // Print a machine type or machine type union to a stream.
47 inline void PrintMachineTypeUnionTo(OStream& os, MachineTypeUnion type) {
48 bool before = false;
49 PRINT(rBit);
50 PRINT(rWord8);
51 PRINT(rWord16);
52 PRINT(rWord32);
53 PRINT(rWord64);
54 PRINT(rFloat64);
55 PRINT(rTagged);
56
57 PRINT(tBool);
58 PRINT(tInt32);
59 PRINT(tUint32);
60 PRINT(tInt64);
61 PRINT(tUint64);
62 PRINT(tNumber);
63 PRINT(tAny);
64 }
65
66 // Globally useful machine types and constants.
67 const MachineTypeUnion rMask =
68 rBit | rWord8 | rWord16 | rWord32 | rWord64 | rFloat64 | rTagged;
69 const MachineTypeUnion tMask =
70 tBool | tInt32 | tUint32 | tInt64 | tUint64 | tNumber | tAny;
71
72 const MachineType mNone = static_cast<MachineType>(0);
73 const MachineType mFloat64 = static_cast<MachineType>(rFloat64 | tNumber);
74 const MachineType mInt8 = static_cast<MachineType>(rWord8 | tInt32);
75 const MachineType mUint8 = static_cast<MachineType>(rWord8 | tUint32);
76 const MachineType mInt16 = static_cast<MachineType>(rWord16 | tInt32);
77 const MachineType mUint16 = static_cast<MachineType>(rWord16 | tUint32);
78 const MachineType mInt32 = static_cast<MachineType>(rWord32 | tInt32);
79 const MachineType mUint32 = static_cast<MachineType>(rWord32 | tUint32);
80 const MachineType mInt64 = static_cast<MachineType>(rWord64 | tInt64);
81 const MachineType mUint64 = static_cast<MachineType>(rWord64 | tUint64);
82 const MachineType mPtr = kPointerSize == 4 ? rWord32 : rWord64;
83 const MachineType mAnyTagged = static_cast<MachineType>(rTagged | tAny);
84
85 // Gets only the representation of the given type.
86 inline MachineType RepresentationOf(MachineType machine_type) {
87 int result = machine_type & rMask;
88 CHECK(IsPowerOf2(result));
89 return static_cast<MachineType>(result);
90 }
91
92 // Gets the element size in bytes of the machine type.
93 inline int ElementSizeOf(MachineType machine_type) {
94 switch (RepresentationOf(machine_type)) {
95 case rBit:
96 case rWord8:
97 return 1;
98 case rWord16:
99 return 2;
100 case rWord32:
101 return 4;
102 case rWord64:
103 case rFloat64:
104 return 8;
105 case rTagged:
106 return kPointerSize;
107 default:
108 UNREACHABLE();
109 return kPointerSize;
110 }
111 }
32 } 112 }
33 } 113 }
34 } // namespace v8::internal::compiler 114 } // namespace v8::internal::compiler
35 115
36 #endif // V8_COMPILER_MACHINE_TYPE_H_ 116 #endif // V8_COMPILER_MACHINE_TYPE_H_
OLDNEW
« no previous file with comments | « src/compiler/machine-operator.h ('k') | src/compiler/representation-change.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698