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

Side by Side Diff: src/ia32/code-stubs-ia32.h

Issue 3195022: Move code stubs from codegen*.* files to code-stub*.* files. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 3 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/arm/ic-arm.cc ('k') | src/ia32/code-stubs-ia32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright 2010 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_IA32_CODE_STUBS_IA32_H_
29 #define V8_IA32_CODE_STUBS_IA32_H_
30
31 #include "codegen-inl.h"
32 #include "ast.h"
33 #include "ic-inl.h"
34
35 namespace v8 {
36 namespace internal {
37
38
39 // Compute a transcendental math function natively, or call the
40 // TranscendentalCache runtime function.
41 class TranscendentalCacheStub: public CodeStub {
42 public:
43 explicit TranscendentalCacheStub(TranscendentalCache::Type type)
44 : type_(type) {}
45 void Generate(MacroAssembler* masm);
46 private:
47 TranscendentalCache::Type type_;
48 Major MajorKey() { return TranscendentalCache; }
49 int MinorKey() { return type_; }
50 Runtime::FunctionId RuntimeFunction();
51 void GenerateOperation(MacroAssembler* masm);
52 };
53
54
55 class ToBooleanStub: public CodeStub {
56 public:
57 ToBooleanStub() { }
58
59 void Generate(MacroAssembler* masm);
60
61 private:
62 Major MajorKey() { return ToBoolean; }
63 int MinorKey() { return 0; }
64 };
65
66
67 // Flag that indicates how to generate code for the stub GenericBinaryOpStub.
68 enum GenericBinaryFlags {
69 NO_GENERIC_BINARY_FLAGS = 0,
70 NO_SMI_CODE_IN_STUB = 1 << 0 // Omit smi code in stub.
71 };
72
73
74 class GenericBinaryOpStub: public CodeStub {
75 public:
76 GenericBinaryOpStub(Token::Value op,
77 OverwriteMode mode,
78 GenericBinaryFlags flags,
79 TypeInfo operands_type)
80 : op_(op),
81 mode_(mode),
82 flags_(flags),
83 args_in_registers_(false),
84 args_reversed_(false),
85 static_operands_type_(operands_type),
86 runtime_operands_type_(BinaryOpIC::DEFAULT),
87 name_(NULL) {
88 if (static_operands_type_.IsSmi()) {
89 mode_ = NO_OVERWRITE;
90 }
91 use_sse3_ = CpuFeatures::IsSupported(SSE3);
92 ASSERT(OpBits::is_valid(Token::NUM_TOKENS));
93 }
94
95 GenericBinaryOpStub(int key, BinaryOpIC::TypeInfo runtime_operands_type)
96 : op_(OpBits::decode(key)),
97 mode_(ModeBits::decode(key)),
98 flags_(FlagBits::decode(key)),
99 args_in_registers_(ArgsInRegistersBits::decode(key)),
100 args_reversed_(ArgsReversedBits::decode(key)),
101 use_sse3_(SSE3Bits::decode(key)),
102 static_operands_type_(TypeInfo::ExpandedRepresentation(
103 StaticTypeInfoBits::decode(key))),
104 runtime_operands_type_(runtime_operands_type),
105 name_(NULL) {
106 }
107
108 // Generate code to call the stub with the supplied arguments. This will add
109 // code at the call site to prepare arguments either in registers or on the
110 // stack together with the actual call.
111 void GenerateCall(MacroAssembler* masm, Register left, Register right);
112 void GenerateCall(MacroAssembler* masm, Register left, Smi* right);
113 void GenerateCall(MacroAssembler* masm, Smi* left, Register right);
114
115 Result GenerateCall(MacroAssembler* masm,
116 VirtualFrame* frame,
117 Result* left,
118 Result* right);
119
120 private:
121 Token::Value op_;
122 OverwriteMode mode_;
123 GenericBinaryFlags flags_;
124 bool args_in_registers_; // Arguments passed in registers not on the stack.
125 bool args_reversed_; // Left and right argument are swapped.
126 bool use_sse3_;
127
128 // Number type information of operands, determined by code generator.
129 TypeInfo static_operands_type_;
130
131 // Operand type information determined at runtime.
132 BinaryOpIC::TypeInfo runtime_operands_type_;
133
134 char* name_;
135
136 const char* GetName();
137
138 #ifdef DEBUG
139 void Print() {
140 PrintF("GenericBinaryOpStub %d (op %s), "
141 "(mode %d, flags %d, registers %d, reversed %d, type_info %s)\n",
142 MinorKey(),
143 Token::String(op_),
144 static_cast<int>(mode_),
145 static_cast<int>(flags_),
146 static_cast<int>(args_in_registers_),
147 static_cast<int>(args_reversed_),
148 static_operands_type_.ToString());
149 }
150 #endif
151
152 // Minor key encoding in 18 bits RRNNNFRASOOOOOOOMM.
153 class ModeBits: public BitField<OverwriteMode, 0, 2> {};
154 class OpBits: public BitField<Token::Value, 2, 7> {};
155 class SSE3Bits: public BitField<bool, 9, 1> {};
156 class ArgsInRegistersBits: public BitField<bool, 10, 1> {};
157 class ArgsReversedBits: public BitField<bool, 11, 1> {};
158 class FlagBits: public BitField<GenericBinaryFlags, 12, 1> {};
159 class StaticTypeInfoBits: public BitField<int, 13, 3> {};
160 class RuntimeTypeInfoBits: public BitField<BinaryOpIC::TypeInfo, 16, 2> {};
161
162 Major MajorKey() { return GenericBinaryOp; }
163 int MinorKey() {
164 // Encode the parameters in a unique 18 bit value.
165 return OpBits::encode(op_)
166 | ModeBits::encode(mode_)
167 | FlagBits::encode(flags_)
168 | SSE3Bits::encode(use_sse3_)
169 | ArgsInRegistersBits::encode(args_in_registers_)
170 | ArgsReversedBits::encode(args_reversed_)
171 | StaticTypeInfoBits::encode(
172 static_operands_type_.ThreeBitRepresentation())
173 | RuntimeTypeInfoBits::encode(runtime_operands_type_);
174 }
175
176 void Generate(MacroAssembler* masm);
177 void GenerateSmiCode(MacroAssembler* masm, Label* slow);
178 void GenerateLoadArguments(MacroAssembler* masm);
179 void GenerateReturn(MacroAssembler* masm);
180 void GenerateHeapResultAllocation(MacroAssembler* masm, Label* alloc_failure);
181 void GenerateRegisterArgsPush(MacroAssembler* masm);
182 void GenerateTypeTransition(MacroAssembler* masm);
183
184 bool ArgsInRegistersSupported() {
185 return op_ == Token::ADD || op_ == Token::SUB
186 || op_ == Token::MUL || op_ == Token::DIV;
187 }
188 bool IsOperationCommutative() {
189 return (op_ == Token::ADD) || (op_ == Token::MUL);
190 }
191
192 void SetArgsInRegisters() { args_in_registers_ = true; }
193 void SetArgsReversed() { args_reversed_ = true; }
194 bool HasSmiCodeInStub() { return (flags_ & NO_SMI_CODE_IN_STUB) == 0; }
195 bool HasArgsInRegisters() { return args_in_registers_; }
196 bool HasArgsReversed() { return args_reversed_; }
197
198 bool ShouldGenerateSmiCode() {
199 return HasSmiCodeInStub() &&
200 runtime_operands_type_ != BinaryOpIC::HEAP_NUMBERS &&
201 runtime_operands_type_ != BinaryOpIC::STRINGS;
202 }
203
204 bool ShouldGenerateFPCode() {
205 return runtime_operands_type_ != BinaryOpIC::STRINGS;
206 }
207
208 virtual int GetCodeKind() { return Code::BINARY_OP_IC; }
209
210 virtual InlineCacheState GetICState() {
211 return BinaryOpIC::ToState(runtime_operands_type_);
212 }
213 };
214
215
216 class StringHelper : public AllStatic {
217 public:
218 // Generate code for copying characters using a simple loop. This should only
219 // be used in places where the number of characters is small and the
220 // additional setup and checking in GenerateCopyCharactersREP adds too much
221 // overhead. Copying of overlapping regions is not supported.
222 static void GenerateCopyCharacters(MacroAssembler* masm,
223 Register dest,
224 Register src,
225 Register count,
226 Register scratch,
227 bool ascii);
228
229 // Generate code for copying characters using the rep movs instruction.
230 // Copies ecx characters from esi to edi. Copying of overlapping regions is
231 // not supported.
232 static void GenerateCopyCharactersREP(MacroAssembler* masm,
233 Register dest, // Must be edi.
234 Register src, // Must be esi.
235 Register count, // Must be ecx.
236 Register scratch, // Neither of above.
237 bool ascii);
238
239 // Probe the symbol table for a two character string. If the string is
240 // not found by probing a jump to the label not_found is performed. This jump
241 // does not guarantee that the string is not in the symbol table. If the
242 // string is found the code falls through with the string in register eax.
243 static void GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm,
244 Register c1,
245 Register c2,
246 Register scratch1,
247 Register scratch2,
248 Register scratch3,
249 Label* not_found);
250
251 // Generate string hash.
252 static void GenerateHashInit(MacroAssembler* masm,
253 Register hash,
254 Register character,
255 Register scratch);
256 static void GenerateHashAddCharacter(MacroAssembler* masm,
257 Register hash,
258 Register character,
259 Register scratch);
260 static void GenerateHashGetHash(MacroAssembler* masm,
261 Register hash,
262 Register scratch);
263
264 private:
265 DISALLOW_IMPLICIT_CONSTRUCTORS(StringHelper);
266 };
267
268
269 // Flag that indicates how to generate code for the stub StringAddStub.
270 enum StringAddFlags {
271 NO_STRING_ADD_FLAGS = 0,
272 NO_STRING_CHECK_IN_STUB = 1 << 0 // Omit string check in stub.
273 };
274
275
276 class StringAddStub: public CodeStub {
277 public:
278 explicit StringAddStub(StringAddFlags flags) {
279 string_check_ = ((flags & NO_STRING_CHECK_IN_STUB) == 0);
280 }
281
282 private:
283 Major MajorKey() { return StringAdd; }
284 int MinorKey() { return string_check_ ? 0 : 1; }
285
286 void Generate(MacroAssembler* masm);
287
288 // Should the stub check whether arguments are strings?
289 bool string_check_;
290 };
291
292
293 class SubStringStub: public CodeStub {
294 public:
295 SubStringStub() {}
296
297 private:
298 Major MajorKey() { return SubString; }
299 int MinorKey() { return 0; }
300
301 void Generate(MacroAssembler* masm);
302 };
303
304
305 class StringCompareStub: public CodeStub {
306 public:
307 explicit StringCompareStub() {
308 }
309
310 // Compare two flat ascii strings and returns result in eax after popping two
311 // arguments from the stack.
312 static void GenerateCompareFlatAsciiStrings(MacroAssembler* masm,
313 Register left,
314 Register right,
315 Register scratch1,
316 Register scratch2,
317 Register scratch3);
318
319 private:
320 Major MajorKey() { return StringCompare; }
321 int MinorKey() { return 0; }
322
323 void Generate(MacroAssembler* masm);
324 };
325
326
327 class NumberToStringStub: public CodeStub {
328 public:
329 NumberToStringStub() { }
330
331 // Generate code to do a lookup in the number string cache. If the number in
332 // the register object is found in the cache the generated code falls through
333 // with the result in the result register. The object and the result register
334 // can be the same. If the number is not found in the cache the code jumps to
335 // the label not_found with only the content of register object unchanged.
336 static void GenerateLookupNumberStringCache(MacroAssembler* masm,
337 Register object,
338 Register result,
339 Register scratch1,
340 Register scratch2,
341 bool object_is_smi,
342 Label* not_found);
343
344 private:
345 Major MajorKey() { return NumberToString; }
346 int MinorKey() { return 0; }
347
348 void Generate(MacroAssembler* masm);
349
350 const char* GetName() { return "NumberToStringStub"; }
351
352 #ifdef DEBUG
353 void Print() {
354 PrintF("NumberToStringStub\n");
355 }
356 #endif
357 };
358
359
360 } } // namespace v8::internal
361
362 #endif // V8_IA32_CODE_STUBS_IA32_H_
OLDNEW
« no previous file with comments | « src/arm/ic-arm.cc ('k') | src/ia32/code-stubs-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698