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

Side by Side Diff: src/sh4/constants-sh4.h

Issue 11275184: First draft of the sh4 port Base URL: http://github.com/v8/v8.git@master
Patch Set: Use GYP and fixe some typos Created 8 years, 1 month 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/sh4/codegen-sh4.cc ('k') | src/sh4/constants-sh4.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 2011-2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #ifndef V8_SH4_CONSTANTS_SH4_H_
29 #define V8_SH4_CONSTANTS_SH4_H_
30
31 namespace v8 {
32 namespace internal {
33
34 // Number of registers in normal SH4 mode.
35 static const int kNumRegisters = 16;
36
37 // Marker for end of register list.
38 static const int kNoRegister = -1;
39
40 // -----------------------------------------------------------------------------
41 // Instructions encoding.
42
43 // Instr is merely used by the Assembler to distinguish 32bit integers
44 // representing instructions from usual 32 bit values.
45 // Instruction objects are pointers to 32bit values, and provide methods to
46 // access the various ISA fields.
47 typedef uint16_t Instr;
48
49
50 // -----------------------------------------------------------------------------
51 // Instruction abstraction.
52
53 class Instruction {
54 public:
55 enum {
56 kInstrSize = 2,
57 kInstrSizeLog2 = 1
58 };
59
60 // Helper macro to define static accessors.
61 // We use the cast to char* trick to bypass the strict anti-aliasing rules.
62 #define DECLARE_STATIC_TYPED_ACCESSOR(return_type, Name) \
63 static inline return_type Name(Instr instr) { \
64 char* temp = reinterpret_cast<char*>(&instr); \
65 return reinterpret_cast<Instruction*>(temp)->Name(); \
66 }
67
68 #define DECLARE_STATIC_ACCESSOR(Name) DECLARE_STATIC_TYPED_ACCESSOR(int, Name)
69
70 // Get the raw instruction bits.
71 inline Instr InstructionBits() const {
72 return *reinterpret_cast<const Instr*>(this);
73 }
74
75 // Set the raw instruction bits to value.
76 inline void SetInstructionBits(Instr value) {
77 *reinterpret_cast<Instr*>(this) = value;
78 }
79
80 // Read one particular bit out of the instruction bits.
81 inline int Bit(int nr) const {
82 return (InstructionBits() >> nr) & 1;
83 }
84
85 // Read a bit field's value out of the instruction bits.
86 inline int Bits(int hi, int lo) const {
87 return (InstructionBits() >> lo) & ((2 << (hi - lo)) - 1);
88 }
89
90 // Read a signed bit field's value out of the instruction bits.
91 inline int SBits(int hi, int lo) const {
92 return (Bits(hi, lo) << (sizeof(int)*8 - hi - 1)) >>
93 (sizeof(int)*8 - hi - 1);
94 }
95
96 // Read a bit field out of the instruction bits.
97 inline int BitField(int hi, int lo) const {
98 return InstructionBits() & (((2 << (hi - lo)) - 1) << lo);
99 }
100
101 // Static support.
102
103 // Read one particular bit out of the instruction bits.
104 static inline int Bit(Instr instr, int nr) {
105 return (instr >> nr) & 1;
106 }
107
108 // Read the value of a bit field out of the instruction bits.
109 static inline int Bits(Instr instr, int hi, int lo) {
110 return (instr >> lo) & ((2 << (hi - lo)) - 1);
111 }
112
113
114 // Read the value of a signed bit field out of the instruction bits.
115 inline int SBits(Instr instr, int hi, int lo) const {
116 return (Bits(instr, hi, lo) << (sizeof(int)*8 - hi - 1)) >>
117 (sizeof(int)*8 - hi - 1);
118 }
119
120 // Read a bit field out of the instruction bits.
121 static inline int BitField(Instr instr, int hi, int lo) {
122 return instr & (((2 << (hi - lo)) - 1) << lo);
123 }
124
125
126
127 // Instructions are read of out a code stream. The only way to get a
128 // reference to an instruction is to convert a pointer. There is no way
129 // to allocate or create instances of class Instruction.
130 // Use the At(pc) function to create references to Instruction.
131 static Instruction* At(byte* pc) {
132 return reinterpret_cast<Instruction*>(pc);
133 }
134
135
136 private:
137 // We need to prevent the creation of instances of class Instruction.
138 DISALLOW_IMPLICIT_CONSTRUCTORS(Instruction);
139 };
140
141
142 // Helper functions for converting between register numbers and names.
143 class Registers {
144 public:
145 // Return the name of the register.
146 static const char* Name(int reg);
147
148 // Lookup the register number for the name provided.
149 static int Number(const char* name);
150
151 struct RegisterAlias {
152 int reg;
153 const char* name;
154 };
155
156 private:
157 static const char* names_[kNumRegisters];
158 static const RegisterAlias aliases_[];
159 };
160
161
162 } } // namespace v8::internal
163
164 #endif // V8_SH4_CONSTANTS_SH4_H_
OLDNEW
« no previous file with comments | « src/sh4/codegen-sh4.cc ('k') | src/sh4/constants-sh4.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698