blob: e7c92b451c09df9feeaa74471cab8dbc5b0bd157 [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 Murdochc7cc0282012-03-05 14:35:55 +000033// Copyright 2012 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 Murdochc7cc0282012-03-05 14:35:55 +000038#include "v8.h"
39
Ben Murdoch257744e2011-11-30 15:57:28 +000040#include "allocation.h"
Ben Murdochc7cc0282012-03-05 14:35:55 +000041#include "builtins.h"
Ben Murdochb8e0da22011-05-16 14:20:40 +010042#include "gdb-jit.h"
Ben Murdochc7cc0282012-03-05 14:35:55 +000043#include "isolate.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000044#include "runtime.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000045#include "token.h"
46
47namespace v8 {
Ben Murdochc7cc0282012-03-05 14:35:55 +000048
49class ApiFunction;
50
Steve Blocka7e24c12009-10-30 11:49:00 +000051namespace internal {
52
Ben Murdochc7cc0282012-03-05 14:35:55 +000053struct StatsCounter;
Ben Murdoch257744e2011-11-30 15:57:28 +000054const unsigned kNoASTId = -1;
Steve Blocka7e24c12009-10-30 11:49:00 +000055// -----------------------------------------------------------------------------
Steve Block44f0eee2011-05-26 01:26:41 +010056// Platform independent assembler base class.
57
58class AssemblerBase: public Malloced {
59 public:
Steve Block053d10c2011-06-13 19:13:29 +010060 explicit AssemblerBase(Isolate* isolate);
Steve Block44f0eee2011-05-26 01:26:41 +010061
62 Isolate* isolate() const { return isolate_; }
Steve Block053d10c2011-06-13 19:13:29 +010063 int jit_cookie() { return jit_cookie_; }
Steve Block44f0eee2011-05-26 01:26:41 +010064
65 private:
66 Isolate* isolate_;
Steve Block053d10c2011-06-13 19:13:29 +010067 int jit_cookie_;
Steve Block44f0eee2011-05-26 01:26:41 +010068};
69
70// -----------------------------------------------------------------------------
Ben Murdochb0fe1622011-05-05 13:52:32 +010071// Common double constants.
72
73class DoubleConstant: public AllStatic {
74 public:
75 static const double min_int;
76 static const double one_half;
Ben Murdochb8e0da22011-05-16 14:20:40 +010077 static const double minus_zero;
Ben Murdoch257744e2011-11-30 15:57:28 +000078 static const double zero;
79 static const double uint8_max_value;
Ben Murdochb0fe1622011-05-05 13:52:32 +010080 static const double negative_infinity;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000081 static const double canonical_non_hole_nan;
82 static const double the_hole_nan;
Ben Murdochb0fe1622011-05-05 13:52:32 +010083};
84
85
86// -----------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +000087// Labels represent pc locations; they are typically jump or call targets.
88// After declaration, a label can be freely used to denote known or (yet)
89// unknown pc location. Assembler::bind() is used to bind a label to the
90// current pc. A label can be bound only once.
91
92class Label BASE_EMBEDDED {
93 public:
Ben Murdoch257744e2011-11-30 15:57:28 +000094 enum Distance {
95 kNear, kFar
96 };
97
98 INLINE(Label()) {
99 Unuse();
100 UnuseNear();
101 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000102
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000103 INLINE(~Label()) {
104 ASSERT(!is_linked());
105 ASSERT(!is_near_linked());
106 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000107
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000108 INLINE(void Unuse()) { pos_ = 0; }
109 INLINE(void UnuseNear()) { near_link_pos_ = 0; }
110
111 INLINE(bool is_bound() const) { return pos_ < 0; }
112 INLINE(bool is_unused() const) { return pos_ == 0 && near_link_pos_ == 0; }
113 INLINE(bool is_linked() const) { return pos_ > 0; }
Ben Murdoch257744e2011-11-30 15:57:28 +0000114 INLINE(bool is_near_linked() const) { return near_link_pos_ > 0; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000115
116 // Returns the position of bound or linked labels. Cannot be used
117 // for unused labels.
118 int pos() const;
Ben Murdoch257744e2011-11-30 15:57:28 +0000119 int near_link_pos() const { return near_link_pos_ - 1; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000120
121 private:
122 // pos_ encodes both the binding state (via its sign)
123 // and the binding position (via its value) of a label.
124 //
125 // pos_ < 0 bound label, pos() returns the jump target position
126 // pos_ == 0 unused label
127 // pos_ > 0 linked label, pos() returns the last reference position
128 int pos_;
129
Ben Murdoch257744e2011-11-30 15:57:28 +0000130 // Behaves like |pos_| in the "> 0" case, but for near jumps to this label.
131 int near_link_pos_;
132
Steve Blocka7e24c12009-10-30 11:49:00 +0000133 void bind_to(int pos) {
134 pos_ = -pos - 1;
135 ASSERT(is_bound());
136 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000137 void link_to(int pos, Distance distance = kFar) {
138 if (distance == kNear) {
139 near_link_pos_ = pos + 1;
140 ASSERT(is_near_linked());
141 } else {
142 pos_ = pos + 1;
143 ASSERT(is_linked());
144 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000145 }
146
147 friend class Assembler;
148 friend class RegexpAssembler;
149 friend class Displacement;
Steve Blocka7e24c12009-10-30 11:49:00 +0000150 friend class RegExpMacroAssemblerIrregexp;
151};
152
153
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000154enum SaveFPRegsMode { kDontSaveFPRegs, kSaveFPRegs };
155
156
Steve Blocka7e24c12009-10-30 11:49:00 +0000157// -----------------------------------------------------------------------------
158// Relocation information
159
160
161// Relocation information consists of the address (pc) of the datum
162// to which the relocation information applies, the relocation mode
163// (rmode), and an optional data field. The relocation mode may be
164// "descriptive" and not indicate a need for relocation, but simply
165// describe a property of the datum. Such rmodes are useful for GC
166// and nice disassembly output.
167
168class RelocInfo BASE_EMBEDDED {
169 public:
170 // The constant kNoPosition is used with the collecting of source positions
171 // in the relocation information. Two types of source positions are collected
172 // "position" (RelocMode position) and "statement position" (RelocMode
173 // statement_position). The "position" is collected at places in the source
174 // code which are of interest when making stack traces to pin-point the source
175 // location of a stack frame as close as possible. The "statement position" is
176 // collected at the beginning at each statement, and is used to indicate
177 // possible break locations. kNoPosition is used to indicate an
178 // invalid/uninitialized position value.
179 static const int kNoPosition = -1;
180
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100181 // This string is used to add padding comments to the reloc info in cases
182 // where we are not sure to have enough space for patching in during
183 // lazy deoptimization. This is the case if we have indirect calls for which
184 // we do not normally record relocation info.
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000185 static const char* const kFillerCommentString;
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100186
187 // The minimum size of a comment is equal to three bytes for the extra tagged
188 // pc + the tag for the data, and kPointerSize for the actual pointer to the
189 // comment.
190 static const int kMinRelocCommentSize = 3 + kPointerSize;
191
192 // The maximum size for a call instruction including pc-jump.
193 static const int kMaxCallSize = 6;
194
Steve Block44f0eee2011-05-26 01:26:41 +0100195 // The maximum pc delta that will use the short encoding.
196 static const int kMaxSmallPCDelta;
197
Steve Blocka7e24c12009-10-30 11:49:00 +0000198 enum Mode {
199 // Please note the order is important (see IsCodeTarget, IsGCRelocMode).
Ben Murdoch257744e2011-11-30 15:57:28 +0000200 CODE_TARGET, // Code target which is not any of the above.
201 CODE_TARGET_WITH_ID,
Steve Blocka7e24c12009-10-30 11:49:00 +0000202 CONSTRUCT_CALL, // code target that is a call to a JavaScript constructor.
Steve Block1e0659c2011-05-24 12:43:12 +0100203 CODE_TARGET_CONTEXT, // Code target used for contextual loads and stores.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100204 DEBUG_BREAK, // Code target for the debugger statement.
Steve Blocka7e24c12009-10-30 11:49:00 +0000205 EMBEDDED_OBJECT,
Ben Murdochb0fe1622011-05-05 13:52:32 +0100206 GLOBAL_PROPERTY_CELL,
207
Steve Blocka7e24c12009-10-30 11:49:00 +0000208 // Everything after runtime_entry (inclusive) is not GC'ed.
209 RUNTIME_ENTRY,
210 JS_RETURN, // Marks start of the ExitJSFrame code.
211 COMMENT,
212 POSITION, // See comment for kNoPosition above.
213 STATEMENT_POSITION, // See comment for kNoPosition above.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100214 DEBUG_BREAK_SLOT, // Additional code inserted for debug break slot.
Steve Blocka7e24c12009-10-30 11:49:00 +0000215 EXTERNAL_REFERENCE, // The address of an external C++ function.
216 INTERNAL_REFERENCE, // An address inside the same function.
217
218 // add more as needed
219 // Pseudo-types
Ben Murdoch257744e2011-11-30 15:57:28 +0000220 NUMBER_OF_MODES, // There are at most 14 modes with noncompact encoding.
Steve Blocka7e24c12009-10-30 11:49:00 +0000221 NONE, // never recorded
Ben Murdoch257744e2011-11-30 15:57:28 +0000222 LAST_CODE_ENUM = DEBUG_BREAK,
223 LAST_GCED_ENUM = GLOBAL_PROPERTY_CELL,
224 // Modes <= LAST_COMPACT_ENUM are guaranteed to have compact encoding.
225 LAST_COMPACT_ENUM = CODE_TARGET_WITH_ID
Steve Blocka7e24c12009-10-30 11:49:00 +0000226 };
227
228
229 RelocInfo() {}
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000230
231 RelocInfo(byte* pc, Mode rmode, intptr_t data, Code* host)
232 : pc_(pc), rmode_(rmode), data_(data), host_(host) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000233 }
234
235 static inline bool IsConstructCall(Mode mode) {
236 return mode == CONSTRUCT_CALL;
237 }
238 static inline bool IsCodeTarget(Mode mode) {
239 return mode <= LAST_CODE_ENUM;
240 }
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000241 static inline bool IsEmbeddedObject(Mode mode) {
242 return mode == EMBEDDED_OBJECT;
243 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000244 // Is the relocation mode affected by GC?
245 static inline bool IsGCRelocMode(Mode mode) {
246 return mode <= LAST_GCED_ENUM;
247 }
248 static inline bool IsJSReturn(Mode mode) {
249 return mode == JS_RETURN;
250 }
251 static inline bool IsComment(Mode mode) {
252 return mode == COMMENT;
253 }
254 static inline bool IsPosition(Mode mode) {
255 return mode == POSITION || mode == STATEMENT_POSITION;
256 }
257 static inline bool IsStatementPosition(Mode mode) {
258 return mode == STATEMENT_POSITION;
259 }
260 static inline bool IsExternalReference(Mode mode) {
261 return mode == EXTERNAL_REFERENCE;
262 }
263 static inline bool IsInternalReference(Mode mode) {
264 return mode == INTERNAL_REFERENCE;
265 }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100266 static inline bool IsDebugBreakSlot(Mode mode) {
267 return mode == DEBUG_BREAK_SLOT;
268 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000269 static inline int ModeMask(Mode mode) { return 1 << mode; }
270
271 // Accessors
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100272 byte* pc() const { return pc_; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000273 void set_pc(byte* pc) { pc_ = pc; }
274 Mode rmode() const { return rmode_; }
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100275 intptr_t data() const { return data_; }
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000276 Code* host() const { return host_; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000277
278 // Apply a relocation by delta bytes
279 INLINE(void apply(intptr_t delta));
280
Leon Clarkef7060e22010-06-03 12:02:55 +0100281 // Is the pointer this relocation info refers to coded like a plain pointer
Ben Murdochc7cc0282012-03-05 14:35:55 +0000282 // or is it strange in some way (e.g. relative or patched into a series of
Leon Clarkef7060e22010-06-03 12:02:55 +0100283 // instructions).
284 bool IsCodedSpecially();
285
Steve Blocka7e24c12009-10-30 11:49:00 +0000286 // Read/modify the code target in the branch/call instruction
287 // this relocation applies to;
288 // can only be called if IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY
289 INLINE(Address target_address());
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000290 INLINE(void set_target_address(Address target,
291 WriteBarrierMode mode = UPDATE_WRITE_BARRIER));
Steve Blocka7e24c12009-10-30 11:49:00 +0000292 INLINE(Object* target_object());
Steve Block3ce2e202009-11-05 08:53:23 +0000293 INLINE(Handle<Object> target_object_handle(Assembler* origin));
Steve Blocka7e24c12009-10-30 11:49:00 +0000294 INLINE(Object** target_object_address());
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000295 INLINE(void set_target_object(Object* target,
296 WriteBarrierMode mode = UPDATE_WRITE_BARRIER));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100297 INLINE(JSGlobalPropertyCell* target_cell());
298 INLINE(Handle<JSGlobalPropertyCell> target_cell_handle());
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000299 INLINE(void set_target_cell(JSGlobalPropertyCell* cell,
300 WriteBarrierMode mode = UPDATE_WRITE_BARRIER));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100301
Steve Blocka7e24c12009-10-30 11:49:00 +0000302
Leon Clarkef7060e22010-06-03 12:02:55 +0100303 // Read the address of the word containing the target_address in an
304 // instruction stream. What this means exactly is architecture-independent.
305 // The only architecture-independent user of this function is the serializer.
306 // The serializer uses it to find out how many raw bytes of instruction to
307 // output before the next target. Architecture-independent code shouldn't
308 // dereference the pointer it gets back from this.
Steve Blocka7e24c12009-10-30 11:49:00 +0000309 INLINE(Address target_address_address());
Leon Clarkef7060e22010-06-03 12:02:55 +0100310 // This indicates how much space a target takes up when deserializing a code
311 // stream. For most architectures this is just the size of a pointer. For
312 // an instruction like movw/movt where the target bits are mixed into the
313 // instruction bits the size of the target will be zero, indicating that the
314 // serializer should not step forwards in memory after a target is resolved
315 // and written. In this case the target_address_address function above
316 // should return the end of the instructions to be patched, allowing the
317 // deserializer to deserialize the instructions as raw bytes and put them in
318 // place, ready to be patched with the target.
319 INLINE(int target_address_size());
Steve Blocka7e24c12009-10-30 11:49:00 +0000320
321 // Read/modify the reference in the instruction this relocation
322 // applies to; can only be called if rmode_ is external_reference
323 INLINE(Address* target_reference_address());
324
325 // Read/modify the address of a call instruction. This is used to relocate
326 // the break points where straight-line code is patched with a call
327 // instruction.
328 INLINE(Address call_address());
329 INLINE(void set_call_address(Address target));
330 INLINE(Object* call_object());
Steve Blocka7e24c12009-10-30 11:49:00 +0000331 INLINE(void set_call_object(Object* target));
Ben Murdochbb769b22010-08-11 14:56:33 +0100332 INLINE(Object** call_object_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000333
Steve Block44f0eee2011-05-26 01:26:41 +0100334 template<typename StaticVisitor> inline void Visit(Heap* heap);
Leon Clarkef7060e22010-06-03 12:02:55 +0100335 inline void Visit(ObjectVisitor* v);
336
Steve Blocka7e24c12009-10-30 11:49:00 +0000337 // Patch the code with some other code.
338 void PatchCode(byte* instructions, int instruction_count);
339
340 // Patch the code with a call.
341 void PatchCodeWithCall(Address target, int guard_bytes);
Steve Block3ce2e202009-11-05 08:53:23 +0000342
343 // Check whether this return sequence has been patched
344 // with a call to the debugger.
345 INLINE(bool IsPatchedReturnSequence());
Steve Blocka7e24c12009-10-30 11:49:00 +0000346
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100347 // Check whether this debug break slot has been patched with a call to the
348 // debugger.
349 INLINE(bool IsPatchedDebugBreakSlotSequence());
350
Steve Blocka7e24c12009-10-30 11:49:00 +0000351#ifdef ENABLE_DISASSEMBLER
352 // Printing
353 static const char* RelocModeName(Mode rmode);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100354 void Print(FILE* out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000355#endif // ENABLE_DISASSEMBLER
356#ifdef DEBUG
357 // Debugging
358 void Verify();
359#endif
360
361 static const int kCodeTargetMask = (1 << (LAST_CODE_ENUM + 1)) - 1;
362 static const int kPositionMask = 1 << POSITION | 1 << STATEMENT_POSITION;
Ben Murdoch257744e2011-11-30 15:57:28 +0000363 static const int kDataMask =
364 (1 << CODE_TARGET_WITH_ID) | kPositionMask | (1 << COMMENT);
Steve Blocka7e24c12009-10-30 11:49:00 +0000365 static const int kApplyMask; // Modes affected by apply. Depends on arch.
366
367 private:
368 // On ARM, note that pc_ is the address of the constant pool entry
369 // to be relocated and not the address of the instruction
370 // referencing the constant pool entry (except when rmode_ ==
371 // comment).
372 byte* pc_;
373 Mode rmode_;
374 intptr_t data_;
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000375 Code* host_;
Ben Murdoch257744e2011-11-30 15:57:28 +0000376#ifdef V8_TARGET_ARCH_MIPS
377 // Code and Embedded Object pointers in mips are stored split
378 // across two consecutive 32-bit instructions. Heap management
379 // routines expect to access these pointers indirectly. The following
380 // location provides a place for these pointers to exist natually
381 // when accessed via the Iterator.
Ben Murdochc7cc0282012-03-05 14:35:55 +0000382 Object* reconstructed_obj_ptr_;
Ben Murdoch257744e2011-11-30 15:57:28 +0000383 // External-reference pointers are also split across instruction-pairs
384 // in mips, but are accessed via indirect pointers. This location
385 // provides a place for that pointer to exist naturally. Its address
386 // is returned by RelocInfo::target_reference_address().
387 Address reconstructed_adr_ptr_;
388#endif // V8_TARGET_ARCH_MIPS
Steve Blocka7e24c12009-10-30 11:49:00 +0000389 friend class RelocIterator;
390};
391
392
393// RelocInfoWriter serializes a stream of relocation info. It writes towards
394// lower addresses.
395class RelocInfoWriter BASE_EMBEDDED {
396 public:
Ben Murdoch257744e2011-11-30 15:57:28 +0000397 RelocInfoWriter() : pos_(NULL),
398 last_pc_(NULL),
399 last_id_(0),
400 last_position_(0) {}
401 RelocInfoWriter(byte* pos, byte* pc) : pos_(pos),
402 last_pc_(pc),
403 last_id_(0),
404 last_position_(0) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000405
406 byte* pos() const { return pos_; }
407 byte* last_pc() const { return last_pc_; }
408
409 void Write(const RelocInfo* rinfo);
410
411 // Update the state of the stream after reloc info buffer
412 // and/or code is moved while the stream is active.
413 void Reposition(byte* pos, byte* pc) {
414 pos_ = pos;
415 last_pc_ = pc;
416 }
417
418 // Max size (bytes) of a written RelocInfo. Longest encoding is
419 // ExtraTag, VariableLengthPCJump, ExtraTag, pc_delta, ExtraTag, data_delta.
420 // On ia32 and arm this is 1 + 4 + 1 + 1 + 1 + 4 = 12.
421 // On x64 this is 1 + 4 + 1 + 1 + 1 + 8 == 16;
422 // Here we use the maximum of the two.
423 static const int kMaxSize = 16;
424
425 private:
426 inline uint32_t WriteVariableLengthPCJump(uint32_t pc_delta);
427 inline void WriteTaggedPC(uint32_t pc_delta, int tag);
428 inline void WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag);
Ben Murdoch257744e2011-11-30 15:57:28 +0000429 inline void WriteExtraTaggedIntData(int data_delta, int top_tag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000430 inline void WriteExtraTaggedData(intptr_t data_delta, int top_tag);
431 inline void WriteTaggedData(intptr_t data_delta, int tag);
432 inline void WriteExtraTag(int extra_tag, int top_tag);
433
434 byte* pos_;
435 byte* last_pc_;
Ben Murdoch257744e2011-11-30 15:57:28 +0000436 int last_id_;
437 int last_position_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000438 DISALLOW_COPY_AND_ASSIGN(RelocInfoWriter);
439};
440
441
442// A RelocIterator iterates over relocation information.
443// Typical use:
444//
445// for (RelocIterator it(code); !it.done(); it.next()) {
446// // do something with it.rinfo() here
447// }
448//
449// A mask can be specified to skip unwanted modes.
450class RelocIterator: public Malloced {
451 public:
452 // Create a new iterator positioned at
453 // the beginning of the reloc info.
454 // Relocation information with mode k is included in the
455 // iteration iff bit k of mode_mask is set.
456 explicit RelocIterator(Code* code, int mode_mask = -1);
457 explicit RelocIterator(const CodeDesc& desc, int mode_mask = -1);
458
459 // Iteration
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100460 bool done() const { return done_; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000461 void next();
462
463 // Return pointer valid until next next().
464 RelocInfo* rinfo() {
465 ASSERT(!done());
466 return &rinfo_;
467 }
468
469 private:
470 // Advance* moves the position before/after reading.
471 // *Read* reads from current byte(s) into rinfo_.
472 // *Get* just reads and returns info on current byte.
473 void Advance(int bytes = 1) { pos_ -= bytes; }
474 int AdvanceGetTag();
475 int GetExtraTag();
476 int GetTopTag();
477 void ReadTaggedPC();
478 void AdvanceReadPC();
Ben Murdoch257744e2011-11-30 15:57:28 +0000479 void AdvanceReadId();
480 void AdvanceReadPosition();
Steve Blocka7e24c12009-10-30 11:49:00 +0000481 void AdvanceReadData();
482 void AdvanceReadVariableLengthPCJump();
Ben Murdoch257744e2011-11-30 15:57:28 +0000483 int GetLocatableTypeTag();
484 void ReadTaggedId();
485 void ReadTaggedPosition();
Steve Blocka7e24c12009-10-30 11:49:00 +0000486
487 // If the given mode is wanted, set it in rinfo_ and return true.
488 // Else return false. Used for efficiently skipping unwanted modes.
489 bool SetMode(RelocInfo::Mode mode) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100490 return (mode_mask_ & (1 << mode)) ? (rinfo_.rmode_ = mode, true) : false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000491 }
492
493 byte* pos_;
494 byte* end_;
495 RelocInfo rinfo_;
496 bool done_;
497 int mode_mask_;
Ben Murdoch257744e2011-11-30 15:57:28 +0000498 int last_id_;
499 int last_position_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000500 DISALLOW_COPY_AND_ASSIGN(RelocIterator);
501};
502
503
504//------------------------------------------------------------------------------
505// External function
506
507//----------------------------------------------------------------------------
508class IC_Utility;
509class SCTableReference;
510#ifdef ENABLE_DEBUGGER_SUPPORT
511class Debug_Address;
512#endif
513
514
Steve Blocka7e24c12009-10-30 11:49:00 +0000515// An ExternalReference represents a C++ address used in the generated
516// code. All references to C++ functions and variables must be encapsulated in
517// an ExternalReference instance. This is done in order to track the origin of
518// all external references in the code so that they can be bound to the correct
519// addresses when deserializing a heap.
520class ExternalReference BASE_EMBEDDED {
521 public:
Steve Block1e0659c2011-05-24 12:43:12 +0100522 // Used in the simulator to support different native api calls.
Steve Block1e0659c2011-05-24 12:43:12 +0100523 enum Type {
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100524 // Builtin call.
525 // MaybeObject* f(v8::internal::Arguments).
Steve Block1e0659c2011-05-24 12:43:12 +0100526 BUILTIN_CALL, // default
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100527
Ben Murdoch257744e2011-11-30 15:57:28 +0000528 // Builtin that takes float arguments and returns an int.
529 // int f(double, double).
530 BUILTIN_COMPARE_CALL,
531
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100532 // Builtin call that returns floating point.
533 // double f(double, double).
Ben Murdoch257744e2011-11-30 15:57:28 +0000534 BUILTIN_FP_FP_CALL,
535
536 // Builtin call that returns floating point.
537 // double f(double).
538 BUILTIN_FP_CALL,
539
540 // Builtin call that returns floating point.
541 // double f(double, int).
542 BUILTIN_FP_INT_CALL,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100543
544 // Direct call to API function callback.
545 // Handle<Value> f(v8::Arguments&)
546 DIRECT_API_CALL,
547
548 // Direct call to accessor getter callback.
549 // Handle<value> f(Local<String> property, AccessorInfo& info)
550 DIRECT_GETTER_CALL
Steve Block1e0659c2011-05-24 12:43:12 +0100551 };
552
553 typedef void* ExternalReferenceRedirector(void* original, Type type);
554
Steve Block44f0eee2011-05-26 01:26:41 +0100555 ExternalReference(Builtins::CFunctionId id, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000556
Steve Block44f0eee2011-05-26 01:26:41 +0100557 ExternalReference(ApiFunction* ptr, Type type, Isolate* isolate);
Steve Blockd0582a62009-12-15 09:54:21 +0000558
Steve Block44f0eee2011-05-26 01:26:41 +0100559 ExternalReference(Builtins::Name name, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000560
Steve Block44f0eee2011-05-26 01:26:41 +0100561 ExternalReference(Runtime::FunctionId id, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000562
Steve Block44f0eee2011-05-26 01:26:41 +0100563 ExternalReference(const Runtime::Function* f, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000564
Steve Block44f0eee2011-05-26 01:26:41 +0100565 ExternalReference(const IC_Utility& ic_utility, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000566
567#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Block44f0eee2011-05-26 01:26:41 +0100568 ExternalReference(const Debug_Address& debug_address, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000569#endif
570
571 explicit ExternalReference(StatsCounter* counter);
572
Steve Block44f0eee2011-05-26 01:26:41 +0100573 ExternalReference(Isolate::AddressId id, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000574
575 explicit ExternalReference(const SCTableReference& table_ref);
576
Steve Block44f0eee2011-05-26 01:26:41 +0100577 // Isolate::Current() as an external reference.
578 static ExternalReference isolate_address();
579
Steve Blocka7e24c12009-10-30 11:49:00 +0000580 // One-of-a-kind references. These references are not part of a general
581 // pattern. This means that they have to be added to the
582 // ExternalReferenceTable in serialize.cc manually.
583
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000584 static ExternalReference incremental_marking_record_write_function(
585 Isolate* isolate);
586 static ExternalReference incremental_evacuation_record_write_function(
587 Isolate* isolate);
588 static ExternalReference store_buffer_overflow_function(
589 Isolate* isolate);
590 static ExternalReference flush_icache_function(Isolate* isolate);
Steve Block44f0eee2011-05-26 01:26:41 +0100591 static ExternalReference perform_gc_function(Isolate* isolate);
592 static ExternalReference fill_heap_number_with_random_function(
593 Isolate* isolate);
594 static ExternalReference random_uint32_function(Isolate* isolate);
595 static ExternalReference transcendental_cache_array_address(Isolate* isolate);
596 static ExternalReference delete_handle_scope_extensions(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000597
Ben Murdochb0fe1622011-05-05 13:52:32 +0100598 // Deoptimization support.
Steve Block44f0eee2011-05-26 01:26:41 +0100599 static ExternalReference new_deoptimizer_function(Isolate* isolate);
600 static ExternalReference compute_output_frames_function(Isolate* isolate);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100601
Leon Clarkee46be812010-01-19 14:06:41 +0000602 // Static data in the keyed lookup cache.
Steve Block44f0eee2011-05-26 01:26:41 +0100603 static ExternalReference keyed_lookup_cache_keys(Isolate* isolate);
604 static ExternalReference keyed_lookup_cache_field_offsets(Isolate* isolate);
Leon Clarkee46be812010-01-19 14:06:41 +0000605
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000606 // Static variable Heap::roots_array_start()
607 static ExternalReference roots_array_start(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000608
609 // Static variable StackGuard::address_of_jslimit()
Steve Block44f0eee2011-05-26 01:26:41 +0100610 static ExternalReference address_of_stack_limit(Isolate* isolate);
Steve Blockd0582a62009-12-15 09:54:21 +0000611
612 // Static variable StackGuard::address_of_real_jslimit()
Steve Block44f0eee2011-05-26 01:26:41 +0100613 static ExternalReference address_of_real_stack_limit(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000614
615 // Static variable RegExpStack::limit_address()
Steve Block44f0eee2011-05-26 01:26:41 +0100616 static ExternalReference address_of_regexp_stack_limit(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000617
Leon Clarkee46be812010-01-19 14:06:41 +0000618 // Static variables for RegExp.
Steve Block44f0eee2011-05-26 01:26:41 +0100619 static ExternalReference address_of_static_offsets_vector(Isolate* isolate);
620 static ExternalReference address_of_regexp_stack_memory_address(
621 Isolate* isolate);
622 static ExternalReference address_of_regexp_stack_memory_size(
623 Isolate* isolate);
Leon Clarkee46be812010-01-19 14:06:41 +0000624
Steve Blocka7e24c12009-10-30 11:49:00 +0000625 // Static variable Heap::NewSpaceStart()
Steve Block44f0eee2011-05-26 01:26:41 +0100626 static ExternalReference new_space_start(Isolate* isolate);
627 static ExternalReference new_space_mask(Isolate* isolate);
628 static ExternalReference heap_always_allocate_scope_depth(Isolate* isolate);
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000629 static ExternalReference new_space_mark_bits(Isolate* isolate);
630
631 // Write barrier.
632 static ExternalReference store_buffer_top(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000633
634 // Used for fast allocation in generated code.
Steve Block44f0eee2011-05-26 01:26:41 +0100635 static ExternalReference new_space_allocation_top_address(Isolate* isolate);
636 static ExternalReference new_space_allocation_limit_address(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000637
Steve Block44f0eee2011-05-26 01:26:41 +0100638 static ExternalReference double_fp_operation(Token::Value operation,
639 Isolate* isolate);
640 static ExternalReference compare_doubles(Isolate* isolate);
641 static ExternalReference power_double_double_function(Isolate* isolate);
642 static ExternalReference power_double_int_function(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000643
Steve Blockd0582a62009-12-15 09:54:21 +0000644 static ExternalReference handle_scope_next_address();
645 static ExternalReference handle_scope_limit_address();
John Reck59135872010-11-02 12:39:01 -0700646 static ExternalReference handle_scope_level_address();
Steve Blockd0582a62009-12-15 09:54:21 +0000647
Steve Block44f0eee2011-05-26 01:26:41 +0100648 static ExternalReference scheduled_exception_address(Isolate* isolate);
Steve Blockd0582a62009-12-15 09:54:21 +0000649
Ben Murdochb0fe1622011-05-05 13:52:32 +0100650 // Static variables containing common double constants.
651 static ExternalReference address_of_min_int();
652 static ExternalReference address_of_one_half();
Ben Murdochb8e0da22011-05-16 14:20:40 +0100653 static ExternalReference address_of_minus_zero();
Ben Murdoch257744e2011-11-30 15:57:28 +0000654 static ExternalReference address_of_zero();
655 static ExternalReference address_of_uint8_max_value();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100656 static ExternalReference address_of_negative_infinity();
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000657 static ExternalReference address_of_canonical_non_hole_nan();
658 static ExternalReference address_of_the_hole_nan();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100659
Steve Block44f0eee2011-05-26 01:26:41 +0100660 static ExternalReference math_sin_double_function(Isolate* isolate);
661 static ExternalReference math_cos_double_function(Isolate* isolate);
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000662 static ExternalReference math_tan_double_function(Isolate* isolate);
Steve Block44f0eee2011-05-26 01:26:41 +0100663 static ExternalReference math_log_double_function(Isolate* isolate);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100664
Steve Blocka7e24c12009-10-30 11:49:00 +0000665 Address address() const {return reinterpret_cast<Address>(address_);}
666
667#ifdef ENABLE_DEBUGGER_SUPPORT
668 // Function Debug::Break()
Steve Block44f0eee2011-05-26 01:26:41 +0100669 static ExternalReference debug_break(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000670
671 // Used to check if single stepping is enabled in generated code.
Steve Block44f0eee2011-05-26 01:26:41 +0100672 static ExternalReference debug_step_in_fp_address(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000673#endif
674
Steve Block6ded16b2010-05-10 14:33:55 +0100675#ifndef V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +0000676 // C functions called from RegExp generated code.
677
678 // Function NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()
Steve Block44f0eee2011-05-26 01:26:41 +0100679 static ExternalReference re_case_insensitive_compare_uc16(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000680
681 // Function RegExpMacroAssembler*::CheckStackGuardState()
Steve Block44f0eee2011-05-26 01:26:41 +0100682 static ExternalReference re_check_stack_guard_state(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000683
684 // Function NativeRegExpMacroAssembler::GrowStack()
Steve Block44f0eee2011-05-26 01:26:41 +0100685 static ExternalReference re_grow_stack(Isolate* isolate);
Leon Clarkee46be812010-01-19 14:06:41 +0000686
687 // byte NativeRegExpMacroAssembler::word_character_bitmap
688 static ExternalReference re_word_character_map();
689
Steve Blocka7e24c12009-10-30 11:49:00 +0000690#endif
691
692 // This lets you register a function that rewrites all external references.
693 // Used by the ARM simulator to catch calls to external references.
Ben Murdoch257744e2011-11-30 15:57:28 +0000694 static void set_redirector(Isolate* isolate,
695 ExternalReferenceRedirector* redirector) {
Steve Block44f0eee2011-05-26 01:26:41 +0100696 // We can't stack them.
Ben Murdoch257744e2011-11-30 15:57:28 +0000697 ASSERT(isolate->external_reference_redirector() == NULL);
698 isolate->set_external_reference_redirector(
Steve Block44f0eee2011-05-26 01:26:41 +0100699 reinterpret_cast<ExternalReferenceRedirectorPointer*>(redirector));
Steve Blocka7e24c12009-10-30 11:49:00 +0000700 }
701
702 private:
703 explicit ExternalReference(void* address)
704 : address_(address) {}
705
Steve Block44f0eee2011-05-26 01:26:41 +0100706 static void* Redirect(Isolate* isolate,
707 void* address,
Steve Block1e0659c2011-05-24 12:43:12 +0100708 Type type = ExternalReference::BUILTIN_CALL) {
Steve Block44f0eee2011-05-26 01:26:41 +0100709 ExternalReferenceRedirector* redirector =
710 reinterpret_cast<ExternalReferenceRedirector*>(
711 isolate->external_reference_redirector());
712 if (redirector == NULL) return address;
713 void* answer = (*redirector)(address, type);
Steve Blockd0582a62009-12-15 09:54:21 +0000714 return answer;
Steve Blocka7e24c12009-10-30 11:49:00 +0000715 }
716
Steve Block44f0eee2011-05-26 01:26:41 +0100717 static void* Redirect(Isolate* isolate,
718 Address address_arg,
Steve Block1e0659c2011-05-24 12:43:12 +0100719 Type type = ExternalReference::BUILTIN_CALL) {
Steve Block44f0eee2011-05-26 01:26:41 +0100720 ExternalReferenceRedirector* redirector =
721 reinterpret_cast<ExternalReferenceRedirector*>(
722 isolate->external_reference_redirector());
Steve Blocka7e24c12009-10-30 11:49:00 +0000723 void* address = reinterpret_cast<void*>(address_arg);
Steve Block44f0eee2011-05-26 01:26:41 +0100724 void* answer = (redirector == NULL) ?
Steve Blockd0582a62009-12-15 09:54:21 +0000725 address :
Steve Block44f0eee2011-05-26 01:26:41 +0100726 (*redirector)(address, type);
Steve Blockd0582a62009-12-15 09:54:21 +0000727 return answer;
Steve Blocka7e24c12009-10-30 11:49:00 +0000728 }
729
730 void* address_;
731};
732
733
734// -----------------------------------------------------------------------------
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800735// Position recording support
736
Ben Murdochb0fe1622011-05-05 13:52:32 +0100737struct PositionState {
738 PositionState() : current_position(RelocInfo::kNoPosition),
739 written_position(RelocInfo::kNoPosition),
740 current_statement_position(RelocInfo::kNoPosition),
741 written_statement_position(RelocInfo::kNoPosition) {}
742
743 int current_position;
744 int written_position;
745
746 int current_statement_position;
747 int written_statement_position;
748};
749
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800750
751class PositionsRecorder BASE_EMBEDDED {
752 public:
753 explicit PositionsRecorder(Assembler* assembler)
Ben Murdochb8e0da22011-05-16 14:20:40 +0100754 : assembler_(assembler) {
755#ifdef ENABLE_GDB_JIT_INTERFACE
756 gdbjit_lineinfo_ = NULL;
757#endif
758 }
759
760#ifdef ENABLE_GDB_JIT_INTERFACE
761 ~PositionsRecorder() {
762 delete gdbjit_lineinfo_;
763 }
764
765 void StartGDBJITLineInfoRecording() {
766 if (FLAG_gdbjit) {
767 gdbjit_lineinfo_ = new GDBJITLineInfo();
768 }
769 }
770
771 GDBJITLineInfo* DetachGDBJITLineInfo() {
772 GDBJITLineInfo* lineinfo = gdbjit_lineinfo_;
773 gdbjit_lineinfo_ = NULL; // To prevent deallocation in destructor.
774 return lineinfo;
775 }
776#endif
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800777
Ben Murdochb0fe1622011-05-05 13:52:32 +0100778 // Set current position to pos.
779 void RecordPosition(int pos);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800780
781 // Set current statement position to pos.
782 void RecordStatementPosition(int pos);
783
784 // Write recorded positions to relocation information.
785 bool WriteRecordedPositions();
786
Ben Murdochb0fe1622011-05-05 13:52:32 +0100787 int current_position() const { return state_.current_position; }
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800788
Ben Murdochb0fe1622011-05-05 13:52:32 +0100789 int current_statement_position() const {
790 return state_.current_statement_position;
791 }
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800792
793 private:
794 Assembler* assembler_;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100795 PositionState state_;
Ben Murdochb8e0da22011-05-16 14:20:40 +0100796#ifdef ENABLE_GDB_JIT_INTERFACE
797 GDBJITLineInfo* gdbjit_lineinfo_;
798#endif
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800799
Ben Murdochb0fe1622011-05-05 13:52:32 +0100800 friend class PreservePositionScope;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800801
Ben Murdochb0fe1622011-05-05 13:52:32 +0100802 DISALLOW_COPY_AND_ASSIGN(PositionsRecorder);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800803};
804
805
Ben Murdochb0fe1622011-05-05 13:52:32 +0100806class PreservePositionScope BASE_EMBEDDED {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800807 public:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100808 explicit PreservePositionScope(PositionsRecorder* positions_recorder)
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800809 : positions_recorder_(positions_recorder),
Ben Murdochb0fe1622011-05-05 13:52:32 +0100810 saved_state_(positions_recorder->state_) {}
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800811
Ben Murdochb0fe1622011-05-05 13:52:32 +0100812 ~PreservePositionScope() {
813 positions_recorder_->state_ = saved_state_;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800814 }
815
816 private:
817 PositionsRecorder* positions_recorder_;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100818 const PositionState saved_state_;
819
820 DISALLOW_COPY_AND_ASSIGN(PreservePositionScope);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800821};
822
823
824// -----------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000825// Utility functions
826
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000827inline bool is_intn(int x, int n) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000828 return -(1 << (n-1)) <= x && x < (1 << (n-1));
829}
830
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000831inline bool is_int8(int x) { return is_intn(x, 8); }
832inline bool is_int16(int x) { return is_intn(x, 16); }
833inline bool is_int18(int x) { return is_intn(x, 18); }
834inline bool is_int24(int x) { return is_intn(x, 24); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000835
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000836inline bool is_uintn(int x, int n) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000837 return (x & -(1 << n)) == 0;
838}
839
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000840inline bool is_uint2(int x) { return is_uintn(x, 2); }
841inline bool is_uint3(int x) { return is_uintn(x, 3); }
842inline bool is_uint4(int x) { return is_uintn(x, 4); }
843inline bool is_uint5(int x) { return is_uintn(x, 5); }
844inline bool is_uint6(int x) { return is_uintn(x, 6); }
845inline bool is_uint8(int x) { return is_uintn(x, 8); }
846inline bool is_uint10(int x) { return is_uintn(x, 10); }
847inline bool is_uint12(int x) { return is_uintn(x, 12); }
848inline bool is_uint16(int x) { return is_uintn(x, 16); }
849inline bool is_uint24(int x) { return is_uintn(x, 24); }
850inline bool is_uint26(int x) { return is_uintn(x, 26); }
851inline bool is_uint28(int x) { return is_uintn(x, 28); }
Andrei Popescu31002712010-02-23 13:46:05 +0000852
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000853inline int NumberOfBitsSet(uint32_t x) {
Andrei Popescu31002712010-02-23 13:46:05 +0000854 unsigned int num_bits_set;
855 for (num_bits_set = 0; x; x >>= 1) {
856 num_bits_set += x & 1;
857 }
858 return num_bits_set;
859}
Steve Blocka7e24c12009-10-30 11:49:00 +0000860
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000861bool EvalComparison(Token::Value op, double op1, double op2);
862
Ben Murdochb0fe1622011-05-05 13:52:32 +0100863// Computes pow(x, y) with the special cases in the spec for Math.pow.
864double power_double_int(double x, int y);
865double power_double_double(double x, double y);
866
Ben Murdoch257744e2011-11-30 15:57:28 +0000867// Helper class for generating code or data associated with the code
868// right after a call instruction. As an example this can be used to
869// generate safepoint data after calls for crankshaft.
870class CallWrapper {
871 public:
872 CallWrapper() { }
873 virtual ~CallWrapper() { }
874 // Called just before emitting a call. Argument is the size of the generated
875 // call code.
876 virtual void BeforeCall(int call_size) const = 0;
877 // Called just after emitting a call, i.e., at the return site for the call.
878 virtual void AfterCall() const = 0;
879};
880
881class NullCallWrapper : public CallWrapper {
882 public:
883 NullCallWrapper() { }
884 virtual ~NullCallWrapper() { }
885 virtual void BeforeCall(int call_size) const { }
886 virtual void AfterCall() const { }
887};
888
Steve Blocka7e24c12009-10-30 11:49:00 +0000889} } // namespace v8::internal
890
891#endif // V8_ASSEMBLER_H_