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

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/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
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/globals.h"
9
8 namespace v8 { 10 namespace v8 {
9 namespace internal { 11 namespace internal {
12
13 class OStream;
14
10 namespace compiler { 15 namespace compiler {
11 16
12 // An enumeration of the storage representations at the machine level. 17 // Machine-level types and representations.
13 // - Words are uninterpreted bits of a given fixed size that can be used 18 // 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 { 19 enum MachineType {
24 kMachineWord8, 20 // Representations.
25 kMachineWord16, 21 kRepBit = 1 << 0,
26 kMachineWord32, 22 kRepWord8 = 1 << 1,
27 kMachineWord64, 23 kRepWord16 = 1 << 2,
28 kMachineFloat64, 24 kRepWord32 = 1 << 3,
29 kMachineTagged, 25 kRepWord64 = 1 << 4,
30 kMachineLast 26 kRepFloat64 = 1 << 5,
27 kRepTagged = 1 << 6,
28
29 // Types.
30 kTypeBool = 1 << 7,
31 kTypeInt32 = 1 << 8,
32 kTypeUint32 = 1 << 9,
33 kTypeInt64 = 1 << 10,
34 kTypeUint64 = 1 << 11,
35 kTypeNumber = 1 << 12,
36 kTypeAny = 1 << 13
31 }; 37 };
38
39 OStream& operator<<(OStream& os, const MachineType& type);
40
41 typedef uint16_t MachineTypeUnion;
42
43 // Globally useful machine types and constants.
44 const MachineTypeUnion kRepMask = kRepBit | kRepWord8 | kRepWord16 |
45 kRepWord32 | kRepWord64 | kRepFloat64 |
46 kRepTagged;
47 const MachineTypeUnion kTypeMask = kTypeBool | kTypeInt32 | kTypeUint32 |
48 kTypeInt64 | kTypeUint64 | kTypeNumber |
49 kTypeAny;
50
51 const MachineType kMachNone = static_cast<MachineType>(0);
52 const MachineType kMachFloat64 =
53 static_cast<MachineType>(kRepFloat64 | kTypeNumber);
54 const MachineType kMachInt8 = static_cast<MachineType>(kRepWord8 | kTypeInt32);
55 const MachineType kMachUint8 =
56 static_cast<MachineType>(kRepWord8 | kTypeUint32);
57 const MachineType kMachInt16 =
58 static_cast<MachineType>(kRepWord16 | kTypeInt32);
59 const MachineType kMachUint16 =
60 static_cast<MachineType>(kRepWord16 | kTypeUint32);
61 const MachineType kMachInt32 =
62 static_cast<MachineType>(kRepWord32 | kTypeInt32);
63 const MachineType kMachUint32 =
64 static_cast<MachineType>(kRepWord32 | kTypeUint32);
65 const MachineType kMachInt64 =
66 static_cast<MachineType>(kRepWord64 | kTypeInt64);
67 const MachineType kMachUint64 =
68 static_cast<MachineType>(kRepWord64 | kTypeUint64);
69 const MachineType kMachPtr = kPointerSize == 4 ? kRepWord32 : kRepWord64;
70 const MachineType kMachAnyTagged =
71 static_cast<MachineType>(kRepTagged | kTypeAny);
72
73 // Gets only the representation of the given type.
74 inline MachineType RepresentationOf(MachineType machine_type) {
75 int result = machine_type & kRepMask;
76 CHECK(IsPowerOf2(result));
77 return static_cast<MachineType>(result);
78 }
79
80 // Gets the element size in bytes of the machine type.
81 inline int ElementSizeOf(MachineType machine_type) {
82 switch (RepresentationOf(machine_type)) {
83 case kRepBit:
84 case kRepWord8:
85 return 1;
86 case kRepWord16:
87 return 2;
88 case kRepWord32:
89 return 4;
90 case kRepWord64:
91 case kRepFloat64:
92 return 8;
93 case kRepTagged:
94 return kPointerSize;
95 default:
96 UNREACHABLE();
97 return kPointerSize;
98 }
99 }
32 } 100 }
33 } 101 }
34 } // namespace v8::internal::compiler 102 } // namespace v8::internal::compiler
35 103
36 #endif // V8_COMPILER_MACHINE_TYPE_H_ 104 #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