blob: 68d0bdc43c2c373267f5972e504839654f6f5a20 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright 2006-2009 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#ifndef V8_GLOBALS_H_
29#define V8_GLOBALS_H_
30
31namespace v8 {
32namespace internal {
33
34// Processor architecture detection. For more info on what's defined, see:
35// http://msdn.microsoft.com/en-us/library/b0084kay.aspx
36// http://www.agner.org/optimize/calling_conventions.pdf
37// or with gcc, run: "echo | gcc -E -dM -"
38#if defined(_M_X64) || defined(__x86_64__)
39#define V8_HOST_ARCH_X64 1
40#define V8_HOST_ARCH_64_BIT 1
41#define V8_HOST_CAN_READ_UNALIGNED 1
42#elif defined(_M_IX86) || defined(__i386__)
43#define V8_HOST_ARCH_IA32 1
44#define V8_HOST_ARCH_32_BIT 1
45#define V8_HOST_CAN_READ_UNALIGNED 1
46#elif defined(__ARMEL__)
47#define V8_HOST_ARCH_ARM 1
48#define V8_HOST_ARCH_32_BIT 1
Andrei Popescu31002712010-02-23 13:46:05 +000049#elif defined(_MIPS_ARCH_MIPS32R2)
50#define V8_HOST_ARCH_MIPS 1
51#define V8_HOST_ARCH_32_BIT 1
Steve Blocka7e24c12009-10-30 11:49:00 +000052#else
53#error Your host architecture was not detected as supported by v8
54#endif
55
56#if defined(V8_TARGET_ARCH_X64) || defined(V8_TARGET_ARCH_IA32)
57#define V8_TARGET_CAN_READ_UNALIGNED 1
58#elif V8_TARGET_ARCH_ARM
Andrei Popescu31002712010-02-23 13:46:05 +000059#elif V8_TARGET_ARCH_MIPS
Steve Blocka7e24c12009-10-30 11:49:00 +000060#else
61#error Your target architecture is not supported by v8
62#endif
63
64// Support for alternative bool type. This is only enabled if the code is
65// compiled with USE_MYBOOL defined. This catches some nasty type bugs.
66// For instance, 'bool b = "false";' results in b == true! This is a hidden
67// source of bugs.
68// However, redefining the bool type does have some negative impact on some
69// platforms. It gives rise to compiler warnings (i.e. with
70// MSVC) in the API header files when mixing code that uses the standard
71// bool with code that uses the redefined version.
72// This does not actually belong in the platform code, but needs to be
73// defined here because the platform code uses bool, and platform.h is
74// include very early in the main include file.
75
76#ifdef USE_MYBOOL
77typedef unsigned int __my_bool__;
78#define bool __my_bool__ // use 'indirection' to avoid name clashes
79#endif
80
81typedef uint8_t byte;
82typedef byte* Address;
83
84// Define our own macros for writing 64-bit constants. This is less fragile
85// than defining __STDC_CONSTANT_MACROS before including <stdint.h>, and it
86// works on compilers that don't have it (like MSVC).
87#if V8_HOST_ARCH_64_BIT
88#ifdef _MSC_VER
89#define V8_UINT64_C(x) (x ## UI64)
90#define V8_INT64_C(x) (x ## I64)
91#define V8_PTR_PREFIX "ll"
92#else // _MSC_VER
93#define V8_UINT64_C(x) (x ## UL)
94#define V8_INT64_C(x) (x ## L)
95#define V8_PTR_PREFIX "l"
96#endif // _MSC_VER
97#else // V8_HOST_ARCH_64_BIT
98#define V8_PTR_PREFIX ""
99#endif // V8_HOST_ARCH_64_BIT
100
101#define V8PRIxPTR V8_PTR_PREFIX "x"
102#define V8PRIdPTR V8_PTR_PREFIX "d"
103
104// Fix for Mac OS X defining uintptr_t as "unsigned long":
105#if defined(__APPLE__) && defined(__MACH__)
106#undef V8PRIxPTR
107#define V8PRIxPTR "lx"
108#endif
109
Steve Blockd0582a62009-12-15 09:54:21 +0000110#if defined(__APPLE__) && defined(__MACH__)
111#define USING_MAC_ABI
112#endif
113
Steve Blocka7e24c12009-10-30 11:49:00 +0000114// Code-point values in Unicode 4.0 are 21 bits wide.
115typedef uint16_t uc16;
116typedef int32_t uc32;
117
118// -----------------------------------------------------------------------------
119// Constants
120
121const int KB = 1024;
122const int MB = KB * KB;
123const int GB = KB * KB * KB;
124const int kMaxInt = 0x7FFFFFFF;
125const int kMinInt = -kMaxInt - 1;
126
127const uint32_t kMaxUInt32 = 0xFFFFFFFFu;
128
129const int kCharSize = sizeof(char); // NOLINT
130const int kShortSize = sizeof(short); // NOLINT
131const int kIntSize = sizeof(int); // NOLINT
132const int kDoubleSize = sizeof(double); // NOLINT
133const int kPointerSize = sizeof(void*); // NOLINT
134const int kIntptrSize = sizeof(intptr_t); // NOLINT
135
136#if V8_HOST_ARCH_64_BIT
137const int kPointerSizeLog2 = 3;
138const intptr_t kIntptrSignBit = V8_INT64_C(0x8000000000000000);
139#else
140const int kPointerSizeLog2 = 2;
141const intptr_t kIntptrSignBit = 0x80000000;
142#endif
143
144const int kObjectAlignmentBits = kPointerSizeLog2;
145const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits;
146const intptr_t kObjectAlignmentMask = kObjectAlignment - 1;
147
148// Desired alignment for pointers.
149const intptr_t kPointerAlignment = (1 << kPointerSizeLog2);
150const intptr_t kPointerAlignmentMask = kPointerAlignment - 1;
151
Leon Clarkee46be812010-01-19 14:06:41 +0000152// Desired alignment for maps.
153#if V8_HOST_ARCH_64_BIT
154const intptr_t kMapAlignmentBits = kObjectAlignmentBits;
155#else
156const intptr_t kMapAlignmentBits = kObjectAlignmentBits + 3;
157#endif
158const intptr_t kMapAlignment = (1 << kMapAlignmentBits);
159const intptr_t kMapAlignmentMask = kMapAlignment - 1;
Steve Blocka7e24c12009-10-30 11:49:00 +0000160
161// Tag information for Failure.
162const int kFailureTag = 3;
163const int kFailureTagSize = 2;
164const intptr_t kFailureTagMask = (1 << kFailureTagSize) - 1;
165
166
167const int kBitsPerByte = 8;
168const int kBitsPerByteLog2 = 3;
169const int kBitsPerPointer = kPointerSize * kBitsPerByte;
170const int kBitsPerInt = kIntSize * kBitsPerByte;
171
172
173// Zap-value: The value used for zapping dead objects.
174// Should be a recognizable hex value tagged as a heap object pointer.
175#ifdef V8_HOST_ARCH_64_BIT
176const Address kZapValue =
177 reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeed));
178const Address kHandleZapValue =
179 reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddead));
180const Address kFromSpaceZapValue =
181 reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdad));
182#else
183const Address kZapValue = reinterpret_cast<Address>(0xdeadbeed);
184const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddead);
185const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdad);
186#endif
187
188
Leon Clarkee46be812010-01-19 14:06:41 +0000189// Number of bits to represent the page size for paged spaces. The value of 13
190// gives 8K bytes per page.
191const int kPageSizeBits = 13;
192
193
Steve Blockd0582a62009-12-15 09:54:21 +0000194// Constants relevant to double precision floating point numbers.
195
196// Quiet NaNs have bits 51 to 62 set, possibly the sign bit, and no
197// other bits set.
198const uint64_t kQuietNaNMask = static_cast<uint64_t>(0xfff) << 51;
199// If looking only at the top 32 bits, the QNaN mask is bits 19 to 30.
200const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32);
201
202
Steve Blocka7e24c12009-10-30 11:49:00 +0000203// -----------------------------------------------------------------------------
204// Forward declarations for frequently used classes
205// (sorted alphabetically)
206
207class AccessorInfo;
208class Allocation;
209class Arguments;
210class Assembler;
Leon Clarke4515c472010-02-03 11:58:03 +0000211class AssertNoAllocation;
Steve Blocka7e24c12009-10-30 11:49:00 +0000212class BreakableStatement;
213class Code;
214class CodeGenerator;
215class CodeStub;
216class Context;
217class Debug;
218class Debugger;
219class DebugInfo;
220class Descriptor;
221class DescriptorArray;
222class Expression;
223class ExternalReference;
224class FixedArray;
225class FunctionEntry;
226class FunctionLiteral;
227class FunctionTemplateInfo;
228class NumberDictionary;
229class StringDictionary;
230class FreeStoreAllocationPolicy;
231template <typename T> class Handle;
232class Heap;
233class HeapObject;
234class IC;
235class InterceptorInfo;
236class IterationStatement;
237class Array;
238class JSArray;
239class JSFunction;
240class JSObject;
241class LargeObjectSpace;
242template <typename T, class P = FreeStoreAllocationPolicy> class List;
243class LookupResult;
244class MacroAssembler;
245class Map;
246class MapSpace;
247class MarkCompactCollector;
248class NewSpace;
249class NodeVisitor;
250class Object;
251class OldSpace;
252class Property;
253class Proxy;
254class RegExpNode;
255struct RegExpCompileData;
256class RegExpTree;
257class RegExpCompiler;
258class RegExpVisitor;
259class Scope;
260template<class Allocator = FreeStoreAllocationPolicy> class ScopeInfo;
261class Script;
262class Slot;
263class Smi;
264class Statement;
265class String;
266class Struct;
267class SwitchStatement;
268class AstVisitor;
269class Variable;
270class VariableProxy;
271class RelocInfo;
272class Deserializer;
273class MessageLocation;
274class ObjectGroup;
275class TickSample;
276class VirtualMemory;
277class Mutex;
278class ZoneScopeInfo;
279
280typedef bool (*WeakSlotCallback)(Object** pointer);
281
282// -----------------------------------------------------------------------------
283// Miscellaneous
284
285// NOTE: SpaceIterator depends on AllocationSpace enumeration values being
286// consecutive.
287enum AllocationSpace {
288 NEW_SPACE, // Semispaces collected with copying collector.
289 OLD_POINTER_SPACE, // May contain pointers to new space.
290 OLD_DATA_SPACE, // Must not have pointers to new space.
291 CODE_SPACE, // No pointers to new space, marked executable.
292 MAP_SPACE, // Only and all map objects.
293 CELL_SPACE, // Only and all cell objects.
294 LO_SPACE, // Promoted large objects.
295
296 FIRST_SPACE = NEW_SPACE,
Steve Blockd0582a62009-12-15 09:54:21 +0000297 LAST_SPACE = LO_SPACE,
298 FIRST_PAGED_SPACE = OLD_POINTER_SPACE,
299 LAST_PAGED_SPACE = CELL_SPACE
Steve Blocka7e24c12009-10-30 11:49:00 +0000300};
301const int kSpaceTagSize = 3;
302const int kSpaceTagMask = (1 << kSpaceTagSize) - 1;
303
304
305// A flag that indicates whether objects should be pretenured when
306// allocated (allocated directly into the old generation) or not
307// (allocated in the young generation if the object size and type
308// allows).
309enum PretenureFlag { NOT_TENURED, TENURED };
310
311enum GarbageCollector { SCAVENGER, MARK_COMPACTOR };
312
313enum Executability { NOT_EXECUTABLE, EXECUTABLE };
314
Leon Clarkee46be812010-01-19 14:06:41 +0000315enum VisitMode { VISIT_ALL, VISIT_ALL_IN_SCAVENGE, VISIT_ONLY_STRONG };
Steve Blockd0582a62009-12-15 09:54:21 +0000316
Andrei Popescu31002712010-02-23 13:46:05 +0000317// Flag indicating whether code is built in to the VM (one of the natives
318// files).
319enum NativesFlag { NOT_NATIVES_CODE, NATIVES_CODE };
320
Steve Blocka7e24c12009-10-30 11:49:00 +0000321
322// A CodeDesc describes a buffer holding instructions and relocation
323// information. The instructions start at the beginning of the buffer
324// and grow forward, the relocation information starts at the end of
325// the buffer and grows backward.
326//
327// |<--------------- buffer_size ---------------->|
328// |<-- instr_size -->| |<-- reloc_size -->|
329// +==================+========+==================+
330// | instructions | free | reloc info |
331// +==================+========+==================+
332// ^
333// |
334// buffer
335
336struct CodeDesc {
337 byte* buffer;
338 int buffer_size;
339 int instr_size;
340 int reloc_size;
341 Assembler* origin;
342};
343
344
345// Callback function on object slots, used for iterating heap object slots in
346// HeapObjects, global pointers to heap objects, etc. The callback allows the
347// callback function to change the value of the slot.
348typedef void (*ObjectSlotCallback)(HeapObject** pointer);
349
350
351// Callback function used for iterating objects in heap spaces,
352// for example, scanning heap objects.
353typedef int (*HeapObjectCallback)(HeapObject* obj);
354
355
356// Callback function used for checking constraints when copying/relocating
357// objects. Returns true if an object can be copied/relocated from its
358// old_addr to a new_addr.
359typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr);
360
361
362// Callback function on inline caches, used for iterating over inline caches
363// in compiled code.
364typedef void (*InlineCacheCallback)(Code* code, Address ic);
365
366
367// State for inline cache call sites. Aliased as IC::State.
368enum InlineCacheState {
369 // Has never been executed.
370 UNINITIALIZED,
371 // Has been executed but monomorhic state has been delayed.
372 PREMONOMORPHIC,
373 // Has been executed and only one receiver type has been seen.
374 MONOMORPHIC,
375 // Like MONOMORPHIC but check failed due to prototype.
376 MONOMORPHIC_PROTOTYPE_FAILURE,
377 // Multiple receiver types have been seen.
378 MEGAMORPHIC,
379 // Special states for debug break or step in prepare stubs.
380 DEBUG_BREAK,
381 DEBUG_PREPARE_STEP_IN
382};
383
384
385enum InLoopFlag {
386 NOT_IN_LOOP,
387 IN_LOOP
388};
389
390
Leon Clarkee46be812010-01-19 14:06:41 +0000391enum CallFunctionFlags {
392 NO_CALL_FUNCTION_FLAGS = 0,
393 RECEIVER_MIGHT_BE_VALUE = 1 << 0 // Receiver might not be a JSObject.
394};
395
396
Steve Blocka7e24c12009-10-30 11:49:00 +0000397// Type of properties.
398// Order of properties is significant.
399// Must fit in the BitField PropertyDetails::TypeField.
Andrei Popescu31002712010-02-23 13:46:05 +0000400// A copy of this is in mirror-debugger.js.
Steve Blocka7e24c12009-10-30 11:49:00 +0000401enum PropertyType {
402 NORMAL = 0, // only in slow mode
403 FIELD = 1, // only in fast mode
404 CONSTANT_FUNCTION = 2, // only in fast mode
405 CALLBACKS = 3,
406 INTERCEPTOR = 4, // only in lookup results, not in descriptors.
407 MAP_TRANSITION = 5, // only in fast mode
408 CONSTANT_TRANSITION = 6, // only in fast mode
409 NULL_DESCRIPTOR = 7, // only in fast mode
410 // All properties before MAP_TRANSITION are real.
411 FIRST_PHANTOM_PROPERTY_TYPE = MAP_TRANSITION
412};
413
414
415// Whether to remove map transitions and constant transitions from a
416// DescriptorArray.
417enum TransitionFlag {
418 REMOVE_TRANSITIONS,
419 KEEP_TRANSITIONS
420};
421
422
423// Union used for fast testing of specific double values.
424union DoubleRepresentation {
425 double value;
426 int64_t bits;
427 DoubleRepresentation(double x) { value = x; }
428};
429
430
431// AccessorCallback
432struct AccessorDescriptor {
433 Object* (*getter)(Object* object, void* data);
434 Object* (*setter)(JSObject* object, Object* value, void* data);
435 void* data;
436};
437
438
439// Logging and profiling.
440// A StateTag represents a possible state of the VM. When compiled with
441// ENABLE_LOGGING_AND_PROFILING, the logger maintains a stack of these.
442// Creating a VMState object enters a state by pushing on the stack, and
443// destroying a VMState object leaves a state by popping the current state
444// from the stack.
445
446#define STATE_TAG_LIST(V) \
447 V(JS) \
448 V(GC) \
449 V(COMPILER) \
450 V(OTHER) \
451 V(EXTERNAL)
452
453enum StateTag {
454#define DEF_STATE_TAG(name) name,
455 STATE_TAG_LIST(DEF_STATE_TAG)
456#undef DEF_STATE_TAG
457 // Pseudo-types.
458 state_tag_count
459};
460
461
462// -----------------------------------------------------------------------------
463// Macros
464
465// Testers for test.
466
467#define HAS_SMI_TAG(value) \
468 ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag)
469
470#define HAS_FAILURE_TAG(value) \
471 ((reinterpret_cast<intptr_t>(value) & kFailureTagMask) == kFailureTag)
472
473// OBJECT_SIZE_ALIGN returns the value aligned HeapObject size
474#define OBJECT_SIZE_ALIGN(value) \
475 (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask)
476
477// POINTER_SIZE_ALIGN returns the value aligned as a pointer.
478#define POINTER_SIZE_ALIGN(value) \
479 (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask)
480
Leon Clarkee46be812010-01-19 14:06:41 +0000481// MAP_SIZE_ALIGN returns the value aligned as a map pointer.
482#define MAP_SIZE_ALIGN(value) \
483 (((value) + kMapAlignmentMask) & ~kMapAlignmentMask)
484
Steve Blocka7e24c12009-10-30 11:49:00 +0000485// The expression OFFSET_OF(type, field) computes the byte-offset
486// of the specified field relative to the containing type. This
487// corresponds to 'offsetof' (in stddef.h), except that it doesn't
488// use 0 or NULL, which causes a problem with the compiler warnings
489// we have enabled (which is also why 'offsetof' doesn't seem to work).
490// Here we simply use the non-zero value 4, which seems to work.
491#define OFFSET_OF(type, field) \
492 (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4)
493
494
495// The expression ARRAY_SIZE(a) is a compile-time constant of type
496// size_t which represents the number of elements of the given
497// array. You should only use ARRAY_SIZE on statically allocated
498// arrays.
499#define ARRAY_SIZE(a) \
500 ((sizeof(a) / sizeof(*(a))) / \
501 static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
502
503
504// The USE(x) template is used to silence C++ compiler warnings
505// issued for (yet) unused variables (typically parameters).
506template <typename T>
507static inline void USE(T) { }
508
509
510// FUNCTION_ADDR(f) gets the address of a C function f.
511#define FUNCTION_ADDR(f) \
512 (reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(f)))
513
514
515// FUNCTION_CAST<F>(addr) casts an address into a function
516// of type F. Used to invoke generated code from within C.
517template <typename F>
518F FUNCTION_CAST(Address addr) {
519 return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr));
520}
521
522
523// A macro to disallow the evil copy constructor and operator= functions
524// This should be used in the private: declarations for a class
525#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
526 TypeName(const TypeName&); \
527 void operator=(const TypeName&)
528
529
530// A macro to disallow all the implicit constructors, namely the
531// default constructor, copy constructor and operator= functions.
532//
533// This should be used in the private: declarations for a class
534// that wants to prevent anyone from instantiating it. This is
535// especially useful for classes containing only static methods.
536#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
537 TypeName(); \
538 DISALLOW_COPY_AND_ASSIGN(TypeName)
539
540
541// Support for tracking C++ memory allocation. Insert TRACK_MEMORY("Fisk")
542// inside a C++ class and new and delete will be overloaded so logging is
543// performed.
544// This file (globals.h) is included before log.h, so we use direct calls to
545// the Logger rather than the LOG macro.
546#ifdef DEBUG
547#define TRACK_MEMORY(name) \
548 void* operator new(size_t size) { \
549 void* result = ::operator new(size); \
550 Logger::NewEvent(name, result, size); \
551 return result; \
552 } \
553 void operator delete(void* object) { \
554 Logger::DeleteEvent(name, object); \
555 ::operator delete(object); \
556 }
557#else
558#define TRACK_MEMORY(name)
559#endif
560
561// define used for helping GCC to make better inlining. Don't bother for debug
562// builds. On GCC 3.4.5 using __attribute__((always_inline)) causes compilation
563// errors in debug build.
564#if defined(__GNUC__) && !defined(DEBUG)
565#if (__GNUC__ >= 4)
566#define INLINE(header) inline header __attribute__((always_inline))
567#else
568#define INLINE(header) inline __attribute__((always_inline)) header
569#endif
570#else
571#define INLINE(header) inline header
572#endif
573
574// The type-based aliasing rule allows the compiler to assume that pointers of
575// different types (for some definition of different) never alias each other.
576// Thus the following code does not work:
577//
578// float f = foo();
579// int fbits = *(int*)(&f);
580//
581// The compiler 'knows' that the int pointer can't refer to f since the types
582// don't match, so the compiler may cache f in a register, leaving random data
583// in fbits. Using C++ style casts makes no difference, however a pointer to
584// char data is assumed to alias any other pointer. This is the 'memcpy
585// exception'.
586//
587// Bit_cast uses the memcpy exception to move the bits from a variable of one
588// type of a variable of another type. Of course the end result is likely to
589// be implementation dependent. Most compilers (gcc-4.2 and MSVC 2005)
590// will completely optimize bit_cast away.
591//
592// There is an additional use for bit_cast.
593// Recent gccs will warn when they see casts that may result in breakage due to
594// the type-based aliasing rule. If you have checked that there is no breakage
595// you can use bit_cast to cast one pointer type to another. This confuses gcc
596// enough that it can no longer see that you have cast one pointer type to
597// another thus avoiding the warning.
598template <class Dest, class Source>
599inline Dest bit_cast(const Source& source) {
600 // Compile time assertion: sizeof(Dest) == sizeof(Source)
601 // A compile error here means your Dest and Source have different sizes.
602 typedef char VerifySizesAreEqual[sizeof(Dest) == sizeof(Source) ? 1 : -1];
603
604 Dest dest;
605 memcpy(&dest, &source, sizeof(dest));
606 return dest;
607}
608
609
Steve Blockd0582a62009-12-15 09:54:21 +0000610// Feature flags bit positions. They are mostly based on the CPUID spec.
611// (We assign CPUID itself to one of the currently reserved bits --
612// feel free to change this if needed.)
613enum CpuFeature { SSE3 = 32, // x86
614 SSE2 = 26, // x86
615 CMOV = 15, // x86
616 RDTSC = 4, // x86
617 CPUID = 10, // x86
618 VFP3 = 1, // ARM
Andrei Popescu31002712010-02-23 13:46:05 +0000619 ARMv7 = 2, // ARM
Steve Blockd0582a62009-12-15 09:54:21 +0000620 SAHF = 0}; // x86
621
Steve Blocka7e24c12009-10-30 11:49:00 +0000622} } // namespace v8::internal
623
624#endif // V8_GLOBALS_H_