blob: fb75d6dc2282f308a5fe15483cd7d3e230bf70b0 [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
60 INLINE(bool is_bound() const) { return pos_ < 0; }
61 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// -----------------------------------------------------------------------------
95// Relocation information
96
97
98// Relocation information consists of the address (pc) of the datum
99// to which the relocation information applies, the relocation mode
100// (rmode), and an optional data field. The relocation mode may be
101// "descriptive" and not indicate a need for relocation, but simply
102// describe a property of the datum. Such rmodes are useful for GC
103// and nice disassembly output.
104
105class RelocInfo BASE_EMBEDDED {
106 public:
107 // The constant kNoPosition is used with the collecting of source positions
108 // in the relocation information. Two types of source positions are collected
109 // "position" (RelocMode position) and "statement position" (RelocMode
110 // statement_position). The "position" is collected at places in the source
111 // code which are of interest when making stack traces to pin-point the source
112 // location of a stack frame as close as possible. The "statement position" is
113 // collected at the beginning at each statement, and is used to indicate
114 // possible break locations. kNoPosition is used to indicate an
115 // invalid/uninitialized position value.
116 static const int kNoPosition = -1;
117
118 enum Mode {
119 // Please note the order is important (see IsCodeTarget, IsGCRelocMode).
120 CONSTRUCT_CALL, // code target that is a call to a JavaScript constructor.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100121 CODE_TARGET_CONTEXT, // Code target used for contextual loads.
122 DEBUG_BREAK, // Code target for the debugger statement.
123 CODE_TARGET, // Code target which is not any of the above.
Steve Blocka7e24c12009-10-30 11:49:00 +0000124 EMBEDDED_OBJECT,
Steve Blocka7e24c12009-10-30 11:49:00 +0000125
126 // Everything after runtime_entry (inclusive) is not GC'ed.
127 RUNTIME_ENTRY,
128 JS_RETURN, // Marks start of the ExitJSFrame code.
129 COMMENT,
130 POSITION, // See comment for kNoPosition above.
131 STATEMENT_POSITION, // See comment for kNoPosition above.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100132 DEBUG_BREAK_SLOT, // Additional code inserted for debug break slot.
Steve Blocka7e24c12009-10-30 11:49:00 +0000133 EXTERNAL_REFERENCE, // The address of an external C++ function.
134 INTERNAL_REFERENCE, // An address inside the same function.
135
136 // add more as needed
137 // Pseudo-types
138 NUMBER_OF_MODES, // must be no greater than 14 - see RelocInfoWriter
139 NONE, // never recorded
140 LAST_CODE_ENUM = CODE_TARGET,
Leon Clarkef7060e22010-06-03 12:02:55 +0100141 LAST_GCED_ENUM = EMBEDDED_OBJECT
Steve Blocka7e24c12009-10-30 11:49:00 +0000142 };
143
144
145 RelocInfo() {}
146 RelocInfo(byte* pc, Mode rmode, intptr_t data)
147 : pc_(pc), rmode_(rmode), data_(data) {
148 }
149
150 static inline bool IsConstructCall(Mode mode) {
151 return mode == CONSTRUCT_CALL;
152 }
153 static inline bool IsCodeTarget(Mode mode) {
154 return mode <= LAST_CODE_ENUM;
155 }
156 // Is the relocation mode affected by GC?
157 static inline bool IsGCRelocMode(Mode mode) {
158 return mode <= LAST_GCED_ENUM;
159 }
160 static inline bool IsJSReturn(Mode mode) {
161 return mode == JS_RETURN;
162 }
163 static inline bool IsComment(Mode mode) {
164 return mode == COMMENT;
165 }
166 static inline bool IsPosition(Mode mode) {
167 return mode == POSITION || mode == STATEMENT_POSITION;
168 }
169 static inline bool IsStatementPosition(Mode mode) {
170 return mode == STATEMENT_POSITION;
171 }
172 static inline bool IsExternalReference(Mode mode) {
173 return mode == EXTERNAL_REFERENCE;
174 }
175 static inline bool IsInternalReference(Mode mode) {
176 return mode == INTERNAL_REFERENCE;
177 }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100178 static inline bool IsDebugBreakSlot(Mode mode) {
179 return mode == DEBUG_BREAK_SLOT;
180 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000181 static inline int ModeMask(Mode mode) { return 1 << mode; }
182
183 // Accessors
184 byte* pc() const { return pc_; }
185 void set_pc(byte* pc) { pc_ = pc; }
186 Mode rmode() const { return rmode_; }
187 intptr_t data() const { return data_; }
188
189 // Apply a relocation by delta bytes
190 INLINE(void apply(intptr_t delta));
191
Leon Clarkef7060e22010-06-03 12:02:55 +0100192 // Is the pointer this relocation info refers to coded like a plain pointer
193 // or is it strange in some way (eg relative or patched into a series of
194 // instructions).
195 bool IsCodedSpecially();
196
Steve Blocka7e24c12009-10-30 11:49:00 +0000197 // Read/modify the code target in the branch/call instruction
198 // this relocation applies to;
199 // can only be called if IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY
200 INLINE(Address target_address());
201 INLINE(void set_target_address(Address target));
202 INLINE(Object* target_object());
Steve Block3ce2e202009-11-05 08:53:23 +0000203 INLINE(Handle<Object> target_object_handle(Assembler* origin));
Steve Blocka7e24c12009-10-30 11:49:00 +0000204 INLINE(Object** target_object_address());
205 INLINE(void set_target_object(Object* target));
206
Leon Clarkef7060e22010-06-03 12:02:55 +0100207 // Read the address of the word containing the target_address in an
208 // instruction stream. What this means exactly is architecture-independent.
209 // The only architecture-independent user of this function is the serializer.
210 // The serializer uses it to find out how many raw bytes of instruction to
211 // output before the next target. Architecture-independent code shouldn't
212 // dereference the pointer it gets back from this.
Steve Blocka7e24c12009-10-30 11:49:00 +0000213 INLINE(Address target_address_address());
Leon Clarkef7060e22010-06-03 12:02:55 +0100214 // This indicates how much space a target takes up when deserializing a code
215 // stream. For most architectures this is just the size of a pointer. For
216 // an instruction like movw/movt where the target bits are mixed into the
217 // instruction bits the size of the target will be zero, indicating that the
218 // serializer should not step forwards in memory after a target is resolved
219 // and written. In this case the target_address_address function above
220 // should return the end of the instructions to be patched, allowing the
221 // deserializer to deserialize the instructions as raw bytes and put them in
222 // place, ready to be patched with the target.
223 INLINE(int target_address_size());
Steve Blocka7e24c12009-10-30 11:49:00 +0000224
225 // Read/modify the reference in the instruction this relocation
226 // applies to; can only be called if rmode_ is external_reference
227 INLINE(Address* target_reference_address());
228
229 // Read/modify the address of a call instruction. This is used to relocate
230 // the break points where straight-line code is patched with a call
231 // instruction.
232 INLINE(Address call_address());
233 INLINE(void set_call_address(Address target));
234 INLINE(Object* call_object());
235 INLINE(Object** call_object_address());
236 INLINE(void set_call_object(Object* target));
237
Leon Clarkef7060e22010-06-03 12:02:55 +0100238 inline void Visit(ObjectVisitor* v);
239
Steve Blocka7e24c12009-10-30 11:49:00 +0000240 // Patch the code with some other code.
241 void PatchCode(byte* instructions, int instruction_count);
242
243 // Patch the code with a call.
244 void PatchCodeWithCall(Address target, int guard_bytes);
Steve Block3ce2e202009-11-05 08:53:23 +0000245
246 // Check whether this return sequence has been patched
247 // with a call to the debugger.
248 INLINE(bool IsPatchedReturnSequence());
Steve Blocka7e24c12009-10-30 11:49:00 +0000249
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100250 // Check whether this debug break slot has been patched with a call to the
251 // debugger.
252 INLINE(bool IsPatchedDebugBreakSlotSequence());
253
Steve Blocka7e24c12009-10-30 11:49:00 +0000254#ifdef ENABLE_DISASSEMBLER
255 // Printing
256 static const char* RelocModeName(Mode rmode);
257 void Print();
258#endif // ENABLE_DISASSEMBLER
259#ifdef DEBUG
260 // Debugging
261 void Verify();
262#endif
263
264 static const int kCodeTargetMask = (1 << (LAST_CODE_ENUM + 1)) - 1;
265 static const int kPositionMask = 1 << POSITION | 1 << STATEMENT_POSITION;
266 static const int kDebugMask = kPositionMask | 1 << COMMENT;
267 static const int kApplyMask; // Modes affected by apply. Depends on arch.
268
269 private:
270 // On ARM, note that pc_ is the address of the constant pool entry
271 // to be relocated and not the address of the instruction
272 // referencing the constant pool entry (except when rmode_ ==
273 // comment).
274 byte* pc_;
275 Mode rmode_;
276 intptr_t data_;
277 friend class RelocIterator;
278};
279
280
281// RelocInfoWriter serializes a stream of relocation info. It writes towards
282// lower addresses.
283class RelocInfoWriter BASE_EMBEDDED {
284 public:
285 RelocInfoWriter() : pos_(NULL), last_pc_(NULL), last_data_(0) {}
286 RelocInfoWriter(byte* pos, byte* pc) : pos_(pos), last_pc_(pc),
287 last_data_(0) {}
288
289 byte* pos() const { return pos_; }
290 byte* last_pc() const { return last_pc_; }
291
292 void Write(const RelocInfo* rinfo);
293
294 // Update the state of the stream after reloc info buffer
295 // and/or code is moved while the stream is active.
296 void Reposition(byte* pos, byte* pc) {
297 pos_ = pos;
298 last_pc_ = pc;
299 }
300
301 // Max size (bytes) of a written RelocInfo. Longest encoding is
302 // ExtraTag, VariableLengthPCJump, ExtraTag, pc_delta, ExtraTag, data_delta.
303 // On ia32 and arm this is 1 + 4 + 1 + 1 + 1 + 4 = 12.
304 // On x64 this is 1 + 4 + 1 + 1 + 1 + 8 == 16;
305 // Here we use the maximum of the two.
306 static const int kMaxSize = 16;
307
308 private:
309 inline uint32_t WriteVariableLengthPCJump(uint32_t pc_delta);
310 inline void WriteTaggedPC(uint32_t pc_delta, int tag);
311 inline void WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag);
312 inline void WriteExtraTaggedData(intptr_t data_delta, int top_tag);
313 inline void WriteTaggedData(intptr_t data_delta, int tag);
314 inline void WriteExtraTag(int extra_tag, int top_tag);
315
316 byte* pos_;
317 byte* last_pc_;
318 intptr_t last_data_;
319 DISALLOW_COPY_AND_ASSIGN(RelocInfoWriter);
320};
321
322
323// A RelocIterator iterates over relocation information.
324// Typical use:
325//
326// for (RelocIterator it(code); !it.done(); it.next()) {
327// // do something with it.rinfo() here
328// }
329//
330// A mask can be specified to skip unwanted modes.
331class RelocIterator: public Malloced {
332 public:
333 // Create a new iterator positioned at
334 // the beginning of the reloc info.
335 // Relocation information with mode k is included in the
336 // iteration iff bit k of mode_mask is set.
337 explicit RelocIterator(Code* code, int mode_mask = -1);
338 explicit RelocIterator(const CodeDesc& desc, int mode_mask = -1);
339
340 // Iteration
341 bool done() const { return done_; }
342 void next();
343
344 // Return pointer valid until next next().
345 RelocInfo* rinfo() {
346 ASSERT(!done());
347 return &rinfo_;
348 }
349
350 private:
351 // Advance* moves the position before/after reading.
352 // *Read* reads from current byte(s) into rinfo_.
353 // *Get* just reads and returns info on current byte.
354 void Advance(int bytes = 1) { pos_ -= bytes; }
355 int AdvanceGetTag();
356 int GetExtraTag();
357 int GetTopTag();
358 void ReadTaggedPC();
359 void AdvanceReadPC();
360 void AdvanceReadData();
361 void AdvanceReadVariableLengthPCJump();
362 int GetPositionTypeTag();
363 void ReadTaggedData();
364
365 static RelocInfo::Mode DebugInfoModeFromTag(int tag);
366
367 // If the given mode is wanted, set it in rinfo_ and return true.
368 // Else return false. Used for efficiently skipping unwanted modes.
369 bool SetMode(RelocInfo::Mode mode) {
370 return (mode_mask_ & 1 << mode) ? (rinfo_.rmode_ = mode, true) : false;
371 }
372
373 byte* pos_;
374 byte* end_;
375 RelocInfo rinfo_;
376 bool done_;
377 int mode_mask_;
378 DISALLOW_COPY_AND_ASSIGN(RelocIterator);
379};
380
381
382//------------------------------------------------------------------------------
383// External function
384
385//----------------------------------------------------------------------------
386class IC_Utility;
387class SCTableReference;
388#ifdef ENABLE_DEBUGGER_SUPPORT
389class Debug_Address;
390#endif
391
392
393typedef void* ExternalReferenceRedirector(void* original, bool fp_return);
394
395
396// An ExternalReference represents a C++ address used in the generated
397// code. All references to C++ functions and variables must be encapsulated in
398// an ExternalReference instance. This is done in order to track the origin of
399// all external references in the code so that they can be bound to the correct
400// addresses when deserializing a heap.
401class ExternalReference BASE_EMBEDDED {
402 public:
403 explicit ExternalReference(Builtins::CFunctionId id);
404
Steve Blockd0582a62009-12-15 09:54:21 +0000405 explicit ExternalReference(ApiFunction* ptr);
406
Steve Blocka7e24c12009-10-30 11:49:00 +0000407 explicit ExternalReference(Builtins::Name name);
408
409 explicit ExternalReference(Runtime::FunctionId id);
410
411 explicit ExternalReference(Runtime::Function* f);
412
413 explicit ExternalReference(const IC_Utility& ic_utility);
414
415#ifdef ENABLE_DEBUGGER_SUPPORT
416 explicit ExternalReference(const Debug_Address& debug_address);
417#endif
418
419 explicit ExternalReference(StatsCounter* counter);
420
421 explicit ExternalReference(Top::AddressId id);
422
423 explicit ExternalReference(const SCTableReference& table_ref);
424
425 // One-of-a-kind references. These references are not part of a general
426 // pattern. This means that they have to be added to the
427 // ExternalReferenceTable in serialize.cc manually.
428
429 static ExternalReference perform_gc_function();
Steve Block6ded16b2010-05-10 14:33:55 +0100430 static ExternalReference fill_heap_number_with_random_function();
431 static ExternalReference random_uint32_function();
Andrei Popescu402d9372010-02-26 13:31:12 +0000432 static ExternalReference transcendental_cache_array_address();
Steve Blocka7e24c12009-10-30 11:49:00 +0000433
Leon Clarkee46be812010-01-19 14:06:41 +0000434 // Static data in the keyed lookup cache.
435 static ExternalReference keyed_lookup_cache_keys();
436 static ExternalReference keyed_lookup_cache_field_offsets();
437
Steve Blocka7e24c12009-10-30 11:49:00 +0000438 // Static variable Factory::the_hole_value.location()
439 static ExternalReference the_hole_value_location();
440
441 // Static variable Heap::roots_address()
442 static ExternalReference roots_address();
443
444 // Static variable StackGuard::address_of_jslimit()
Steve Blockd0582a62009-12-15 09:54:21 +0000445 static ExternalReference address_of_stack_limit();
446
447 // Static variable StackGuard::address_of_real_jslimit()
448 static ExternalReference address_of_real_stack_limit();
Steve Blocka7e24c12009-10-30 11:49:00 +0000449
450 // Static variable RegExpStack::limit_address()
451 static ExternalReference address_of_regexp_stack_limit();
452
Leon Clarkee46be812010-01-19 14:06:41 +0000453 // Static variables for RegExp.
454 static ExternalReference address_of_static_offsets_vector();
455 static ExternalReference address_of_regexp_stack_memory_address();
456 static ExternalReference address_of_regexp_stack_memory_size();
457
Steve Blocka7e24c12009-10-30 11:49:00 +0000458 // Static variable Heap::NewSpaceStart()
459 static ExternalReference new_space_start();
Andrei Popescu402d9372010-02-26 13:31:12 +0000460 static ExternalReference new_space_mask();
Steve Blocka7e24c12009-10-30 11:49:00 +0000461 static ExternalReference heap_always_allocate_scope_depth();
462
463 // Used for fast allocation in generated code.
464 static ExternalReference new_space_allocation_top_address();
465 static ExternalReference new_space_allocation_limit_address();
466
467 static ExternalReference double_fp_operation(Token::Value operation);
468 static ExternalReference compare_doubles();
469
Steve Blockd0582a62009-12-15 09:54:21 +0000470 static ExternalReference handle_scope_extensions_address();
471 static ExternalReference handle_scope_next_address();
472 static ExternalReference handle_scope_limit_address();
473
474 static ExternalReference scheduled_exception_address();
475
Steve Blocka7e24c12009-10-30 11:49:00 +0000476 Address address() const {return reinterpret_cast<Address>(address_);}
477
478#ifdef ENABLE_DEBUGGER_SUPPORT
479 // Function Debug::Break()
480 static ExternalReference debug_break();
481
482 // Used to check if single stepping is enabled in generated code.
483 static ExternalReference debug_step_in_fp_address();
484#endif
485
Steve Block6ded16b2010-05-10 14:33:55 +0100486#ifndef V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +0000487 // C functions called from RegExp generated code.
488
489 // Function NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()
490 static ExternalReference re_case_insensitive_compare_uc16();
491
492 // Function RegExpMacroAssembler*::CheckStackGuardState()
493 static ExternalReference re_check_stack_guard_state();
494
495 // Function NativeRegExpMacroAssembler::GrowStack()
496 static ExternalReference re_grow_stack();
Leon Clarkee46be812010-01-19 14:06:41 +0000497
498 // byte NativeRegExpMacroAssembler::word_character_bitmap
499 static ExternalReference re_word_character_map();
500
Steve Blocka7e24c12009-10-30 11:49:00 +0000501#endif
502
503 // This lets you register a function that rewrites all external references.
504 // Used by the ARM simulator to catch calls to external references.
505 static void set_redirector(ExternalReferenceRedirector* redirector) {
506 ASSERT(redirector_ == NULL); // We can't stack them.
507 redirector_ = redirector;
508 }
509
510 private:
511 explicit ExternalReference(void* address)
512 : address_(address) {}
513
514 static ExternalReferenceRedirector* redirector_;
515
516 static void* Redirect(void* address, bool fp_return = false) {
517 if (redirector_ == NULL) return address;
Steve Blockd0582a62009-12-15 09:54:21 +0000518 void* answer = (*redirector_)(address, fp_return);
519 return answer;
Steve Blocka7e24c12009-10-30 11:49:00 +0000520 }
521
522 static void* Redirect(Address address_arg, bool fp_return = false) {
523 void* address = reinterpret_cast<void*>(address_arg);
Steve Blockd0582a62009-12-15 09:54:21 +0000524 void* answer = (redirector_ == NULL) ?
525 address :
526 (*redirector_)(address, fp_return);
527 return answer;
Steve Blocka7e24c12009-10-30 11:49:00 +0000528 }
529
530 void* address_;
531};
532
533
534// -----------------------------------------------------------------------------
535// Utility functions
536
537static inline bool is_intn(int x, int n) {
538 return -(1 << (n-1)) <= x && x < (1 << (n-1));
539}
540
Steve Blocka7e24c12009-10-30 11:49:00 +0000541static inline bool is_int8(int x) { return is_intn(x, 8); }
Andrei Popescu31002712010-02-23 13:46:05 +0000542static inline bool is_int16(int x) { return is_intn(x, 16); }
543static inline bool is_int18(int x) { return is_intn(x, 18); }
544static inline bool is_int24(int x) { return is_intn(x, 24); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000545
546static inline bool is_uintn(int x, int n) {
547 return (x & -(1 << n)) == 0;
548}
549
550static inline bool is_uint2(int x) { return is_uintn(x, 2); }
551static inline bool is_uint3(int x) { return is_uintn(x, 3); }
552static inline bool is_uint4(int x) { return is_uintn(x, 4); }
553static inline bool is_uint5(int x) { return is_uintn(x, 5); }
554static inline bool is_uint6(int x) { return is_uintn(x, 6); }
555static inline bool is_uint8(int x) { return is_uintn(x, 8); }
Andrei Popescu31002712010-02-23 13:46:05 +0000556static inline bool is_uint10(int x) { return is_uintn(x, 10); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000557static inline bool is_uint12(int x) { return is_uintn(x, 12); }
558static inline bool is_uint16(int x) { return is_uintn(x, 16); }
559static inline bool is_uint24(int x) { return is_uintn(x, 24); }
Andrei Popescu31002712010-02-23 13:46:05 +0000560static inline bool is_uint26(int x) { return is_uintn(x, 26); }
561static inline bool is_uint28(int x) { return is_uintn(x, 28); }
562
563static inline int NumberOfBitsSet(uint32_t x) {
564 unsigned int num_bits_set;
565 for (num_bits_set = 0; x; x >>= 1) {
566 num_bits_set += x & 1;
567 }
568 return num_bits_set;
569}
Steve Blocka7e24c12009-10-30 11:49:00 +0000570
571} } // namespace v8::internal
572
573#endif // V8_ASSEMBLER_H_