OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_GLOBALS_H_ | 5 #ifndef VM_GLOBALS_H_ |
6 #define VM_GLOBALS_H_ | 6 #define VM_GLOBALS_H_ |
7 | 7 |
8 // This file contains global definitions for the VM library only. Anything that | 8 // This file contains global definitions for the VM library only. Anything that |
Ivan Posva
2012/01/13 23:51:01
Are there other parts in this file that do not dep
Søren Gjesse
2012/01/16 10:53:00
Moved the template functions implicit_cast, down_c
| |
9 // is more globally useful should be added to 'vm/globals.h'. | 9 // is more globally useful should be added to 'vm/globals.h'. |
10 | 10 |
11 #include "platform/globals.h" | 11 #include "platform/globals.h" |
12 | 12 |
13 #if defined(_WIN32) | 13 #if defined(_WIN32) |
14 // Undef conflicting defines. | 14 // Undef conflicting defines. |
15 #undef PARITY_EVEN | 15 #undef PARITY_EVEN |
16 #undef PARITY_ODD | 16 #undef PARITY_ODD |
17 #undef near | 17 #undef near |
18 #endif | 18 #endif |
19 | 19 |
20 // The following #defines are invalidated. | 20 // The following #defines are invalidated. |
21 #undef OVERFLOW // From math.h conflicts in constants_ia32.h | 21 #undef OVERFLOW // From math.h conflicts in constants_ia32.h |
22 | 22 |
23 namespace dart { | 23 namespace dart { |
24 | 24 |
25 // Processor architecture detection. For more info on what's defined, see: | |
26 // http://msdn.microsoft.com/en-us/library/b0084kay.aspx | |
27 // http://www.agner.org/optimize/calling_conventions.pdf | |
28 // or with gcc, run: "echo | gcc -E -dM -" | |
29 #if defined(_M_X64) || defined(__x86_64__) | |
30 #define HOST_ARCH_X64 1 | |
31 #define ARCH_IS_64_BIT 1 | |
32 #elif defined(_M_IX86) || defined(__i386__) | |
33 #define HOST_ARCH_IA32 1 | |
34 #define ARCH_IS_32_BIT 1 | |
35 #elif defined(__ARMEL__) | |
36 #define HOST_ARCH_ARM 1 | |
37 #define ARCH_IS_32_BIT 1 | |
38 #else | |
39 #error Architecture was not detected as supported by Dart. | |
40 #endif | |
41 | |
42 #if !defined(TARGET_ARCH_ARM) | |
43 #if !defined(TARGET_ARCH_X64) | |
44 #if !defined(TARGET_ARCH_IA32) | |
45 // No target architecture specified pick the one matching the host architecture. | |
46 #if defined(HOST_ARCH_ARM) | |
47 #define TARGET_ARCH_ARM 1 | |
48 #elif defined(HOST_ARCH_X64) | |
49 #define TARGET_ARCH_X64 1 | |
50 #elif defined(HOST_ARCH_IA32) | |
51 #define TARGET_ARCH_IA32 1 | |
52 #else | |
53 #error Automatic target architecture detection failed. | |
54 #endif | |
55 #endif | |
56 #endif | |
57 #endif | |
58 | |
59 // Verify that host and target architectures match, we cannot | |
60 // have a 64 bit Dart VM generating 32 bit code or vice-versa. | |
61 #if defined(TARGET_ARCH_X64) | |
62 #if !defined(ARCH_IS_64_BIT) | |
63 #error Mismatched Host/Target architectures. | |
64 #endif | |
65 #elif defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_ARM) | |
66 #if !defined(ARCH_IS_32_BIT) | |
67 #error Mismatched Host/Target architectures. | |
68 #endif | |
69 #endif | |
70 | |
71 | |
72 // Printf format for intptr_t on Windows. | |
73 #if !defined(PRIxPTR) && defined(TARGET_OS_WINDOWS) | |
74 #if defined(ARCH_IS_32_BIT) | |
75 #define PRIxPTR "x" | |
76 #else | |
77 #define PRIxPTR "llx" | |
78 #endif // defined(ARCH_IS_32_BIT) | |
79 #endif // !defined(PRIxPTR) && defined(TARGET_OS_WINDOWS) | |
80 | |
81 | |
82 // Suffixes for 64-bit integer literals. | |
83 #ifdef _MSC_VER | |
84 #define DART_INT64_C(x) x##I64 | |
85 #define DART_UINT64_C(x) x##UI64 | |
86 #else | |
87 #define DART_INT64_C(x) x##LL | |
88 #define DART_UINT64_C(x) x##ULL | |
89 #endif | |
90 | |
91 | |
92 // The following macro works on both 32 and 64-bit platforms. | |
93 // Usage: instead of writing 0x1234567890123456 | |
94 // write DART_2PART_UINT64_C(0x12345678,90123456); | |
95 #define DART_2PART_UINT64_C(a, b) \ | |
96 (((static_cast<uint64_t>(a) << 32) + 0x##b##u)) | |
97 | |
98 | |
99 // Types for native machine words. Guaranteed to be able to hold pointers and | |
100 // integers. | |
101 typedef intptr_t word; | |
102 typedef uintptr_t uword; | |
103 | |
104 // A type large enough to contain the value of the C++ vtable. This is needed | |
105 // to support the handle operations. | |
106 typedef uword cpp_vtable; | |
107 | |
108 // Byte sizes. | |
109 const int kWordSize = sizeof(word); | |
110 #ifdef ARCH_IS_32_BIT | |
111 const int kWordSizeLog2 = 2; | |
112 #else | |
113 const int kWordSizeLog2 = 3; | |
114 #endif | |
115 | |
116 // Bit sizes. | |
117 const int kBitsPerByte = 8; | |
118 const int kBitsPerByteLog2 = 3; | |
119 const int kBitsPerWord = kWordSize * kBitsPerByte; | |
120 | |
121 // System-wide named constants. | |
122 const int KB = 1024; | |
123 const int MB = KB * KB; | |
124 const int GB = KB * KB * KB; | |
125 const intptr_t kIntptrOne = 1; | |
126 const intptr_t kIntptrMin = (kIntptrOne << (kBitsPerWord - 1)); | |
127 const intptr_t kIntptrMax = ~kIntptrMin; | |
128 | |
129 // Time constants. | |
130 const int kMillisecondsPerSecond = 1000; | |
131 const int kMicrosecondsPerMillisecond = 1000; | |
132 const int kMicrosecondsPerSecond = (kMicrosecondsPerMillisecond * | |
133 kMillisecondsPerSecond); | |
134 const int kNanosecondsPerMicrosecond = 1000; | |
135 const int kNanosecondsPerMillisecond = (kNanosecondsPerMicrosecond * | |
136 kMicrosecondsPerMillisecond); | |
137 const int kNanosecondsPerSecond = (kNanosecondsPerMicrosecond * | |
138 kMicrosecondsPerSecond); | |
139 | |
140 // The expression ARRAY_SIZE(array) is a compile-time constant of type | 25 // The expression ARRAY_SIZE(array) is a compile-time constant of type |
141 // size_t which represents the number of elements of the given | 26 // size_t which represents the number of elements of the given |
142 // array. You should only use ARRAY_SIZE on statically allocated | 27 // array. You should only use ARRAY_SIZE on statically allocated |
143 // arrays. | 28 // arrays. |
144 #define ARRAY_SIZE(array) \ | 29 #define ARRAY_SIZE(array) \ |
145 ((sizeof(array) / sizeof(*(array))) / \ | 30 ((sizeof(array) / sizeof(*(array))) / \ |
146 static_cast<intptr_t>(!(sizeof(array) % sizeof(*(array))))) | 31 static_cast<intptr_t>(!(sizeof(array) % sizeof(*(array))))) |
147 | 32 |
148 | 33 |
149 // The expression OFFSET_OF(type, field) computes the byte-offset of | 34 // The expression OFFSET_OF(type, field) computes the byte-offset of |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 // contants are 16 byte aligned. | 159 // contants are 16 byte aligned. |
275 #if defined(TARGET_OS_WINDOWS) | 160 #if defined(TARGET_OS_WINDOWS) |
276 #define ALIGN16 __declspec(align(16)) | 161 #define ALIGN16 __declspec(align(16)) |
277 #else | 162 #else |
278 #define ALIGN16 __attribute__((aligned(16))) | 163 #define ALIGN16 __attribute__((aligned(16))) |
279 #endif | 164 #endif |
280 | 165 |
281 } // namespace dart | 166 } // namespace dart |
282 | 167 |
283 #endif // VM_GLOBALS_H_ | 168 #endif // VM_GLOBALS_H_ |
OLD | NEW |