blob: d28bf437096aceb17059056974bb2436f6fa8827 [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.
33// Copyright 2006-2009 the V8 project authors. All rights reserved.
34
35#ifndef V8_ASSEMBLER_H_
36#define V8_ASSEMBLER_H_
37
38#include "runtime.h"
39#include "top.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000040#include "token.h"
Leon Clarkef7060e22010-06-03 12:02:55 +010041#include "objects.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000042
43namespace v8 {
44namespace internal {
45
46
47// -----------------------------------------------------------------------------
48// Labels represent pc locations; they are typically jump or call targets.
49// After declaration, a label can be freely used to denote known or (yet)
50// unknown pc location. Assembler::bind() is used to bind a label to the
51// current pc. A label can be bound only once.
52
53class Label BASE_EMBEDDED {
54 public:
55 INLINE(Label()) { Unuse(); }
56 INLINE(~Label()) { ASSERT(!is_linked()); }
57
58 INLINE(void Unuse()) { pos_ = 0; }
59
Kristian Monsen0d5e1162010-09-30 15:31:59 +010060 INLINE(bool is_bound() const) { return pos_ < 0; }
Steve Blocka7e24c12009-10-30 11:49:00 +000061 INLINE(bool is_unused() const) { return pos_ == 0; }
62 INLINE(bool is_linked() const) { return pos_ > 0; }
63
64 // Returns the position of bound or linked labels. Cannot be used
65 // for unused labels.
66 int pos() const;
67
68 private:
69 // pos_ encodes both the binding state (via its sign)
70 // and the binding position (via its value) of a label.
71 //
72 // pos_ < 0 bound label, pos() returns the jump target position
73 // pos_ == 0 unused label
74 // pos_ > 0 linked label, pos() returns the last reference position
75 int pos_;
76
77 void bind_to(int pos) {
78 pos_ = -pos - 1;
79 ASSERT(is_bound());
80 }
81 void link_to(int pos) {
82 pos_ = pos + 1;
83 ASSERT(is_linked());
84 }
85
86 friend class Assembler;
87 friend class RegexpAssembler;
88 friend class Displacement;
89 friend class ShadowTarget;
90 friend class RegExpMacroAssemblerIrregexp;
91};
92
93
94// -----------------------------------------------------------------------------
Kristian Monsen0d5e1162010-09-30 15:31:59 +010095// NearLabels are labels used for short jumps (in Intel jargon).
96// NearLabels should be used if it can be guaranteed that the jump range is
97// within -128 to +127. We already use short jumps when jumping backwards,
98// so using a NearLabel will only have performance impact if used for forward
99// jumps.
100class NearLabel BASE_EMBEDDED {
101 public:
102 NearLabel() { Unuse(); }
103 ~NearLabel() { ASSERT(!is_linked()); }
104
105 void Unuse() {
106 pos_ = -1;
107 unresolved_branches_ = 0;
108#ifdef DEBUG
109 for (int i = 0; i < kMaxUnresolvedBranches; i++) {
110 unresolved_positions_[i] = -1;
111 }
112#endif
113 }
114
115 int pos() {
116 ASSERT(is_bound());
117 return pos_;
118 }
119
120 bool is_bound() { return pos_ >= 0; }
121 bool is_linked() { return !is_bound() && unresolved_branches_ > 0; }
122 bool is_unused() { return !is_bound() && unresolved_branches_ == 0; }
123
124 void bind_to(int position) {
125 ASSERT(!is_bound());
126 pos_ = position;
127 }
128
129 void link_to(int position) {
130 ASSERT(!is_bound());
131 ASSERT(unresolved_branches_ < kMaxUnresolvedBranches);
132 unresolved_positions_[unresolved_branches_++] = position;
133 }
134
135 private:
136 static const int kMaxUnresolvedBranches = 8;
137 int pos_;
138 int unresolved_branches_;
139 int unresolved_positions_[kMaxUnresolvedBranches];
140
141 friend class Assembler;
142};
143
144
145// -----------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000146// Relocation information
147
148
149// Relocation information consists of the address (pc) of the datum
150// to which the relocation information applies, the relocation mode
151// (rmode), and an optional data field. The relocation mode may be
152// "descriptive" and not indicate a need for relocation, but simply
153// describe a property of the datum. Such rmodes are useful for GC
154// and nice disassembly output.
155
156class RelocInfo BASE_EMBEDDED {
157 public:
158 // The constant kNoPosition is used with the collecting of source positions
159 // in the relocation information. Two types of source positions are collected
160 // "position" (RelocMode position) and "statement position" (RelocMode
161 // statement_position). The "position" is collected at places in the source
162 // code which are of interest when making stack traces to pin-point the source
163 // location of a stack frame as close as possible. The "statement position" is
164 // collected at the beginning at each statement, and is used to indicate
165 // possible break locations. kNoPosition is used to indicate an
166 // invalid/uninitialized position value.
167 static const int kNoPosition = -1;
168
169 enum Mode {
170 // Please note the order is important (see IsCodeTarget, IsGCRelocMode).
171 CONSTRUCT_CALL, // code target that is a call to a JavaScript constructor.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100172 CODE_TARGET_CONTEXT, // Code target used for contextual loads.
173 DEBUG_BREAK, // Code target for the debugger statement.
174 CODE_TARGET, // Code target which is not any of the above.
Steve Blocka7e24c12009-10-30 11:49:00 +0000175 EMBEDDED_OBJECT,
Steve Blocka7e24c12009-10-30 11:49:00 +0000176
177 // Everything after runtime_entry (inclusive) is not GC'ed.
178 RUNTIME_ENTRY,
179 JS_RETURN, // Marks start of the ExitJSFrame code.
180 COMMENT,
181 POSITION, // See comment for kNoPosition above.
182 STATEMENT_POSITION, // See comment for kNoPosition above.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100183 DEBUG_BREAK_SLOT, // Additional code inserted for debug break slot.
Steve Blocka7e24c12009-10-30 11:49:00 +0000184 EXTERNAL_REFERENCE, // The address of an external C++ function.
185 INTERNAL_REFERENCE, // An address inside the same function.
186
187 // add more as needed
188 // Pseudo-types
189 NUMBER_OF_MODES, // must be no greater than 14 - see RelocInfoWriter
190 NONE, // never recorded
191 LAST_CODE_ENUM = CODE_TARGET,
Leon Clarkef7060e22010-06-03 12:02:55 +0100192 LAST_GCED_ENUM = EMBEDDED_OBJECT
Steve Blocka7e24c12009-10-30 11:49:00 +0000193 };
194
195
196 RelocInfo() {}
197 RelocInfo(byte* pc, Mode rmode, intptr_t data)
198 : pc_(pc), rmode_(rmode), data_(data) {
199 }
200
201 static inline bool IsConstructCall(Mode mode) {
202 return mode == CONSTRUCT_CALL;
203 }
204 static inline bool IsCodeTarget(Mode mode) {
205 return mode <= LAST_CODE_ENUM;
206 }
207 // Is the relocation mode affected by GC?
208 static inline bool IsGCRelocMode(Mode mode) {
209 return mode <= LAST_GCED_ENUM;
210 }
211 static inline bool IsJSReturn(Mode mode) {
212 return mode == JS_RETURN;
213 }
214 static inline bool IsComment(Mode mode) {
215 return mode == COMMENT;
216 }
217 static inline bool IsPosition(Mode mode) {
218 return mode == POSITION || mode == STATEMENT_POSITION;
219 }
220 static inline bool IsStatementPosition(Mode mode) {
221 return mode == STATEMENT_POSITION;
222 }
223 static inline bool IsExternalReference(Mode mode) {
224 return mode == EXTERNAL_REFERENCE;
225 }
226 static inline bool IsInternalReference(Mode mode) {
227 return mode == INTERNAL_REFERENCE;
228 }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100229 static inline bool IsDebugBreakSlot(Mode mode) {
230 return mode == DEBUG_BREAK_SLOT;
231 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000232 static inline int ModeMask(Mode mode) { return 1 << mode; }
233
234 // Accessors
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100235 byte* pc() const { return pc_; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000236 void set_pc(byte* pc) { pc_ = pc; }
237 Mode rmode() const { return rmode_; }
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100238 intptr_t data() const { return data_; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000239
240 // Apply a relocation by delta bytes
241 INLINE(void apply(intptr_t delta));
242
Leon Clarkef7060e22010-06-03 12:02:55 +0100243 // Is the pointer this relocation info refers to coded like a plain pointer
244 // or is it strange in some way (eg relative or patched into a series of
245 // instructions).
246 bool IsCodedSpecially();
247
Steve Blocka7e24c12009-10-30 11:49:00 +0000248 // Read/modify the code target in the branch/call instruction
249 // this relocation applies to;
250 // can only be called if IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY
251 INLINE(Address target_address());
252 INLINE(void set_target_address(Address target));
253 INLINE(Object* target_object());
Steve Block3ce2e202009-11-05 08:53:23 +0000254 INLINE(Handle<Object> target_object_handle(Assembler* origin));
Steve Blocka7e24c12009-10-30 11:49:00 +0000255 INLINE(Object** target_object_address());
256 INLINE(void set_target_object(Object* target));
257
Leon Clarkef7060e22010-06-03 12:02:55 +0100258 // Read the address of the word containing the target_address in an
259 // instruction stream. What this means exactly is architecture-independent.
260 // The only architecture-independent user of this function is the serializer.
261 // The serializer uses it to find out how many raw bytes of instruction to
262 // output before the next target. Architecture-independent code shouldn't
263 // dereference the pointer it gets back from this.
Steve Blocka7e24c12009-10-30 11:49:00 +0000264 INLINE(Address target_address_address());
Leon Clarkef7060e22010-06-03 12:02:55 +0100265 // This indicates how much space a target takes up when deserializing a code
266 // stream. For most architectures this is just the size of a pointer. For
267 // an instruction like movw/movt where the target bits are mixed into the
268 // instruction bits the size of the target will be zero, indicating that the
269 // serializer should not step forwards in memory after a target is resolved
270 // and written. In this case the target_address_address function above
271 // should return the end of the instructions to be patched, allowing the
272 // deserializer to deserialize the instructions as raw bytes and put them in
273 // place, ready to be patched with the target.
274 INLINE(int target_address_size());
Steve Blocka7e24c12009-10-30 11:49:00 +0000275
276 // Read/modify the reference in the instruction this relocation
277 // applies to; can only be called if rmode_ is external_reference
278 INLINE(Address* target_reference_address());
279
280 // Read/modify the address of a call instruction. This is used to relocate
281 // the break points where straight-line code is patched with a call
282 // instruction.
283 INLINE(Address call_address());
284 INLINE(void set_call_address(Address target));
285 INLINE(Object* call_object());
Steve Blocka7e24c12009-10-30 11:49:00 +0000286 INLINE(void set_call_object(Object* target));
Ben Murdochbb769b22010-08-11 14:56:33 +0100287 INLINE(Object** call_object_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000288
Iain Merrick75681382010-08-19 15:07:18 +0100289 template<typename StaticVisitor> inline void Visit();
Leon Clarkef7060e22010-06-03 12:02:55 +0100290 inline void Visit(ObjectVisitor* v);
291
Steve Blocka7e24c12009-10-30 11:49:00 +0000292 // Patch the code with some other code.
293 void PatchCode(byte* instructions, int instruction_count);
294
295 // Patch the code with a call.
296 void PatchCodeWithCall(Address target, int guard_bytes);
Steve Block3ce2e202009-11-05 08:53:23 +0000297
298 // Check whether this return sequence has been patched
299 // with a call to the debugger.
300 INLINE(bool IsPatchedReturnSequence());
Steve Blocka7e24c12009-10-30 11:49:00 +0000301
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100302 // Check whether this debug break slot has been patched with a call to the
303 // debugger.
304 INLINE(bool IsPatchedDebugBreakSlotSequence());
305
Steve Blocka7e24c12009-10-30 11:49:00 +0000306#ifdef ENABLE_DISASSEMBLER
307 // Printing
308 static const char* RelocModeName(Mode rmode);
309 void Print();
310#endif // ENABLE_DISASSEMBLER
311#ifdef DEBUG
312 // Debugging
313 void Verify();
314#endif
315
316 static const int kCodeTargetMask = (1 << (LAST_CODE_ENUM + 1)) - 1;
317 static const int kPositionMask = 1 << POSITION | 1 << STATEMENT_POSITION;
318 static const int kDebugMask = kPositionMask | 1 << COMMENT;
319 static const int kApplyMask; // Modes affected by apply. Depends on arch.
320
321 private:
322 // On ARM, note that pc_ is the address of the constant pool entry
323 // to be relocated and not the address of the instruction
324 // referencing the constant pool entry (except when rmode_ ==
325 // comment).
326 byte* pc_;
327 Mode rmode_;
328 intptr_t data_;
329 friend class RelocIterator;
330};
331
332
333// RelocInfoWriter serializes a stream of relocation info. It writes towards
334// lower addresses.
335class RelocInfoWriter BASE_EMBEDDED {
336 public:
337 RelocInfoWriter() : pos_(NULL), last_pc_(NULL), last_data_(0) {}
338 RelocInfoWriter(byte* pos, byte* pc) : pos_(pos), last_pc_(pc),
339 last_data_(0) {}
340
341 byte* pos() const { return pos_; }
342 byte* last_pc() const { return last_pc_; }
343
344 void Write(const RelocInfo* rinfo);
345
346 // Update the state of the stream after reloc info buffer
347 // and/or code is moved while the stream is active.
348 void Reposition(byte* pos, byte* pc) {
349 pos_ = pos;
350 last_pc_ = pc;
351 }
352
353 // Max size (bytes) of a written RelocInfo. Longest encoding is
354 // ExtraTag, VariableLengthPCJump, ExtraTag, pc_delta, ExtraTag, data_delta.
355 // On ia32 and arm this is 1 + 4 + 1 + 1 + 1 + 4 = 12.
356 // On x64 this is 1 + 4 + 1 + 1 + 1 + 8 == 16;
357 // Here we use the maximum of the two.
358 static const int kMaxSize = 16;
359
360 private:
361 inline uint32_t WriteVariableLengthPCJump(uint32_t pc_delta);
362 inline void WriteTaggedPC(uint32_t pc_delta, int tag);
363 inline void WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag);
364 inline void WriteExtraTaggedData(intptr_t data_delta, int top_tag);
365 inline void WriteTaggedData(intptr_t data_delta, int tag);
366 inline void WriteExtraTag(int extra_tag, int top_tag);
367
368 byte* pos_;
369 byte* last_pc_;
370 intptr_t last_data_;
371 DISALLOW_COPY_AND_ASSIGN(RelocInfoWriter);
372};
373
374
375// A RelocIterator iterates over relocation information.
376// Typical use:
377//
378// for (RelocIterator it(code); !it.done(); it.next()) {
379// // do something with it.rinfo() here
380// }
381//
382// A mask can be specified to skip unwanted modes.
383class RelocIterator: public Malloced {
384 public:
385 // Create a new iterator positioned at
386 // the beginning of the reloc info.
387 // Relocation information with mode k is included in the
388 // iteration iff bit k of mode_mask is set.
389 explicit RelocIterator(Code* code, int mode_mask = -1);
390 explicit RelocIterator(const CodeDesc& desc, int mode_mask = -1);
391
392 // Iteration
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100393 bool done() const { return done_; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000394 void next();
395
396 // Return pointer valid until next next().
397 RelocInfo* rinfo() {
398 ASSERT(!done());
399 return &rinfo_;
400 }
401
402 private:
403 // Advance* moves the position before/after reading.
404 // *Read* reads from current byte(s) into rinfo_.
405 // *Get* just reads and returns info on current byte.
406 void Advance(int bytes = 1) { pos_ -= bytes; }
407 int AdvanceGetTag();
408 int GetExtraTag();
409 int GetTopTag();
410 void ReadTaggedPC();
411 void AdvanceReadPC();
412 void AdvanceReadData();
413 void AdvanceReadVariableLengthPCJump();
414 int GetPositionTypeTag();
415 void ReadTaggedData();
416
417 static RelocInfo::Mode DebugInfoModeFromTag(int tag);
418
419 // If the given mode is wanted, set it in rinfo_ and return true.
420 // Else return false. Used for efficiently skipping unwanted modes.
421 bool SetMode(RelocInfo::Mode mode) {
422 return (mode_mask_ & 1 << mode) ? (rinfo_.rmode_ = mode, true) : false;
423 }
424
425 byte* pos_;
426 byte* end_;
427 RelocInfo rinfo_;
428 bool done_;
429 int mode_mask_;
430 DISALLOW_COPY_AND_ASSIGN(RelocIterator);
431};
432
433
434//------------------------------------------------------------------------------
435// External function
436
437//----------------------------------------------------------------------------
438class IC_Utility;
439class SCTableReference;
440#ifdef ENABLE_DEBUGGER_SUPPORT
441class Debug_Address;
442#endif
443
444
445typedef void* ExternalReferenceRedirector(void* original, bool fp_return);
446
447
448// An ExternalReference represents a C++ address used in the generated
449// code. All references to C++ functions and variables must be encapsulated in
450// an ExternalReference instance. This is done in order to track the origin of
451// all external references in the code so that they can be bound to the correct
452// addresses when deserializing a heap.
453class ExternalReference BASE_EMBEDDED {
454 public:
455 explicit ExternalReference(Builtins::CFunctionId id);
456
Steve Blockd0582a62009-12-15 09:54:21 +0000457 explicit ExternalReference(ApiFunction* ptr);
458
Steve Blocka7e24c12009-10-30 11:49:00 +0000459 explicit ExternalReference(Builtins::Name name);
460
461 explicit ExternalReference(Runtime::FunctionId id);
462
463 explicit ExternalReference(Runtime::Function* f);
464
465 explicit ExternalReference(const IC_Utility& ic_utility);
466
467#ifdef ENABLE_DEBUGGER_SUPPORT
468 explicit ExternalReference(const Debug_Address& debug_address);
469#endif
470
471 explicit ExternalReference(StatsCounter* counter);
472
473 explicit ExternalReference(Top::AddressId id);
474
475 explicit ExternalReference(const SCTableReference& table_ref);
476
477 // One-of-a-kind references. These references are not part of a general
478 // pattern. This means that they have to be added to the
479 // ExternalReferenceTable in serialize.cc manually.
480
481 static ExternalReference perform_gc_function();
Steve Block6ded16b2010-05-10 14:33:55 +0100482 static ExternalReference fill_heap_number_with_random_function();
483 static ExternalReference random_uint32_function();
Andrei Popescu402d9372010-02-26 13:31:12 +0000484 static ExternalReference transcendental_cache_array_address();
Steve Blocka7e24c12009-10-30 11:49:00 +0000485
Leon Clarkee46be812010-01-19 14:06:41 +0000486 // Static data in the keyed lookup cache.
487 static ExternalReference keyed_lookup_cache_keys();
488 static ExternalReference keyed_lookup_cache_field_offsets();
489
Steve Blocka7e24c12009-10-30 11:49:00 +0000490 // Static variable Factory::the_hole_value.location()
491 static ExternalReference the_hole_value_location();
492
493 // Static variable Heap::roots_address()
494 static ExternalReference roots_address();
495
496 // Static variable StackGuard::address_of_jslimit()
Steve Blockd0582a62009-12-15 09:54:21 +0000497 static ExternalReference address_of_stack_limit();
498
499 // Static variable StackGuard::address_of_real_jslimit()
500 static ExternalReference address_of_real_stack_limit();
Steve Blocka7e24c12009-10-30 11:49:00 +0000501
502 // Static variable RegExpStack::limit_address()
503 static ExternalReference address_of_regexp_stack_limit();
504
Leon Clarkee46be812010-01-19 14:06:41 +0000505 // Static variables for RegExp.
506 static ExternalReference address_of_static_offsets_vector();
507 static ExternalReference address_of_regexp_stack_memory_address();
508 static ExternalReference address_of_regexp_stack_memory_size();
509
Steve Blocka7e24c12009-10-30 11:49:00 +0000510 // Static variable Heap::NewSpaceStart()
511 static ExternalReference new_space_start();
Andrei Popescu402d9372010-02-26 13:31:12 +0000512 static ExternalReference new_space_mask();
Steve Blocka7e24c12009-10-30 11:49:00 +0000513 static ExternalReference heap_always_allocate_scope_depth();
514
515 // Used for fast allocation in generated code.
516 static ExternalReference new_space_allocation_top_address();
517 static ExternalReference new_space_allocation_limit_address();
518
519 static ExternalReference double_fp_operation(Token::Value operation);
520 static ExternalReference compare_doubles();
521
Steve Blockd0582a62009-12-15 09:54:21 +0000522 static ExternalReference handle_scope_extensions_address();
523 static ExternalReference handle_scope_next_address();
524 static ExternalReference handle_scope_limit_address();
525
526 static ExternalReference scheduled_exception_address();
527
Steve Blocka7e24c12009-10-30 11:49:00 +0000528 Address address() const {return reinterpret_cast<Address>(address_);}
529
530#ifdef ENABLE_DEBUGGER_SUPPORT
531 // Function Debug::Break()
532 static ExternalReference debug_break();
533
534 // Used to check if single stepping is enabled in generated code.
535 static ExternalReference debug_step_in_fp_address();
536#endif
537
Steve Block6ded16b2010-05-10 14:33:55 +0100538#ifndef V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +0000539 // C functions called from RegExp generated code.
540
541 // Function NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()
542 static ExternalReference re_case_insensitive_compare_uc16();
543
544 // Function RegExpMacroAssembler*::CheckStackGuardState()
545 static ExternalReference re_check_stack_guard_state();
546
547 // Function NativeRegExpMacroAssembler::GrowStack()
548 static ExternalReference re_grow_stack();
Leon Clarkee46be812010-01-19 14:06:41 +0000549
550 // byte NativeRegExpMacroAssembler::word_character_bitmap
551 static ExternalReference re_word_character_map();
552
Steve Blocka7e24c12009-10-30 11:49:00 +0000553#endif
554
555 // This lets you register a function that rewrites all external references.
556 // Used by the ARM simulator to catch calls to external references.
557 static void set_redirector(ExternalReferenceRedirector* redirector) {
558 ASSERT(redirector_ == NULL); // We can't stack them.
559 redirector_ = redirector;
560 }
561
562 private:
563 explicit ExternalReference(void* address)
564 : address_(address) {}
565
566 static ExternalReferenceRedirector* redirector_;
567
568 static void* Redirect(void* address, bool fp_return = false) {
569 if (redirector_ == NULL) return address;
Steve Blockd0582a62009-12-15 09:54:21 +0000570 void* answer = (*redirector_)(address, fp_return);
571 return answer;
Steve Blocka7e24c12009-10-30 11:49:00 +0000572 }
573
574 static void* Redirect(Address address_arg, bool fp_return = false) {
575 void* address = reinterpret_cast<void*>(address_arg);
Steve Blockd0582a62009-12-15 09:54:21 +0000576 void* answer = (redirector_ == NULL) ?
577 address :
578 (*redirector_)(address, fp_return);
579 return answer;
Steve Blocka7e24c12009-10-30 11:49:00 +0000580 }
581
582 void* address_;
583};
584
585
586// -----------------------------------------------------------------------------
587// Utility functions
588
589static inline bool is_intn(int x, int n) {
590 return -(1 << (n-1)) <= x && x < (1 << (n-1));
591}
592
Steve Blocka7e24c12009-10-30 11:49:00 +0000593static inline bool is_int8(int x) { return is_intn(x, 8); }
Andrei Popescu31002712010-02-23 13:46:05 +0000594static inline bool is_int16(int x) { return is_intn(x, 16); }
595static inline bool is_int18(int x) { return is_intn(x, 18); }
596static inline bool is_int24(int x) { return is_intn(x, 24); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000597
598static inline bool is_uintn(int x, int n) {
599 return (x & -(1 << n)) == 0;
600}
601
602static inline bool is_uint2(int x) { return is_uintn(x, 2); }
603static inline bool is_uint3(int x) { return is_uintn(x, 3); }
604static inline bool is_uint4(int x) { return is_uintn(x, 4); }
605static inline bool is_uint5(int x) { return is_uintn(x, 5); }
606static inline bool is_uint6(int x) { return is_uintn(x, 6); }
607static inline bool is_uint8(int x) { return is_uintn(x, 8); }
Andrei Popescu31002712010-02-23 13:46:05 +0000608static inline bool is_uint10(int x) { return is_uintn(x, 10); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000609static inline bool is_uint12(int x) { return is_uintn(x, 12); }
610static inline bool is_uint16(int x) { return is_uintn(x, 16); }
611static inline bool is_uint24(int x) { return is_uintn(x, 24); }
Andrei Popescu31002712010-02-23 13:46:05 +0000612static inline bool is_uint26(int x) { return is_uintn(x, 26); }
613static inline bool is_uint28(int x) { return is_uintn(x, 28); }
614
615static inline int NumberOfBitsSet(uint32_t x) {
616 unsigned int num_bits_set;
617 for (num_bits_set = 0; x; x >>= 1) {
618 num_bits_set += x & 1;
619 }
620 return num_bits_set;
621}
Steve Blocka7e24c12009-10-30 11:49:00 +0000622
623} } // namespace v8::internal
624
625#endif // V8_ASSEMBLER_H_