blob: 70a7b277656c1270406004acea282a5dca706fe8 [file] [log] [blame]
ager@chromium.org7c537e22008-10-16 08:43:32 +00001// Copyright 2006-2008 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
ager@chromium.org5ec48922009-05-05 07:25:34 +000028#ifndef V8_ARM_CODEGEN_ARM_H_
29#define V8_ARM_CODEGEN_ARM_H_
ager@chromium.org7c537e22008-10-16 08:43:32 +000030
kasperl@chromium.org71affb52009-05-26 05:44:31 +000031namespace v8 {
32namespace internal {
ager@chromium.org7c537e22008-10-16 08:43:32 +000033
34// Forward declarations
35class DeferredCode;
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000036class RegisterAllocator;
37class RegisterFile;
ager@chromium.org7c537e22008-10-16 08:43:32 +000038
ager@chromium.org3bf7b912008-11-17 09:09:45 +000039enum InitState { CONST_INIT, NOT_CONST_INIT };
40enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF };
ager@chromium.org7c537e22008-10-16 08:43:32 +000041
ager@chromium.org3bf7b912008-11-17 09:09:45 +000042
43// -------------------------------------------------------------------------
ager@chromium.org7c537e22008-10-16 08:43:32 +000044// Reference support
45
46// A reference is a C++ stack-allocated object that keeps an ECMA
47// reference on the execution stack while in scope. For variables
48// the reference is empty, indicating that it isn't necessary to
49// store state on the stack for keeping track of references to those.
50// For properties, we keep either one (named) or two (indexed) values
51// on the execution stack to represent the reference.
52
ager@chromium.org7c537e22008-10-16 08:43:32 +000053class Reference BASE_EMBEDDED {
54 public:
55 // The values of the types is important, see size().
56 enum Type { ILLEGAL = -1, SLOT = 0, NAMED = 1, KEYED = 2 };
57 Reference(CodeGenerator* cgen, Expression* expression);
58 ~Reference();
59
60 Expression* expression() const { return expression_; }
61 Type type() const { return type_; }
62 void set_type(Type value) {
63 ASSERT(type_ == ILLEGAL);
64 type_ = value;
65 }
66
ager@chromium.org3bf7b912008-11-17 09:09:45 +000067 // The size the reference takes up on the stack.
68 int size() const { return (type_ == ILLEGAL) ? 0 : type_; }
ager@chromium.org7c537e22008-10-16 08:43:32 +000069
70 bool is_illegal() const { return type_ == ILLEGAL; }
71 bool is_slot() const { return type_ == SLOT; }
72 bool is_property() const { return type_ == NAMED || type_ == KEYED; }
73
74 // Return the name. Only valid for named property references.
75 Handle<String> GetName();
76
77 // Generate code to push the value of the reference on top of the
78 // expression stack. The reference is expected to be already on top of
79 // the expression stack, and it is left in place with its value above it.
80 void GetValue(TypeofState typeof_state);
81
kasperl@chromium.org7be3c992009-03-12 07:19:55 +000082 // Generate code to push the value of a reference on top of the expression
83 // stack and then spill the stack frame. This function is used temporarily
84 // while the code generator is being transformed.
85 inline void GetValueAndSpill(TypeofState typeof_state);
86
ager@chromium.org7c537e22008-10-16 08:43:32 +000087 // Generate code to store the value on top of the expression stack in the
88 // reference. The reference is expected to be immediately below the value
89 // on the expression stack. The stored value is left in place (with the
90 // reference intact below it) to support chained assignments.
91 void SetValue(InitState init_state);
92
93 private:
94 CodeGenerator* cgen_;
95 Expression* expression_;
96 Type type_;
97};
98
99
100// -------------------------------------------------------------------------
101// Code generation state
102
103// The state is passed down the AST by the code generator (and back up, in
104// the form of the state of the label pair). It is threaded through the
105// call stack. Constructing a state implicitly pushes it on the owning code
106// generator's stack of states, and destroying one implicitly pops it.
107
108class CodeGenState BASE_EMBEDDED {
109 public:
110 // Create an initial code generator state. Destroying the initial state
111 // leaves the code generator with a NULL state.
112 explicit CodeGenState(CodeGenerator* owner);
113
114 // Create a code generator state based on a code generator's current
115 // state. The new state has its own typeof state and pair of branch
116 // labels.
117 CodeGenState(CodeGenerator* owner,
118 TypeofState typeof_state,
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000119 JumpTarget* true_target,
120 JumpTarget* false_target);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000121
122 // Destroy a code generator state and restore the owning code generator's
123 // previous state.
124 ~CodeGenState();
125
126 TypeofState typeof_state() const { return typeof_state_; }
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000127 JumpTarget* true_target() const { return true_target_; }
128 JumpTarget* false_target() const { return false_target_; }
ager@chromium.org7c537e22008-10-16 08:43:32 +0000129
130 private:
131 CodeGenerator* owner_;
132 TypeofState typeof_state_;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000133 JumpTarget* true_target_;
134 JumpTarget* false_target_;
ager@chromium.org7c537e22008-10-16 08:43:32 +0000135 CodeGenState* previous_;
136};
137
138
ager@chromium.org3bf7b912008-11-17 09:09:45 +0000139// -------------------------------------------------------------------------
ager@chromium.org7c537e22008-10-16 08:43:32 +0000140// CodeGenerator
141
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000142class CodeGenerator: public AstVisitor {
ager@chromium.org7c537e22008-10-16 08:43:32 +0000143 public:
144 // Takes a function literal, generates code for it. This function should only
145 // be called by compiler.cc.
146 static Handle<Code> MakeCode(FunctionLiteral* fun,
147 Handle<Script> script,
148 bool is_eval);
149
christian.plesner.hansen@gmail.comaca49682009-01-07 14:29:04 +0000150#ifdef ENABLE_LOGGING_AND_PROFILING
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000151 static bool ShouldGenerateLog(Expression* type);
christian.plesner.hansen@gmail.comaca49682009-01-07 14:29:04 +0000152#endif
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000153
ager@chromium.org7c537e22008-10-16 08:43:32 +0000154 static void SetFunctionInfo(Handle<JSFunction> fun,
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000155 FunctionLiteral* lit,
ager@chromium.org7c537e22008-10-16 08:43:32 +0000156 bool is_toplevel,
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000157 Handle<Script> script);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000158
159 // Accessors
160 MacroAssembler* masm() { return masm_; }
161
ager@chromium.org3bf7b912008-11-17 09:09:45 +0000162 VirtualFrame* frame() const { return frame_; }
163
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000164 bool has_valid_frame() const { return frame_ != NULL; }
165
166 // Set the virtual frame to be new_frame, with non-frame register
167 // reference counts given by non_frame_registers. The non-frame
168 // register reference counts of the old frame are returned in
169 // non_frame_registers.
170 void SetFrame(VirtualFrame* new_frame, RegisterFile* non_frame_registers);
171
172 void DeleteFrame();
173
174 RegisterAllocator* allocator() const { return allocator_; }
175
ager@chromium.org7c537e22008-10-16 08:43:32 +0000176 CodeGenState* state() { return state_; }
177 void set_state(CodeGenState* state) { state_ = state; }
178
179 void AddDeferred(DeferredCode* code) { deferred_.Add(code); }
180
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000181 static const int kUnknownIntValue = -1;
182
ager@chromium.org7c537e22008-10-16 08:43:32 +0000183 private:
184 // Construction/Destruction
185 CodeGenerator(int buffer_size, Handle<Script> script, bool is_eval);
186 virtual ~CodeGenerator() { delete masm_; }
187
188 // Accessors
189 Scope* scope() const { return scope_; }
190
sgjesse@chromium.org755c5b12009-05-29 11:04:38 +0000191 // Generating deferred code.
ager@chromium.org7c537e22008-10-16 08:43:32 +0000192 void ProcessDeferred();
193
194 bool is_eval() { return is_eval_; }
195
196 // State
197 bool has_cc() const { return cc_reg_ != al; }
198 TypeofState typeof_state() const { return state_->typeof_state(); }
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000199 JumpTarget* true_target() const { return state_->true_target(); }
200 JumpTarget* false_target() const { return state_->false_target(); }
ager@chromium.org7c537e22008-10-16 08:43:32 +0000201
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000202 // We don't track loop nesting level on ARM yet.
203 int loop_nesting() const { return 0; }
ager@chromium.org7c537e22008-10-16 08:43:32 +0000204
205 // Node visitors.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000206 void VisitStatements(ZoneList<Statement*>* statements);
207
ager@chromium.org7c537e22008-10-16 08:43:32 +0000208#define DEF_VISIT(type) \
209 void Visit##type(type* node);
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000210 AST_NODE_LIST(DEF_VISIT)
ager@chromium.org7c537e22008-10-16 08:43:32 +0000211#undef DEF_VISIT
212
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000213 // Visit a statement and then spill the virtual frame if control flow can
214 // reach the end of the statement (ie, it does not exit via break,
215 // continue, return, or throw). This function is used temporarily while
216 // the code generator is being transformed.
christian.plesner.hansen@gmail.com5a6af922009-08-12 14:20:51 +0000217 inline void VisitAndSpill(Statement* statement);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000218
219 // Visit a list of statements and then spill the virtual frame if control
220 // flow can reach the end of the list.
christian.plesner.hansen@gmail.com5a6af922009-08-12 14:20:51 +0000221 inline void VisitStatementsAndSpill(ZoneList<Statement*>* statements);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000222
ager@chromium.org7c537e22008-10-16 08:43:32 +0000223 // Main code generation function
224 void GenCode(FunctionLiteral* fun);
225
226 // The following are used by class Reference.
227 void LoadReference(Reference* ref);
228 void UnloadReference(Reference* ref);
229
ager@chromium.org7c537e22008-10-16 08:43:32 +0000230 MemOperand ContextOperand(Register context, int index) const {
231 return MemOperand(context, Context::SlotOffset(index));
232 }
233
234 MemOperand SlotOperand(Slot* slot, Register tmp);
235
ager@chromium.org381abbb2009-02-25 13:23:22 +0000236 MemOperand ContextSlotOperandCheckExtensions(Slot* slot,
237 Register tmp,
238 Register tmp2,
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000239 JumpTarget* slow);
ager@chromium.org381abbb2009-02-25 13:23:22 +0000240
ager@chromium.org7c537e22008-10-16 08:43:32 +0000241 // Expressions
242 MemOperand GlobalObject() const {
243 return ContextOperand(cp, Context::GLOBAL_INDEX);
244 }
245
246 void LoadCondition(Expression* x,
247 TypeofState typeof_state,
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000248 JumpTarget* true_target,
249 JumpTarget* false_target,
ager@chromium.org7c537e22008-10-16 08:43:32 +0000250 bool force_cc);
251 void Load(Expression* x, TypeofState typeof_state = NOT_INSIDE_TYPEOF);
252 void LoadGlobal();
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000253 void LoadGlobalReceiver(Register scratch);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000254
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000255 // Generate code to push the value of an expression on top of the frame
256 // and then spill the frame fully to memory. This function is used
257 // temporarily while the code generator is being transformed.
christian.plesner.hansen@gmail.com5a6af922009-08-12 14:20:51 +0000258 inline void LoadAndSpill(Expression* expression,
259 TypeofState typeof_state = NOT_INSIDE_TYPEOF);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000260
261 // Call LoadCondition and then spill the virtual frame unless control flow
262 // cannot reach the end of the expression (ie, by emitting only
263 // unconditional jumps to the control targets).
christian.plesner.hansen@gmail.com5a6af922009-08-12 14:20:51 +0000264 inline void LoadConditionAndSpill(Expression* expression,
265 TypeofState typeof_state,
266 JumpTarget* true_target,
267 JumpTarget* false_target,
268 bool force_control);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000269
ager@chromium.org7c537e22008-10-16 08:43:32 +0000270 // Read a value from a slot and leave it on top of the expression stack.
271 void LoadFromSlot(Slot* slot, TypeofState typeof_state);
ager@chromium.org381abbb2009-02-25 13:23:22 +0000272 void LoadFromGlobalSlotCheckExtensions(Slot* slot,
273 TypeofState typeof_state,
274 Register tmp,
275 Register tmp2,
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000276 JumpTarget* slow);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000277
278 // Special code for typeof expressions: Unfortunately, we must
279 // be careful when loading the expression in 'typeof'
280 // expressions. We are not allowed to throw reference errors for
281 // non-existing properties of the global object, so we must make it
282 // look like an explicit property access, instead of an access
283 // through the context chain.
284 void LoadTypeofExpression(Expression* x);
285
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000286 void ToBoolean(JumpTarget* true_target, JumpTarget* false_target);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000287
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000288 void GenericBinaryOperation(Token::Value op,
289 OverwriteMode overwrite_mode,
290 int known_rhs = kUnknownIntValue);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000291 void Comparison(Condition cc,
292 Expression* left,
293 Expression* right,
294 bool strict = false);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000295
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000296 void SmiOperation(Token::Value op,
297 Handle<Object> value,
298 bool reversed,
299 OverwriteMode mode);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000300
301 void CallWithArguments(ZoneList<Expression*>* arguments, int position);
302
303 // Control flow
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000304 void Branch(bool if_true, JumpTarget* target);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000305 void CheckStack();
ager@chromium.org7c537e22008-10-16 08:43:32 +0000306
ager@chromium.org9085a012009-05-11 19:22:57 +0000307 struct InlineRuntimeLUT {
308 void (CodeGenerator::*method)(ZoneList<Expression*>*);
309 const char* name;
310 };
311
312 static InlineRuntimeLUT* FindInlineRuntimeLUT(Handle<String> name);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000313 bool CheckForInlineRuntimeCall(CallRuntime* node);
ager@chromium.org9085a012009-05-11 19:22:57 +0000314 static bool PatchInlineRuntimeEntry(Handle<String> name,
315 const InlineRuntimeLUT& new_entry,
316 InlineRuntimeLUT* old_entry);
317
ager@chromium.org7c537e22008-10-16 08:43:32 +0000318 Handle<JSFunction> BuildBoilerplate(FunctionLiteral* node);
319 void ProcessDeclarations(ZoneList<Declaration*>* declarations);
320
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000321 Handle<Code> ComputeCallInitialize(int argc, InLoopFlag in_loop);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000322
323 // Declare global variables and functions in the given array of
324 // name/value pairs.
325 void DeclareGlobals(Handle<FixedArray> pairs);
326
327 // Instantiate the function boilerplate.
328 void InstantiateBoilerplate(Handle<JSFunction> boilerplate);
329
330 // Support for type checks.
331 void GenerateIsSmi(ZoneList<Expression*>* args);
332 void GenerateIsNonNegativeSmi(ZoneList<Expression*>* args);
333 void GenerateIsArray(ZoneList<Expression*>* args);
334
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000335 // Support for construct call checks.
336 void GenerateIsConstructCall(ZoneList<Expression*>* args);
337
ager@chromium.org7c537e22008-10-16 08:43:32 +0000338 // Support for arguments.length and arguments[?].
339 void GenerateArgumentsLength(ZoneList<Expression*>* args);
340 void GenerateArgumentsAccess(ZoneList<Expression*>* args);
341
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000342 // Support for accessing the class and value fields of an object.
343 void GenerateClassOf(ZoneList<Expression*>* args);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000344 void GenerateValueOf(ZoneList<Expression*>* args);
345 void GenerateSetValueOf(ZoneList<Expression*>* args);
346
347 // Fast support for charCodeAt(n).
348 void GenerateFastCharCodeAt(ZoneList<Expression*>* args);
349
350 // Fast support for object equality testing.
351 void GenerateObjectEquals(ZoneList<Expression*>* args);
352
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000353 void GenerateLog(ZoneList<Expression*>* args);
354
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000355 // Fast support for Math.random().
356 void GenerateRandomPositiveSmi(ZoneList<Expression*>* args);
357
358 // Fast support for Math.sin and Math.cos.
359 enum MathOp { SIN, COS };
360 void GenerateFastMathOp(MathOp op, ZoneList<Expression*>* args);
361 inline void GenerateMathSin(ZoneList<Expression*>* args);
362 inline void GenerateMathCos(ZoneList<Expression*>* args);
363
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000364 // Methods used to indicate which source code is generated for. Source
365 // positions are collected by the assembler and emitted with the relocation
366 // information.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000367 void CodeForFunctionPosition(FunctionLiteral* fun);
kasperl@chromium.org8ccb0be2009-04-07 07:21:39 +0000368 void CodeForReturnPosition(FunctionLiteral* fun);
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000369 void CodeForStatementPosition(AstNode* node);
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000370 void CodeForSourcePosition(int pos);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000371
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000372#ifdef DEBUG
373 // True if the registers are valid for entry to a block.
374 bool HasValidEntryRegisters();
375#endif
376
ager@chromium.org7c537e22008-10-16 08:43:32 +0000377 bool is_eval_; // Tells whether code is generated for eval.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000378
ager@chromium.org7c537e22008-10-16 08:43:32 +0000379 Handle<Script> script_;
380 List<DeferredCode*> deferred_;
381
382 // Assembler
383 MacroAssembler* masm_; // to generate code
384
385 // Code generation state
386 Scope* scope_;
ager@chromium.org3bf7b912008-11-17 09:09:45 +0000387 VirtualFrame* frame_;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000388 RegisterAllocator* allocator_;
ager@chromium.org7c537e22008-10-16 08:43:32 +0000389 Condition cc_reg_;
390 CodeGenState* state_;
ager@chromium.org7c537e22008-10-16 08:43:32 +0000391
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000392 // Jump targets
393 BreakTarget function_return_;
394
395 // True if the function return is shadowed (ie, jumping to the target
396 // function_return_ does not jump to the true function return, but rather
397 // to some unlinking code).
398 bool function_return_is_shadowed_;
399
ager@chromium.org9085a012009-05-11 19:22:57 +0000400 static InlineRuntimeLUT kInlineRuntimeLUT[];
401
ager@chromium.org3bf7b912008-11-17 09:09:45 +0000402 friend class VirtualFrame;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000403 friend class JumpTarget;
ager@chromium.org7c537e22008-10-16 08:43:32 +0000404 friend class Reference;
ager@chromium.org7c537e22008-10-16 08:43:32 +0000405
406 DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
407};
408
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000409
christian.plesner.hansen@gmail.com5a6af922009-08-12 14:20:51 +0000410class GenericBinaryOpStub : public CodeStub {
411 public:
412 GenericBinaryOpStub(Token::Value op,
413 OverwriteMode mode,
414 int constant_rhs = CodeGenerator::kUnknownIntValue)
415 : op_(op),
416 mode_(mode),
417 constant_rhs_(constant_rhs),
418 specialized_on_rhs_(RhsIsOneWeWantToOptimizeFor(op, constant_rhs)) { }
419
420 private:
421 Token::Value op_;
422 OverwriteMode mode_;
423 int constant_rhs_;
424 bool specialized_on_rhs_;
425
426 static const int kMaxKnownRhs = 0x40000000;
427
428 // Minor key encoding in 16 bits.
429 class ModeBits: public BitField<OverwriteMode, 0, 2> {};
430 class OpBits: public BitField<Token::Value, 2, 6> {};
431 class KnownIntBits: public BitField<int, 8, 8> {};
432
433 Major MajorKey() { return GenericBinaryOp; }
434 int MinorKey() {
435 // Encode the parameters in a unique 16 bit value.
436 return OpBits::encode(op_)
437 | ModeBits::encode(mode_)
438 | KnownIntBits::encode(MinorKeyForKnownInt());
439 }
440
441 void Generate(MacroAssembler* masm);
442 void HandleNonSmiBitwiseOp(MacroAssembler* masm);
443
444 static bool RhsIsOneWeWantToOptimizeFor(Token::Value op, int constant_rhs) {
445 if (constant_rhs == CodeGenerator::kUnknownIntValue) return false;
446 if (op == Token::DIV) return constant_rhs >= 2 && constant_rhs <= 3;
447 if (op == Token::MOD) {
448 if (constant_rhs <= 1) return false;
449 if (constant_rhs <= 10) return true;
450 if (constant_rhs <= kMaxKnownRhs && IsPowerOf2(constant_rhs)) return true;
451 return false;
452 }
453 return false;
454 }
455
456 int MinorKeyForKnownInt() {
457 if (!specialized_on_rhs_) return 0;
458 if (constant_rhs_ <= 10) return constant_rhs_ + 1;
459 ASSERT(IsPowerOf2(constant_rhs_));
460 int key = 12;
461 int d = constant_rhs_;
462 while ((d & 1) == 0) {
463 key++;
464 d >>= 1;
465 }
466 return key;
467 }
468
469 const char* GetName() {
470 switch (op_) {
471 case Token::ADD: return "GenericBinaryOpStub_ADD";
472 case Token::SUB: return "GenericBinaryOpStub_SUB";
473 case Token::MUL: return "GenericBinaryOpStub_MUL";
474 case Token::DIV: return "GenericBinaryOpStub_DIV";
475 case Token::MOD: return "GenericBinaryOpStub_MOD";
476 case Token::BIT_OR: return "GenericBinaryOpStub_BIT_OR";
477 case Token::BIT_AND: return "GenericBinaryOpStub_BIT_AND";
478 case Token::BIT_XOR: return "GenericBinaryOpStub_BIT_XOR";
479 case Token::SAR: return "GenericBinaryOpStub_SAR";
480 case Token::SHL: return "GenericBinaryOpStub_SHL";
481 case Token::SHR: return "GenericBinaryOpStub_SHR";
482 default: return "GenericBinaryOpStub";
483 }
484 }
485
486#ifdef DEBUG
487 void Print() {
488 if (!specialized_on_rhs_) {
489 PrintF("GenericBinaryOpStub (%s)\n", Token::String(op_));
490 } else {
491 PrintF("GenericBinaryOpStub (%s by %d)\n",
492 Token::String(op_),
493 constant_rhs_);
494 }
495 }
496#endif
497};
498
499
ager@chromium.org7c537e22008-10-16 08:43:32 +0000500} } // namespace v8::internal
501
ager@chromium.org5ec48922009-05-05 07:25:34 +0000502#endif // V8_ARM_CODEGEN_ARM_H_