blob: cec20fca073add3d9b77a7f4aa4d873b4df184d9 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright (c) 1994-2006 Sun Microsystems Inc.
2// All Rights Reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// - Redistributions of source code must retain the above copyright notice,
9// this list of conditions and the following disclaimer.
10//
11// - Redistribution in binary form must reproduce the above copyright
12// notice, this list of conditions and the following disclaimer in the
13// documentation and/or other materials provided with the distribution.
14//
15// - Neither the name of Sun Microsystems or the names of contributors may
16// be used to endorse or promote products derived from this software without
17// specific prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31// The original source code covered by the above license above has been
32// modified significantly by Google Inc.
Ben Murdoch8b112d22011-06-08 16:22:53 +010033// Copyright 2011 the V8 project authors. All rights reserved.
Steve Blocka7e24c12009-10-30 11:49:00 +000034
35#ifndef V8_ASSEMBLER_H_
36#define V8_ASSEMBLER_H_
37
Ben Murdoch257744e2011-11-30 15:57:28 +000038#include "allocation.h"
Ben Murdochb8e0da22011-05-16 14:20:40 +010039#include "gdb-jit.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000040#include "runtime.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000041#include "token.h"
42
43namespace v8 {
44namespace internal {
45
Ben Murdoch257744e2011-11-30 15:57:28 +000046const unsigned kNoASTId = -1;
Steve Blocka7e24c12009-10-30 11:49:00 +000047// -----------------------------------------------------------------------------
Steve Block44f0eee2011-05-26 01:26:41 +010048// Platform independent assembler base class.
49
50class AssemblerBase: public Malloced {
51 public:
Steve Block053d10c2011-06-13 19:13:29 +010052 explicit AssemblerBase(Isolate* isolate);
Steve Block44f0eee2011-05-26 01:26:41 +010053
54 Isolate* isolate() const { return isolate_; }
Steve Block053d10c2011-06-13 19:13:29 +010055 int jit_cookie() { return jit_cookie_; }
Steve Block44f0eee2011-05-26 01:26:41 +010056
57 private:
58 Isolate* isolate_;
Steve Block053d10c2011-06-13 19:13:29 +010059 int jit_cookie_;
Steve Block44f0eee2011-05-26 01:26:41 +010060};
61
62// -----------------------------------------------------------------------------
Ben Murdochb0fe1622011-05-05 13:52:32 +010063// Common double constants.
64
65class DoubleConstant: public AllStatic {
66 public:
67 static const double min_int;
68 static const double one_half;
Ben Murdochb8e0da22011-05-16 14:20:40 +010069 static const double minus_zero;
Ben Murdoch257744e2011-11-30 15:57:28 +000070 static const double zero;
71 static const double uint8_max_value;
Ben Murdochb0fe1622011-05-05 13:52:32 +010072 static const double negative_infinity;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000073 static const double canonical_non_hole_nan;
74 static const double the_hole_nan;
Ben Murdochb0fe1622011-05-05 13:52:32 +010075};
76
77
78// -----------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +000079// Labels represent pc locations; they are typically jump or call targets.
80// After declaration, a label can be freely used to denote known or (yet)
81// unknown pc location. Assembler::bind() is used to bind a label to the
82// current pc. A label can be bound only once.
83
84class Label BASE_EMBEDDED {
85 public:
Ben Murdoch257744e2011-11-30 15:57:28 +000086 enum Distance {
87 kNear, kFar
88 };
89
90 INLINE(Label()) {
91 Unuse();
92 UnuseNear();
93 }
Steve Blocka7e24c12009-10-30 11:49:00 +000094
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000095 INLINE(~Label()) {
96 ASSERT(!is_linked());
97 ASSERT(!is_near_linked());
98 }
Steve Blocka7e24c12009-10-30 11:49:00 +000099
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000100 INLINE(void Unuse()) { pos_ = 0; }
101 INLINE(void UnuseNear()) { near_link_pos_ = 0; }
102
103 INLINE(bool is_bound() const) { return pos_ < 0; }
104 INLINE(bool is_unused() const) { return pos_ == 0 && near_link_pos_ == 0; }
105 INLINE(bool is_linked() const) { return pos_ > 0; }
Ben Murdoch257744e2011-11-30 15:57:28 +0000106 INLINE(bool is_near_linked() const) { return near_link_pos_ > 0; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000107
108 // Returns the position of bound or linked labels. Cannot be used
109 // for unused labels.
110 int pos() const;
Ben Murdoch257744e2011-11-30 15:57:28 +0000111 int near_link_pos() const { return near_link_pos_ - 1; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000112
113 private:
114 // pos_ encodes both the binding state (via its sign)
115 // and the binding position (via its value) of a label.
116 //
117 // pos_ < 0 bound label, pos() returns the jump target position
118 // pos_ == 0 unused label
119 // pos_ > 0 linked label, pos() returns the last reference position
120 int pos_;
121
Ben Murdoch257744e2011-11-30 15:57:28 +0000122 // Behaves like |pos_| in the "> 0" case, but for near jumps to this label.
123 int near_link_pos_;
124
Steve Blocka7e24c12009-10-30 11:49:00 +0000125 void bind_to(int pos) {
126 pos_ = -pos - 1;
127 ASSERT(is_bound());
128 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000129 void link_to(int pos, Distance distance = kFar) {
130 if (distance == kNear) {
131 near_link_pos_ = pos + 1;
132 ASSERT(is_near_linked());
133 } else {
134 pos_ = pos + 1;
135 ASSERT(is_linked());
136 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000137 }
138
139 friend class Assembler;
140 friend class RegexpAssembler;
141 friend class Displacement;
Steve Blocka7e24c12009-10-30 11:49:00 +0000142 friend class RegExpMacroAssemblerIrregexp;
143};
144
145
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000146enum SaveFPRegsMode { kDontSaveFPRegs, kSaveFPRegs };
147
148
Steve Blocka7e24c12009-10-30 11:49:00 +0000149// -----------------------------------------------------------------------------
150// Relocation information
151
152
153// Relocation information consists of the address (pc) of the datum
154// to which the relocation information applies, the relocation mode
155// (rmode), and an optional data field. The relocation mode may be
156// "descriptive" and not indicate a need for relocation, but simply
157// describe a property of the datum. Such rmodes are useful for GC
158// and nice disassembly output.
159
160class RelocInfo BASE_EMBEDDED {
161 public:
162 // The constant kNoPosition is used with the collecting of source positions
163 // in the relocation information. Two types of source positions are collected
164 // "position" (RelocMode position) and "statement position" (RelocMode
165 // statement_position). The "position" is collected at places in the source
166 // code which are of interest when making stack traces to pin-point the source
167 // location of a stack frame as close as possible. The "statement position" is
168 // collected at the beginning at each statement, and is used to indicate
169 // possible break locations. kNoPosition is used to indicate an
170 // invalid/uninitialized position value.
171 static const int kNoPosition = -1;
172
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100173 // This string is used to add padding comments to the reloc info in cases
174 // where we are not sure to have enough space for patching in during
175 // lazy deoptimization. This is the case if we have indirect calls for which
176 // we do not normally record relocation info.
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000177 static const char* const kFillerCommentString;
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100178
179 // The minimum size of a comment is equal to three bytes for the extra tagged
180 // pc + the tag for the data, and kPointerSize for the actual pointer to the
181 // comment.
182 static const int kMinRelocCommentSize = 3 + kPointerSize;
183
184 // The maximum size for a call instruction including pc-jump.
185 static const int kMaxCallSize = 6;
186
Steve Block44f0eee2011-05-26 01:26:41 +0100187 // The maximum pc delta that will use the short encoding.
188 static const int kMaxSmallPCDelta;
189
Steve Blocka7e24c12009-10-30 11:49:00 +0000190 enum Mode {
191 // Please note the order is important (see IsCodeTarget, IsGCRelocMode).
Ben Murdoch257744e2011-11-30 15:57:28 +0000192 CODE_TARGET, // Code target which is not any of the above.
193 CODE_TARGET_WITH_ID,
Steve Blocka7e24c12009-10-30 11:49:00 +0000194 CONSTRUCT_CALL, // code target that is a call to a JavaScript constructor.
Steve Block1e0659c2011-05-24 12:43:12 +0100195 CODE_TARGET_CONTEXT, // Code target used for contextual loads and stores.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100196 DEBUG_BREAK, // Code target for the debugger statement.
Steve Blocka7e24c12009-10-30 11:49:00 +0000197 EMBEDDED_OBJECT,
Ben Murdochb0fe1622011-05-05 13:52:32 +0100198 GLOBAL_PROPERTY_CELL,
199
Steve Blocka7e24c12009-10-30 11:49:00 +0000200 // Everything after runtime_entry (inclusive) is not GC'ed.
201 RUNTIME_ENTRY,
202 JS_RETURN, // Marks start of the ExitJSFrame code.
203 COMMENT,
204 POSITION, // See comment for kNoPosition above.
205 STATEMENT_POSITION, // See comment for kNoPosition above.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100206 DEBUG_BREAK_SLOT, // Additional code inserted for debug break slot.
Steve Blocka7e24c12009-10-30 11:49:00 +0000207 EXTERNAL_REFERENCE, // The address of an external C++ function.
208 INTERNAL_REFERENCE, // An address inside the same function.
209
210 // add more as needed
211 // Pseudo-types
Ben Murdoch257744e2011-11-30 15:57:28 +0000212 NUMBER_OF_MODES, // There are at most 14 modes with noncompact encoding.
Steve Blocka7e24c12009-10-30 11:49:00 +0000213 NONE, // never recorded
Ben Murdoch257744e2011-11-30 15:57:28 +0000214 LAST_CODE_ENUM = DEBUG_BREAK,
215 LAST_GCED_ENUM = GLOBAL_PROPERTY_CELL,
216 // Modes <= LAST_COMPACT_ENUM are guaranteed to have compact encoding.
217 LAST_COMPACT_ENUM = CODE_TARGET_WITH_ID
Steve Blocka7e24c12009-10-30 11:49:00 +0000218 };
219
220
221 RelocInfo() {}
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000222
223 RelocInfo(byte* pc, Mode rmode, intptr_t data, Code* host)
224 : pc_(pc), rmode_(rmode), data_(data), host_(host) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000225 }
226
227 static inline bool IsConstructCall(Mode mode) {
228 return mode == CONSTRUCT_CALL;
229 }
230 static inline bool IsCodeTarget(Mode mode) {
231 return mode <= LAST_CODE_ENUM;
232 }
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000233 static inline bool IsEmbeddedObject(Mode mode) {
234 return mode == EMBEDDED_OBJECT;
235 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000236 // Is the relocation mode affected by GC?
237 static inline bool IsGCRelocMode(Mode mode) {
238 return mode <= LAST_GCED_ENUM;
239 }
240 static inline bool IsJSReturn(Mode mode) {
241 return mode == JS_RETURN;
242 }
243 static inline bool IsComment(Mode mode) {
244 return mode == COMMENT;
245 }
246 static inline bool IsPosition(Mode mode) {
247 return mode == POSITION || mode == STATEMENT_POSITION;
248 }
249 static inline bool IsStatementPosition(Mode mode) {
250 return mode == STATEMENT_POSITION;
251 }
252 static inline bool IsExternalReference(Mode mode) {
253 return mode == EXTERNAL_REFERENCE;
254 }
255 static inline bool IsInternalReference(Mode mode) {
256 return mode == INTERNAL_REFERENCE;
257 }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100258 static inline bool IsDebugBreakSlot(Mode mode) {
259 return mode == DEBUG_BREAK_SLOT;
260 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000261 static inline int ModeMask(Mode mode) { return 1 << mode; }
262
263 // Accessors
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100264 byte* pc() const { return pc_; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000265 void set_pc(byte* pc) { pc_ = pc; }
266 Mode rmode() const { return rmode_; }
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100267 intptr_t data() const { return data_; }
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000268 Code* host() const { return host_; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000269
270 // Apply a relocation by delta bytes
271 INLINE(void apply(intptr_t delta));
272
Leon Clarkef7060e22010-06-03 12:02:55 +0100273 // Is the pointer this relocation info refers to coded like a plain pointer
274 // or is it strange in some way (eg relative or patched into a series of
275 // instructions).
276 bool IsCodedSpecially();
277
Steve Blocka7e24c12009-10-30 11:49:00 +0000278 // Read/modify the code target in the branch/call instruction
279 // this relocation applies to;
280 // can only be called if IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY
281 INLINE(Address target_address());
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000282 INLINE(void set_target_address(Address target,
283 WriteBarrierMode mode = UPDATE_WRITE_BARRIER));
Steve Blocka7e24c12009-10-30 11:49:00 +0000284 INLINE(Object* target_object());
Steve Block3ce2e202009-11-05 08:53:23 +0000285 INLINE(Handle<Object> target_object_handle(Assembler* origin));
Steve Blocka7e24c12009-10-30 11:49:00 +0000286 INLINE(Object** target_object_address());
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000287 INLINE(void set_target_object(Object* target,
288 WriteBarrierMode mode = UPDATE_WRITE_BARRIER));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100289 INLINE(JSGlobalPropertyCell* target_cell());
290 INLINE(Handle<JSGlobalPropertyCell> target_cell_handle());
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000291 INLINE(void set_target_cell(JSGlobalPropertyCell* cell,
292 WriteBarrierMode mode = UPDATE_WRITE_BARRIER));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100293
Steve Blocka7e24c12009-10-30 11:49:00 +0000294
Leon Clarkef7060e22010-06-03 12:02:55 +0100295 // Read the address of the word containing the target_address in an
296 // instruction stream. What this means exactly is architecture-independent.
297 // The only architecture-independent user of this function is the serializer.
298 // The serializer uses it to find out how many raw bytes of instruction to
299 // output before the next target. Architecture-independent code shouldn't
300 // dereference the pointer it gets back from this.
Steve Blocka7e24c12009-10-30 11:49:00 +0000301 INLINE(Address target_address_address());
Leon Clarkef7060e22010-06-03 12:02:55 +0100302 // This indicates how much space a target takes up when deserializing a code
303 // stream. For most architectures this is just the size of a pointer. For
304 // an instruction like movw/movt where the target bits are mixed into the
305 // instruction bits the size of the target will be zero, indicating that the
306 // serializer should not step forwards in memory after a target is resolved
307 // and written. In this case the target_address_address function above
308 // should return the end of the instructions to be patched, allowing the
309 // deserializer to deserialize the instructions as raw bytes and put them in
310 // place, ready to be patched with the target.
311 INLINE(int target_address_size());
Steve Blocka7e24c12009-10-30 11:49:00 +0000312
313 // Read/modify the reference in the instruction this relocation
314 // applies to; can only be called if rmode_ is external_reference
315 INLINE(Address* target_reference_address());
316
317 // Read/modify the address of a call instruction. This is used to relocate
318 // the break points where straight-line code is patched with a call
319 // instruction.
320 INLINE(Address call_address());
321 INLINE(void set_call_address(Address target));
322 INLINE(Object* call_object());
Steve Blocka7e24c12009-10-30 11:49:00 +0000323 INLINE(void set_call_object(Object* target));
Ben Murdochbb769b22010-08-11 14:56:33 +0100324 INLINE(Object** call_object_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000325
Steve Block44f0eee2011-05-26 01:26:41 +0100326 template<typename StaticVisitor> inline void Visit(Heap* heap);
Leon Clarkef7060e22010-06-03 12:02:55 +0100327 inline void Visit(ObjectVisitor* v);
328
Steve Blocka7e24c12009-10-30 11:49:00 +0000329 // Patch the code with some other code.
330 void PatchCode(byte* instructions, int instruction_count);
331
332 // Patch the code with a call.
333 void PatchCodeWithCall(Address target, int guard_bytes);
Steve Block3ce2e202009-11-05 08:53:23 +0000334
335 // Check whether this return sequence has been patched
336 // with a call to the debugger.
337 INLINE(bool IsPatchedReturnSequence());
Steve Blocka7e24c12009-10-30 11:49:00 +0000338
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100339 // Check whether this debug break slot has been patched with a call to the
340 // debugger.
341 INLINE(bool IsPatchedDebugBreakSlotSequence());
342
Steve Blocka7e24c12009-10-30 11:49:00 +0000343#ifdef ENABLE_DISASSEMBLER
344 // Printing
345 static const char* RelocModeName(Mode rmode);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100346 void Print(FILE* out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000347#endif // ENABLE_DISASSEMBLER
348#ifdef DEBUG
349 // Debugging
350 void Verify();
351#endif
352
353 static const int kCodeTargetMask = (1 << (LAST_CODE_ENUM + 1)) - 1;
354 static const int kPositionMask = 1 << POSITION | 1 << STATEMENT_POSITION;
Ben Murdoch257744e2011-11-30 15:57:28 +0000355 static const int kDataMask =
356 (1 << CODE_TARGET_WITH_ID) | kPositionMask | (1 << COMMENT);
Steve Blocka7e24c12009-10-30 11:49:00 +0000357 static const int kApplyMask; // Modes affected by apply. Depends on arch.
358
359 private:
360 // On ARM, note that pc_ is the address of the constant pool entry
361 // to be relocated and not the address of the instruction
362 // referencing the constant pool entry (except when rmode_ ==
363 // comment).
364 byte* pc_;
365 Mode rmode_;
366 intptr_t data_;
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000367 Code* host_;
Ben Murdoch257744e2011-11-30 15:57:28 +0000368#ifdef V8_TARGET_ARCH_MIPS
369 // Code and Embedded Object pointers in mips are stored split
370 // across two consecutive 32-bit instructions. Heap management
371 // routines expect to access these pointers indirectly. The following
372 // location provides a place for these pointers to exist natually
373 // when accessed via the Iterator.
374 Object *reconstructed_obj_ptr_;
375 // External-reference pointers are also split across instruction-pairs
376 // in mips, but are accessed via indirect pointers. This location
377 // provides a place for that pointer to exist naturally. Its address
378 // is returned by RelocInfo::target_reference_address().
379 Address reconstructed_adr_ptr_;
380#endif // V8_TARGET_ARCH_MIPS
Steve Blocka7e24c12009-10-30 11:49:00 +0000381 friend class RelocIterator;
382};
383
384
385// RelocInfoWriter serializes a stream of relocation info. It writes towards
386// lower addresses.
387class RelocInfoWriter BASE_EMBEDDED {
388 public:
Ben Murdoch257744e2011-11-30 15:57:28 +0000389 RelocInfoWriter() : pos_(NULL),
390 last_pc_(NULL),
391 last_id_(0),
392 last_position_(0) {}
393 RelocInfoWriter(byte* pos, byte* pc) : pos_(pos),
394 last_pc_(pc),
395 last_id_(0),
396 last_position_(0) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000397
398 byte* pos() const { return pos_; }
399 byte* last_pc() const { return last_pc_; }
400
401 void Write(const RelocInfo* rinfo);
402
403 // Update the state of the stream after reloc info buffer
404 // and/or code is moved while the stream is active.
405 void Reposition(byte* pos, byte* pc) {
406 pos_ = pos;
407 last_pc_ = pc;
408 }
409
410 // Max size (bytes) of a written RelocInfo. Longest encoding is
411 // ExtraTag, VariableLengthPCJump, ExtraTag, pc_delta, ExtraTag, data_delta.
412 // On ia32 and arm this is 1 + 4 + 1 + 1 + 1 + 4 = 12.
413 // On x64 this is 1 + 4 + 1 + 1 + 1 + 8 == 16;
414 // Here we use the maximum of the two.
415 static const int kMaxSize = 16;
416
417 private:
418 inline uint32_t WriteVariableLengthPCJump(uint32_t pc_delta);
419 inline void WriteTaggedPC(uint32_t pc_delta, int tag);
420 inline void WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag);
Ben Murdoch257744e2011-11-30 15:57:28 +0000421 inline void WriteExtraTaggedIntData(int data_delta, int top_tag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000422 inline void WriteExtraTaggedData(intptr_t data_delta, int top_tag);
423 inline void WriteTaggedData(intptr_t data_delta, int tag);
424 inline void WriteExtraTag(int extra_tag, int top_tag);
425
426 byte* pos_;
427 byte* last_pc_;
Ben Murdoch257744e2011-11-30 15:57:28 +0000428 int last_id_;
429 int last_position_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000430 DISALLOW_COPY_AND_ASSIGN(RelocInfoWriter);
431};
432
433
434// A RelocIterator iterates over relocation information.
435// Typical use:
436//
437// for (RelocIterator it(code); !it.done(); it.next()) {
438// // do something with it.rinfo() here
439// }
440//
441// A mask can be specified to skip unwanted modes.
442class RelocIterator: public Malloced {
443 public:
444 // Create a new iterator positioned at
445 // the beginning of the reloc info.
446 // Relocation information with mode k is included in the
447 // iteration iff bit k of mode_mask is set.
448 explicit RelocIterator(Code* code, int mode_mask = -1);
449 explicit RelocIterator(const CodeDesc& desc, int mode_mask = -1);
450
451 // Iteration
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100452 bool done() const { return done_; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000453 void next();
454
455 // Return pointer valid until next next().
456 RelocInfo* rinfo() {
457 ASSERT(!done());
458 return &rinfo_;
459 }
460
461 private:
462 // Advance* moves the position before/after reading.
463 // *Read* reads from current byte(s) into rinfo_.
464 // *Get* just reads and returns info on current byte.
465 void Advance(int bytes = 1) { pos_ -= bytes; }
466 int AdvanceGetTag();
467 int GetExtraTag();
468 int GetTopTag();
469 void ReadTaggedPC();
470 void AdvanceReadPC();
Ben Murdoch257744e2011-11-30 15:57:28 +0000471 void AdvanceReadId();
472 void AdvanceReadPosition();
Steve Blocka7e24c12009-10-30 11:49:00 +0000473 void AdvanceReadData();
474 void AdvanceReadVariableLengthPCJump();
Ben Murdoch257744e2011-11-30 15:57:28 +0000475 int GetLocatableTypeTag();
476 void ReadTaggedId();
477 void ReadTaggedPosition();
Steve Blocka7e24c12009-10-30 11:49:00 +0000478
479 // If the given mode is wanted, set it in rinfo_ and return true.
480 // Else return false. Used for efficiently skipping unwanted modes.
481 bool SetMode(RelocInfo::Mode mode) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100482 return (mode_mask_ & (1 << mode)) ? (rinfo_.rmode_ = mode, true) : false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000483 }
484
485 byte* pos_;
486 byte* end_;
487 RelocInfo rinfo_;
488 bool done_;
489 int mode_mask_;
Ben Murdoch257744e2011-11-30 15:57:28 +0000490 int last_id_;
491 int last_position_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000492 DISALLOW_COPY_AND_ASSIGN(RelocIterator);
493};
494
495
496//------------------------------------------------------------------------------
497// External function
498
499//----------------------------------------------------------------------------
500class IC_Utility;
501class SCTableReference;
502#ifdef ENABLE_DEBUGGER_SUPPORT
503class Debug_Address;
504#endif
505
506
Steve Blocka7e24c12009-10-30 11:49:00 +0000507// An ExternalReference represents a C++ address used in the generated
508// code. All references to C++ functions and variables must be encapsulated in
509// an ExternalReference instance. This is done in order to track the origin of
510// all external references in the code so that they can be bound to the correct
511// addresses when deserializing a heap.
512class ExternalReference BASE_EMBEDDED {
513 public:
Steve Block1e0659c2011-05-24 12:43:12 +0100514 // Used in the simulator to support different native api calls.
Steve Block1e0659c2011-05-24 12:43:12 +0100515 enum Type {
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100516 // Builtin call.
517 // MaybeObject* f(v8::internal::Arguments).
Steve Block1e0659c2011-05-24 12:43:12 +0100518 BUILTIN_CALL, // default
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100519
Ben Murdoch257744e2011-11-30 15:57:28 +0000520 // Builtin that takes float arguments and returns an int.
521 // int f(double, double).
522 BUILTIN_COMPARE_CALL,
523
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100524 // Builtin call that returns floating point.
525 // double f(double, double).
Ben Murdoch257744e2011-11-30 15:57:28 +0000526 BUILTIN_FP_FP_CALL,
527
528 // Builtin call that returns floating point.
529 // double f(double).
530 BUILTIN_FP_CALL,
531
532 // Builtin call that returns floating point.
533 // double f(double, int).
534 BUILTIN_FP_INT_CALL,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100535
536 // Direct call to API function callback.
537 // Handle<Value> f(v8::Arguments&)
538 DIRECT_API_CALL,
539
540 // Direct call to accessor getter callback.
541 // Handle<value> f(Local<String> property, AccessorInfo& info)
542 DIRECT_GETTER_CALL
Steve Block1e0659c2011-05-24 12:43:12 +0100543 };
544
545 typedef void* ExternalReferenceRedirector(void* original, Type type);
546
Steve Block44f0eee2011-05-26 01:26:41 +0100547 ExternalReference(Builtins::CFunctionId id, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000548
Steve Block44f0eee2011-05-26 01:26:41 +0100549 ExternalReference(ApiFunction* ptr, Type type, Isolate* isolate);
Steve Blockd0582a62009-12-15 09:54:21 +0000550
Steve Block44f0eee2011-05-26 01:26:41 +0100551 ExternalReference(Builtins::Name name, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000552
Steve Block44f0eee2011-05-26 01:26:41 +0100553 ExternalReference(Runtime::FunctionId id, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000554
Steve Block44f0eee2011-05-26 01:26:41 +0100555 ExternalReference(const Runtime::Function* f, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000556
Steve Block44f0eee2011-05-26 01:26:41 +0100557 ExternalReference(const IC_Utility& ic_utility, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000558
559#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Block44f0eee2011-05-26 01:26:41 +0100560 ExternalReference(const Debug_Address& debug_address, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000561#endif
562
563 explicit ExternalReference(StatsCounter* counter);
564
Steve Block44f0eee2011-05-26 01:26:41 +0100565 ExternalReference(Isolate::AddressId id, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000566
567 explicit ExternalReference(const SCTableReference& table_ref);
568
Steve Block44f0eee2011-05-26 01:26:41 +0100569 // Isolate::Current() as an external reference.
570 static ExternalReference isolate_address();
571
Steve Blocka7e24c12009-10-30 11:49:00 +0000572 // One-of-a-kind references. These references are not part of a general
573 // pattern. This means that they have to be added to the
574 // ExternalReferenceTable in serialize.cc manually.
575
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000576 static ExternalReference incremental_marking_record_write_function(
577 Isolate* isolate);
578 static ExternalReference incremental_evacuation_record_write_function(
579 Isolate* isolate);
580 static ExternalReference store_buffer_overflow_function(
581 Isolate* isolate);
582 static ExternalReference flush_icache_function(Isolate* isolate);
Steve Block44f0eee2011-05-26 01:26:41 +0100583 static ExternalReference perform_gc_function(Isolate* isolate);
584 static ExternalReference fill_heap_number_with_random_function(
585 Isolate* isolate);
586 static ExternalReference random_uint32_function(Isolate* isolate);
587 static ExternalReference transcendental_cache_array_address(Isolate* isolate);
588 static ExternalReference delete_handle_scope_extensions(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000589
Ben Murdochb0fe1622011-05-05 13:52:32 +0100590 // Deoptimization support.
Steve Block44f0eee2011-05-26 01:26:41 +0100591 static ExternalReference new_deoptimizer_function(Isolate* isolate);
592 static ExternalReference compute_output_frames_function(Isolate* isolate);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100593
Leon Clarkee46be812010-01-19 14:06:41 +0000594 // Static data in the keyed lookup cache.
Steve Block44f0eee2011-05-26 01:26:41 +0100595 static ExternalReference keyed_lookup_cache_keys(Isolate* isolate);
596 static ExternalReference keyed_lookup_cache_field_offsets(Isolate* isolate);
Leon Clarkee46be812010-01-19 14:06:41 +0000597
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000598 // Static variable Heap::roots_array_start()
599 static ExternalReference roots_array_start(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000600
601 // Static variable StackGuard::address_of_jslimit()
Steve Block44f0eee2011-05-26 01:26:41 +0100602 static ExternalReference address_of_stack_limit(Isolate* isolate);
Steve Blockd0582a62009-12-15 09:54:21 +0000603
604 // Static variable StackGuard::address_of_real_jslimit()
Steve Block44f0eee2011-05-26 01:26:41 +0100605 static ExternalReference address_of_real_stack_limit(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000606
607 // Static variable RegExpStack::limit_address()
Steve Block44f0eee2011-05-26 01:26:41 +0100608 static ExternalReference address_of_regexp_stack_limit(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000609
Leon Clarkee46be812010-01-19 14:06:41 +0000610 // Static variables for RegExp.
Steve Block44f0eee2011-05-26 01:26:41 +0100611 static ExternalReference address_of_static_offsets_vector(Isolate* isolate);
612 static ExternalReference address_of_regexp_stack_memory_address(
613 Isolate* isolate);
614 static ExternalReference address_of_regexp_stack_memory_size(
615 Isolate* isolate);
Leon Clarkee46be812010-01-19 14:06:41 +0000616
Steve Blocka7e24c12009-10-30 11:49:00 +0000617 // Static variable Heap::NewSpaceStart()
Steve Block44f0eee2011-05-26 01:26:41 +0100618 static ExternalReference new_space_start(Isolate* isolate);
619 static ExternalReference new_space_mask(Isolate* isolate);
620 static ExternalReference heap_always_allocate_scope_depth(Isolate* isolate);
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000621 static ExternalReference new_space_mark_bits(Isolate* isolate);
622
623 // Write barrier.
624 static ExternalReference store_buffer_top(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000625
626 // Used for fast allocation in generated code.
Steve Block44f0eee2011-05-26 01:26:41 +0100627 static ExternalReference new_space_allocation_top_address(Isolate* isolate);
628 static ExternalReference new_space_allocation_limit_address(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000629
Steve Block44f0eee2011-05-26 01:26:41 +0100630 static ExternalReference double_fp_operation(Token::Value operation,
631 Isolate* isolate);
632 static ExternalReference compare_doubles(Isolate* isolate);
633 static ExternalReference power_double_double_function(Isolate* isolate);
634 static ExternalReference power_double_int_function(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000635
Steve Blockd0582a62009-12-15 09:54:21 +0000636 static ExternalReference handle_scope_next_address();
637 static ExternalReference handle_scope_limit_address();
John Reck59135872010-11-02 12:39:01 -0700638 static ExternalReference handle_scope_level_address();
Steve Blockd0582a62009-12-15 09:54:21 +0000639
Steve Block44f0eee2011-05-26 01:26:41 +0100640 static ExternalReference scheduled_exception_address(Isolate* isolate);
Steve Blockd0582a62009-12-15 09:54:21 +0000641
Ben Murdochb0fe1622011-05-05 13:52:32 +0100642 // Static variables containing common double constants.
643 static ExternalReference address_of_min_int();
644 static ExternalReference address_of_one_half();
Ben Murdochb8e0da22011-05-16 14:20:40 +0100645 static ExternalReference address_of_minus_zero();
Ben Murdoch257744e2011-11-30 15:57:28 +0000646 static ExternalReference address_of_zero();
647 static ExternalReference address_of_uint8_max_value();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100648 static ExternalReference address_of_negative_infinity();
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000649 static ExternalReference address_of_canonical_non_hole_nan();
650 static ExternalReference address_of_the_hole_nan();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100651
Steve Block44f0eee2011-05-26 01:26:41 +0100652 static ExternalReference math_sin_double_function(Isolate* isolate);
653 static ExternalReference math_cos_double_function(Isolate* isolate);
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000654 static ExternalReference math_tan_double_function(Isolate* isolate);
Steve Block44f0eee2011-05-26 01:26:41 +0100655 static ExternalReference math_log_double_function(Isolate* isolate);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100656
Steve Blocka7e24c12009-10-30 11:49:00 +0000657 Address address() const {return reinterpret_cast<Address>(address_);}
658
659#ifdef ENABLE_DEBUGGER_SUPPORT
660 // Function Debug::Break()
Steve Block44f0eee2011-05-26 01:26:41 +0100661 static ExternalReference debug_break(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000662
663 // Used to check if single stepping is enabled in generated code.
Steve Block44f0eee2011-05-26 01:26:41 +0100664 static ExternalReference debug_step_in_fp_address(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000665#endif
666
Steve Block6ded16b2010-05-10 14:33:55 +0100667#ifndef V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +0000668 // C functions called from RegExp generated code.
669
670 // Function NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()
Steve Block44f0eee2011-05-26 01:26:41 +0100671 static ExternalReference re_case_insensitive_compare_uc16(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000672
673 // Function RegExpMacroAssembler*::CheckStackGuardState()
Steve Block44f0eee2011-05-26 01:26:41 +0100674 static ExternalReference re_check_stack_guard_state(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000675
676 // Function NativeRegExpMacroAssembler::GrowStack()
Steve Block44f0eee2011-05-26 01:26:41 +0100677 static ExternalReference re_grow_stack(Isolate* isolate);
Leon Clarkee46be812010-01-19 14:06:41 +0000678
679 // byte NativeRegExpMacroAssembler::word_character_bitmap
680 static ExternalReference re_word_character_map();
681
Steve Blocka7e24c12009-10-30 11:49:00 +0000682#endif
683
684 // This lets you register a function that rewrites all external references.
685 // Used by the ARM simulator to catch calls to external references.
Ben Murdoch257744e2011-11-30 15:57:28 +0000686 static void set_redirector(Isolate* isolate,
687 ExternalReferenceRedirector* redirector) {
Steve Block44f0eee2011-05-26 01:26:41 +0100688 // We can't stack them.
Ben Murdoch257744e2011-11-30 15:57:28 +0000689 ASSERT(isolate->external_reference_redirector() == NULL);
690 isolate->set_external_reference_redirector(
Steve Block44f0eee2011-05-26 01:26:41 +0100691 reinterpret_cast<ExternalReferenceRedirectorPointer*>(redirector));
Steve Blocka7e24c12009-10-30 11:49:00 +0000692 }
693
694 private:
695 explicit ExternalReference(void* address)
696 : address_(address) {}
697
Steve Block44f0eee2011-05-26 01:26:41 +0100698 static void* Redirect(Isolate* isolate,
699 void* address,
Steve Block1e0659c2011-05-24 12:43:12 +0100700 Type type = ExternalReference::BUILTIN_CALL) {
Steve Block44f0eee2011-05-26 01:26:41 +0100701 ExternalReferenceRedirector* redirector =
702 reinterpret_cast<ExternalReferenceRedirector*>(
703 isolate->external_reference_redirector());
704 if (redirector == NULL) return address;
705 void* answer = (*redirector)(address, type);
Steve Blockd0582a62009-12-15 09:54:21 +0000706 return answer;
Steve Blocka7e24c12009-10-30 11:49:00 +0000707 }
708
Steve Block44f0eee2011-05-26 01:26:41 +0100709 static void* Redirect(Isolate* isolate,
710 Address address_arg,
Steve Block1e0659c2011-05-24 12:43:12 +0100711 Type type = ExternalReference::BUILTIN_CALL) {
Steve Block44f0eee2011-05-26 01:26:41 +0100712 ExternalReferenceRedirector* redirector =
713 reinterpret_cast<ExternalReferenceRedirector*>(
714 isolate->external_reference_redirector());
Steve Blocka7e24c12009-10-30 11:49:00 +0000715 void* address = reinterpret_cast<void*>(address_arg);
Steve Block44f0eee2011-05-26 01:26:41 +0100716 void* answer = (redirector == NULL) ?
Steve Blockd0582a62009-12-15 09:54:21 +0000717 address :
Steve Block44f0eee2011-05-26 01:26:41 +0100718 (*redirector)(address, type);
Steve Blockd0582a62009-12-15 09:54:21 +0000719 return answer;
Steve Blocka7e24c12009-10-30 11:49:00 +0000720 }
721
722 void* address_;
723};
724
725
726// -----------------------------------------------------------------------------
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800727// Position recording support
728
Ben Murdochb0fe1622011-05-05 13:52:32 +0100729struct PositionState {
730 PositionState() : current_position(RelocInfo::kNoPosition),
731 written_position(RelocInfo::kNoPosition),
732 current_statement_position(RelocInfo::kNoPosition),
733 written_statement_position(RelocInfo::kNoPosition) {}
734
735 int current_position;
736 int written_position;
737
738 int current_statement_position;
739 int written_statement_position;
740};
741
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800742
743class PositionsRecorder BASE_EMBEDDED {
744 public:
745 explicit PositionsRecorder(Assembler* assembler)
Ben Murdochb8e0da22011-05-16 14:20:40 +0100746 : assembler_(assembler) {
747#ifdef ENABLE_GDB_JIT_INTERFACE
748 gdbjit_lineinfo_ = NULL;
749#endif
750 }
751
752#ifdef ENABLE_GDB_JIT_INTERFACE
753 ~PositionsRecorder() {
754 delete gdbjit_lineinfo_;
755 }
756
757 void StartGDBJITLineInfoRecording() {
758 if (FLAG_gdbjit) {
759 gdbjit_lineinfo_ = new GDBJITLineInfo();
760 }
761 }
762
763 GDBJITLineInfo* DetachGDBJITLineInfo() {
764 GDBJITLineInfo* lineinfo = gdbjit_lineinfo_;
765 gdbjit_lineinfo_ = NULL; // To prevent deallocation in destructor.
766 return lineinfo;
767 }
768#endif
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800769
Ben Murdochb0fe1622011-05-05 13:52:32 +0100770 // Set current position to pos.
771 void RecordPosition(int pos);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800772
773 // Set current statement position to pos.
774 void RecordStatementPosition(int pos);
775
776 // Write recorded positions to relocation information.
777 bool WriteRecordedPositions();
778
Ben Murdochb0fe1622011-05-05 13:52:32 +0100779 int current_position() const { return state_.current_position; }
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800780
Ben Murdochb0fe1622011-05-05 13:52:32 +0100781 int current_statement_position() const {
782 return state_.current_statement_position;
783 }
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800784
785 private:
786 Assembler* assembler_;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100787 PositionState state_;
Ben Murdochb8e0da22011-05-16 14:20:40 +0100788#ifdef ENABLE_GDB_JIT_INTERFACE
789 GDBJITLineInfo* gdbjit_lineinfo_;
790#endif
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800791
Ben Murdochb0fe1622011-05-05 13:52:32 +0100792 friend class PreservePositionScope;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800793
Ben Murdochb0fe1622011-05-05 13:52:32 +0100794 DISALLOW_COPY_AND_ASSIGN(PositionsRecorder);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800795};
796
797
Ben Murdochb0fe1622011-05-05 13:52:32 +0100798class PreservePositionScope BASE_EMBEDDED {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800799 public:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100800 explicit PreservePositionScope(PositionsRecorder* positions_recorder)
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800801 : positions_recorder_(positions_recorder),
Ben Murdochb0fe1622011-05-05 13:52:32 +0100802 saved_state_(positions_recorder->state_) {}
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800803
Ben Murdochb0fe1622011-05-05 13:52:32 +0100804 ~PreservePositionScope() {
805 positions_recorder_->state_ = saved_state_;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800806 }
807
808 private:
809 PositionsRecorder* positions_recorder_;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100810 const PositionState saved_state_;
811
812 DISALLOW_COPY_AND_ASSIGN(PreservePositionScope);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800813};
814
815
816// -----------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000817// Utility functions
818
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000819inline bool is_intn(int x, int n) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000820 return -(1 << (n-1)) <= x && x < (1 << (n-1));
821}
822
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000823inline bool is_int8(int x) { return is_intn(x, 8); }
824inline bool is_int16(int x) { return is_intn(x, 16); }
825inline bool is_int18(int x) { return is_intn(x, 18); }
826inline bool is_int24(int x) { return is_intn(x, 24); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000827
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000828inline bool is_uintn(int x, int n) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000829 return (x & -(1 << n)) == 0;
830}
831
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000832inline bool is_uint2(int x) { return is_uintn(x, 2); }
833inline bool is_uint3(int x) { return is_uintn(x, 3); }
834inline bool is_uint4(int x) { return is_uintn(x, 4); }
835inline bool is_uint5(int x) { return is_uintn(x, 5); }
836inline bool is_uint6(int x) { return is_uintn(x, 6); }
837inline bool is_uint8(int x) { return is_uintn(x, 8); }
838inline bool is_uint10(int x) { return is_uintn(x, 10); }
839inline bool is_uint12(int x) { return is_uintn(x, 12); }
840inline bool is_uint16(int x) { return is_uintn(x, 16); }
841inline bool is_uint24(int x) { return is_uintn(x, 24); }
842inline bool is_uint26(int x) { return is_uintn(x, 26); }
843inline bool is_uint28(int x) { return is_uintn(x, 28); }
Andrei Popescu31002712010-02-23 13:46:05 +0000844
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000845inline int NumberOfBitsSet(uint32_t x) {
Andrei Popescu31002712010-02-23 13:46:05 +0000846 unsigned int num_bits_set;
847 for (num_bits_set = 0; x; x >>= 1) {
848 num_bits_set += x & 1;
849 }
850 return num_bits_set;
851}
Steve Blocka7e24c12009-10-30 11:49:00 +0000852
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000853bool EvalComparison(Token::Value op, double op1, double op2);
854
Ben Murdochb0fe1622011-05-05 13:52:32 +0100855// Computes pow(x, y) with the special cases in the spec for Math.pow.
856double power_double_int(double x, int y);
857double power_double_double(double x, double y);
858
Ben Murdoch257744e2011-11-30 15:57:28 +0000859// Helper class for generating code or data associated with the code
860// right after a call instruction. As an example this can be used to
861// generate safepoint data after calls for crankshaft.
862class CallWrapper {
863 public:
864 CallWrapper() { }
865 virtual ~CallWrapper() { }
866 // Called just before emitting a call. Argument is the size of the generated
867 // call code.
868 virtual void BeforeCall(int call_size) const = 0;
869 // Called just after emitting a call, i.e., at the return site for the call.
870 virtual void AfterCall() const = 0;
871};
872
873class NullCallWrapper : public CallWrapper {
874 public:
875 NullCallWrapper() { }
876 virtual ~NullCallWrapper() { }
877 virtual void BeforeCall(int call_size) const { }
878 virtual void AfterCall() const { }
879};
880
Steve Blocka7e24c12009-10-30 11:49:00 +0000881} } // namespace v8::internal
882
883#endif // V8_ASSEMBLER_H_