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

Side by Side Diff: src/x64/code-stubs-x64.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, 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/ia32/full-codegen-ia32.cc ('k') | src/x64/code-stubs-x64.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_X64_CODE_STUBS_X64_H_
29 #define V8_X64_CODE_STUBS_X64_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, Label* on_nan_result);
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 = TypeInfo::Unknown())
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 ASSERT(OpBits::is_valid(Token::NUM_TOKENS));
89 }
90
91 GenericBinaryOpStub(int key, BinaryOpIC::TypeInfo type_info)
92 : op_(OpBits::decode(key)),
93 mode_(ModeBits::decode(key)),
94 flags_(FlagBits::decode(key)),
95 args_in_registers_(ArgsInRegistersBits::decode(key)),
96 args_reversed_(ArgsReversedBits::decode(key)),
97 static_operands_type_(TypeInfo::ExpandedRepresentation(
98 StaticTypeInfoBits::decode(key))),
99 runtime_operands_type_(type_info),
100 name_(NULL) {
101 }
102
103 // Generate code to call the stub with the supplied arguments. This will add
104 // code at the call site to prepare arguments either in registers or on the
105 // stack together with the actual call.
106 void GenerateCall(MacroAssembler* masm, Register left, Register right);
107 void GenerateCall(MacroAssembler* masm, Register left, Smi* right);
108 void GenerateCall(MacroAssembler* masm, Smi* left, Register right);
109
110 Result GenerateCall(MacroAssembler* masm,
111 VirtualFrame* frame,
112 Result* left,
113 Result* right);
114
115 private:
116 Token::Value op_;
117 OverwriteMode mode_;
118 GenericBinaryFlags flags_;
119 bool args_in_registers_; // Arguments passed in registers not on the stack.
120 bool args_reversed_; // Left and right argument are swapped.
121
122 // Number type information of operands, determined by code generator.
123 TypeInfo static_operands_type_;
124
125 // Operand type information determined at runtime.
126 BinaryOpIC::TypeInfo runtime_operands_type_;
127
128 char* name_;
129
130 const char* GetName();
131
132 #ifdef DEBUG
133 void Print() {
134 PrintF("GenericBinaryOpStub %d (op %s), "
135 "(mode %d, flags %d, registers %d, reversed %d, only_numbers %s)\n",
136 MinorKey(),
137 Token::String(op_),
138 static_cast<int>(mode_),
139 static_cast<int>(flags_),
140 static_cast<int>(args_in_registers_),
141 static_cast<int>(args_reversed_),
142 static_operands_type_.ToString());
143 }
144 #endif
145
146 // Minor key encoding in 17 bits TTNNNFRAOOOOOOOMM.
147 class ModeBits: public BitField<OverwriteMode, 0, 2> {};
148 class OpBits: public BitField<Token::Value, 2, 7> {};
149 class ArgsInRegistersBits: public BitField<bool, 9, 1> {};
150 class ArgsReversedBits: public BitField<bool, 10, 1> {};
151 class FlagBits: public BitField<GenericBinaryFlags, 11, 1> {};
152 class StaticTypeInfoBits: public BitField<int, 12, 3> {};
153 class RuntimeTypeInfoBits: public BitField<BinaryOpIC::TypeInfo, 15, 2> {};
154
155 Major MajorKey() { return GenericBinaryOp; }
156 int MinorKey() {
157 // Encode the parameters in a unique 18 bit value.
158 return OpBits::encode(op_)
159 | ModeBits::encode(mode_)
160 | FlagBits::encode(flags_)
161 | ArgsInRegistersBits::encode(args_in_registers_)
162 | ArgsReversedBits::encode(args_reversed_)
163 | StaticTypeInfoBits::encode(
164 static_operands_type_.ThreeBitRepresentation())
165 | RuntimeTypeInfoBits::encode(runtime_operands_type_);
166 }
167
168 void Generate(MacroAssembler* masm);
169 void GenerateSmiCode(MacroAssembler* masm, Label* slow);
170 void GenerateLoadArguments(MacroAssembler* masm);
171 void GenerateReturn(MacroAssembler* masm);
172 void GenerateRegisterArgsPush(MacroAssembler* masm);
173 void GenerateTypeTransition(MacroAssembler* masm);
174
175 bool ArgsInRegistersSupported() {
176 return (op_ == Token::ADD) || (op_ == Token::SUB)
177 || (op_ == Token::MUL) || (op_ == Token::DIV);
178 }
179 bool IsOperationCommutative() {
180 return (op_ == Token::ADD) || (op_ == Token::MUL);
181 }
182
183 void SetArgsInRegisters() { args_in_registers_ = true; }
184 void SetArgsReversed() { args_reversed_ = true; }
185 bool HasSmiCodeInStub() { return (flags_ & NO_SMI_CODE_IN_STUB) == 0; }
186 bool HasArgsInRegisters() { return args_in_registers_; }
187 bool HasArgsReversed() { return args_reversed_; }
188
189 bool ShouldGenerateSmiCode() {
190 return HasSmiCodeInStub() &&
191 runtime_operands_type_ != BinaryOpIC::HEAP_NUMBERS &&
192 runtime_operands_type_ != BinaryOpIC::STRINGS;
193 }
194
195 bool ShouldGenerateFPCode() {
196 return runtime_operands_type_ != BinaryOpIC::STRINGS;
197 }
198
199 virtual int GetCodeKind() { return Code::BINARY_OP_IC; }
200
201 virtual InlineCacheState GetICState() {
202 return BinaryOpIC::ToState(runtime_operands_type_);
203 }
204 };
205
206 class StringHelper : public AllStatic {
207 public:
208 // Generate code for copying characters using a simple loop. This should only
209 // be used in places where the number of characters is small and the
210 // additional setup and checking in GenerateCopyCharactersREP adds too much
211 // overhead. Copying of overlapping regions is not supported.
212 static void GenerateCopyCharacters(MacroAssembler* masm,
213 Register dest,
214 Register src,
215 Register count,
216 bool ascii);
217
218 // Generate code for copying characters using the rep movs instruction.
219 // Copies rcx characters from rsi to rdi. Copying of overlapping regions is
220 // not supported.
221 static void GenerateCopyCharactersREP(MacroAssembler* masm,
222 Register dest, // Must be rdi.
223 Register src, // Must be rsi.
224 Register count, // Must be rcx.
225 bool ascii);
226
227
228 // Probe the symbol table for a two character string. If the string is
229 // not found by probing a jump to the label not_found is performed. This jump
230 // does not guarantee that the string is not in the symbol table. If the
231 // string is found the code falls through with the string in register rax.
232 static void GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm,
233 Register c1,
234 Register c2,
235 Register scratch1,
236 Register scratch2,
237 Register scratch3,
238 Register scratch4,
239 Label* not_found);
240
241 // Generate string hash.
242 static void GenerateHashInit(MacroAssembler* masm,
243 Register hash,
244 Register character,
245 Register scratch);
246 static void GenerateHashAddCharacter(MacroAssembler* masm,
247 Register hash,
248 Register character,
249 Register scratch);
250 static void GenerateHashGetHash(MacroAssembler* masm,
251 Register hash,
252 Register scratch);
253
254 private:
255 DISALLOW_IMPLICIT_CONSTRUCTORS(StringHelper);
256 };
257
258
259 // Flag that indicates how to generate code for the stub StringAddStub.
260 enum StringAddFlags {
261 NO_STRING_ADD_FLAGS = 0,
262 NO_STRING_CHECK_IN_STUB = 1 << 0 // Omit string check in stub.
263 };
264
265
266 class StringAddStub: public CodeStub {
267 public:
268 explicit StringAddStub(StringAddFlags flags) {
269 string_check_ = ((flags & NO_STRING_CHECK_IN_STUB) == 0);
270 }
271
272 private:
273 Major MajorKey() { return StringAdd; }
274 int MinorKey() { return string_check_ ? 0 : 1; }
275
276 void Generate(MacroAssembler* masm);
277
278 // Should the stub check whether arguments are strings?
279 bool string_check_;
280 };
281
282
283 class SubStringStub: public CodeStub {
284 public:
285 SubStringStub() {}
286
287 private:
288 Major MajorKey() { return SubString; }
289 int MinorKey() { return 0; }
290
291 void Generate(MacroAssembler* masm);
292 };
293
294
295 class StringCompareStub: public CodeStub {
296 public:
297 explicit StringCompareStub() {}
298
299 // Compare two flat ascii strings and returns result in rax after popping two
300 // arguments from the stack.
301 static void GenerateCompareFlatAsciiStrings(MacroAssembler* masm,
302 Register left,
303 Register right,
304 Register scratch1,
305 Register scratch2,
306 Register scratch3,
307 Register scratch4);
308
309 private:
310 Major MajorKey() { return StringCompare; }
311 int MinorKey() { return 0; }
312
313 void Generate(MacroAssembler* masm);
314 };
315
316
317 class NumberToStringStub: public CodeStub {
318 public:
319 NumberToStringStub() { }
320
321 // Generate code to do a lookup in the number string cache. If the number in
322 // the register object is found in the cache the generated code falls through
323 // with the result in the result register. The object and the result register
324 // can be the same. If the number is not found in the cache the code jumps to
325 // the label not_found with only the content of register object unchanged.
326 static void GenerateLookupNumberStringCache(MacroAssembler* masm,
327 Register object,
328 Register result,
329 Register scratch1,
330 Register scratch2,
331 bool object_is_smi,
332 Label* not_found);
333
334 private:
335 static void GenerateConvertHashCodeToIndex(MacroAssembler* masm,
336 Register hash,
337 Register mask);
338
339 Major MajorKey() { return NumberToString; }
340 int MinorKey() { return 0; }
341
342 void Generate(MacroAssembler* masm);
343
344 const char* GetName() { return "NumberToStringStub"; }
345
346 #ifdef DEBUG
347 void Print() {
348 PrintF("NumberToStringStub\n");
349 }
350 #endif
351 };
352
353
354 class RecordWriteStub : public CodeStub {
355 public:
356 RecordWriteStub(Register object, Register addr, Register scratch)
357 : object_(object), addr_(addr), scratch_(scratch) { }
358
359 void Generate(MacroAssembler* masm);
360
361 private:
362 Register object_;
363 Register addr_;
364 Register scratch_;
365
366 #ifdef DEBUG
367 void Print() {
368 PrintF("RecordWriteStub (object reg %d), (addr reg %d), (scratch reg %d)\n",
369 object_.code(), addr_.code(), scratch_.code());
370 }
371 #endif
372
373 // Minor key encoding in 12 bits. 4 bits for each of the three
374 // registers (object, address and scratch) OOOOAAAASSSS.
375 class ScratchBits : public BitField<uint32_t, 0, 4> {};
376 class AddressBits : public BitField<uint32_t, 4, 4> {};
377 class ObjectBits : public BitField<uint32_t, 8, 4> {};
378
379 Major MajorKey() { return RecordWrite; }
380
381 int MinorKey() {
382 // Encode the registers.
383 return ObjectBits::encode(object_.code()) |
384 AddressBits::encode(addr_.code()) |
385 ScratchBits::encode(scratch_.code());
386 }
387 };
388
389
390 } } // namespace v8::internal
391
392 #endif // V8_X64_CODE_STUBS_X64_H_
OLDNEW
« no previous file with comments | « src/ia32/full-codegen-ia32.cc ('k') | src/x64/code-stubs-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698