• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_BASE_BUILD_CONFIG_H_
6 #define V8_BASE_BUILD_CONFIG_H_
7 
8 #include "include/v8config.h"
9 
10 // Processor architecture detection.  For more info on what's defined, see:
11 //   http://msdn.microsoft.com/en-us/library/b0084kay.aspx
12 //   http://www.agner.org/optimize/calling_conventions.pdf
13 //   or with gcc, run: "echo | gcc -E -dM -"
14 #if defined(_M_X64) || defined(__x86_64__)
15 #define V8_HOST_ARCH_X64 1
16 #if defined(__x86_64__) && __SIZEOF_POINTER__ == 4  // Check for x32.
17 #define V8_HOST_ARCH_32_BIT 1
18 #else
19 #define V8_HOST_ARCH_64_BIT 1
20 #endif
21 #elif defined(_M_IX86) || defined(__i386__)
22 #define V8_HOST_ARCH_IA32 1
23 #define V8_HOST_ARCH_32_BIT 1
24 #elif defined(__AARCH64EL__) || defined(_M_ARM64)
25 #define V8_HOST_ARCH_ARM64 1
26 #define V8_HOST_ARCH_64_BIT 1
27 #elif defined(__ARMEL__)
28 #define V8_HOST_ARCH_ARM 1
29 #define V8_HOST_ARCH_32_BIT 1
30 #elif defined(__mips64)
31 #define V8_HOST_ARCH_MIPS64 1
32 #define V8_HOST_ARCH_64_BIT 1
33 #elif defined(__MIPSEB__) || defined(__MIPSEL__)
34 #define V8_HOST_ARCH_MIPS 1
35 #define V8_HOST_ARCH_32_BIT 1
36 #elif defined(__loongarch64)
37 #define V8_HOST_ARCH_LOONG64 1
38 #define V8_HOST_ARCH_64_BIT 1
39 #elif defined(__PPC64__) || defined(_ARCH_PPC64)
40 #define V8_HOST_ARCH_PPC64 1
41 #define V8_HOST_ARCH_64_BIT 1
42 #elif defined(__PPC__) || defined(_ARCH_PPC)
43 #define V8_HOST_ARCH_PPC 1
44 #define V8_HOST_ARCH_32_BIT 1
45 #elif defined(__s390__) || defined(__s390x__)
46 #define V8_HOST_ARCH_S390 1
47 #if defined(__s390x__)
48 #define V8_HOST_ARCH_64_BIT 1
49 #else
50 #define V8_HOST_ARCH_32_BIT 1
51 #endif
52 #elif defined(__riscv) || defined(__riscv__)
53 #if __riscv_xlen == 64
54 #define V8_HOST_ARCH_RISCV64 1
55 #define V8_HOST_ARCH_64_BIT 1
56 #else
57 #error "Cannot detect Riscv's bitwidth"
58 #endif
59 #else
60 #error "Host architecture was not detected as supported by v8"
61 #endif
62 
63 #if defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || \
64     defined(__ARM_ARCH_7__)
65 #define CAN_USE_ARMV7_INSTRUCTIONS 1
66 #ifdef __ARM_ARCH_EXT_IDIV__
67 #define CAN_USE_SUDIV 1
68 #endif
69 #ifndef CAN_USE_VFP3_INSTRUCTIONS
70 #define CAN_USE_VFP3_INSTRUCTIONS 1
71 #endif
72 #endif
73 
74 #if defined(__ARM_ARCH_8A__)
75 #define CAN_USE_ARMV7_INSTRUCTIONS 1
76 #define CAN_USE_SUDIV 1
77 #define CAN_USE_ARMV8_INSTRUCTIONS 1
78 #ifndef CAN_USE_VFP3_INSTRUCTIONS
79 #define CAN_USE_VFP3_INSTRUCTIONS 1
80 #endif
81 #endif
82 
83 // Target architecture detection. This may be set externally. If not, detect
84 // in the same way as the host architecture, that is, target the native
85 // environment as presented by the compiler.
86 #if !V8_TARGET_ARCH_X64 && !V8_TARGET_ARCH_IA32 && !V8_TARGET_ARCH_ARM &&      \
87     !V8_TARGET_ARCH_ARM64 && !V8_TARGET_ARCH_MIPS && !V8_TARGET_ARCH_MIPS64 && \
88     !V8_TARGET_ARCH_PPC && !V8_TARGET_ARCH_PPC64 && !V8_TARGET_ARCH_S390 &&    \
89     !V8_TARGET_ARCH_RISCV64 && !V8_TARGET_ARCH_LOONG64
90 #if defined(_M_X64) || defined(__x86_64__)
91 #define V8_TARGET_ARCH_X64 1
92 #elif defined(_M_IX86) || defined(__i386__)
93 #define V8_TARGET_ARCH_IA32 1
94 #elif defined(__AARCH64EL__) || defined(_M_ARM64)
95 #define V8_TARGET_ARCH_ARM64 1
96 #elif defined(__ARMEL__)
97 #define V8_TARGET_ARCH_ARM 1
98 #elif defined(__mips64)
99 #define V8_TARGET_ARCH_MIPS64 1
100 #elif defined(__MIPSEB__) || defined(__MIPSEL__)
101 #define V8_TARGET_ARCH_MIPS 1
102 #elif defined(_ARCH_PPC64)
103 #define V8_TARGET_ARCH_PPC64 1
104 #elif defined(_ARCH_PPC)
105 #define V8_TARGET_ARCH_PPC 1
106 #elif defined(__riscv) || defined(__riscv__)
107 #if __riscv_xlen == 64
108 #define V8_TARGET_ARCH_RISCV64 1
109 #endif
110 #else
111 #error Target architecture was not detected as supported by v8
112 #endif
113 #endif
114 
115 // Determine architecture pointer size.
116 #if V8_TARGET_ARCH_IA32
117 #define V8_TARGET_ARCH_32_BIT 1
118 #elif V8_TARGET_ARCH_X64
119 #if !V8_TARGET_ARCH_32_BIT && !V8_TARGET_ARCH_64_BIT
120 #if defined(__x86_64__) && __SIZEOF_POINTER__ == 4  // Check for x32.
121 #define V8_TARGET_ARCH_32_BIT 1
122 #else
123 #define V8_TARGET_ARCH_64_BIT 1
124 #endif
125 #endif
126 #elif V8_TARGET_ARCH_ARM
127 #define V8_TARGET_ARCH_32_BIT 1
128 #elif V8_TARGET_ARCH_ARM64
129 #define V8_TARGET_ARCH_64_BIT 1
130 #elif V8_TARGET_ARCH_MIPS
131 #define V8_TARGET_ARCH_32_BIT 1
132 #elif V8_TARGET_ARCH_MIPS64
133 #define V8_TARGET_ARCH_64_BIT 1
134 #elif V8_TARGET_ARCH_LOONG64
135 #define V8_TARGET_ARCH_64_BIT 1
136 #elif V8_TARGET_ARCH_PPC
137 #define V8_TARGET_ARCH_32_BIT 1
138 #elif V8_TARGET_ARCH_PPC64
139 #define V8_TARGET_ARCH_64_BIT 1
140 #elif V8_TARGET_ARCH_S390
141 #if V8_TARGET_ARCH_S390X
142 #define V8_TARGET_ARCH_64_BIT 1
143 #else
144 #define V8_TARGET_ARCH_32_BIT 1
145 #endif
146 #elif V8_TARGET_ARCH_RISCV64
147 #define V8_TARGET_ARCH_64_BIT 1
148 #else
149 #error Unknown target architecture pointer size
150 #endif
151 
152 // Check for supported combinations of host and target architectures.
153 #if V8_TARGET_ARCH_IA32 && !V8_HOST_ARCH_IA32
154 #error Target architecture ia32 is only supported on ia32 host
155 #endif
156 #if (V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_64_BIT && \
157      !((V8_HOST_ARCH_X64 || V8_HOST_ARCH_ARM64) && V8_HOST_ARCH_64_BIT))
158 #error Target architecture x64 is only supported on x64 and arm64 host
159 #endif
160 #if (V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT && \
161      !(V8_HOST_ARCH_X64 && V8_HOST_ARCH_32_BIT))
162 #error Target architecture x32 is only supported on x64 host with x32 support
163 #endif
164 #if (V8_TARGET_ARCH_ARM && !(V8_HOST_ARCH_IA32 || V8_HOST_ARCH_ARM))
165 #error Target architecture arm is only supported on arm and ia32 host
166 #endif
167 #if (V8_TARGET_ARCH_ARM64 && !(V8_HOST_ARCH_X64 || V8_HOST_ARCH_ARM64))
168 #error Target architecture arm64 is only supported on arm64 and x64 host
169 #endif
170 #if (V8_TARGET_ARCH_MIPS && !(V8_HOST_ARCH_IA32 || V8_HOST_ARCH_MIPS))
171 #error Target architecture mips is only supported on mips and ia32 host
172 #endif
173 #if (V8_TARGET_ARCH_MIPS64 && !(V8_HOST_ARCH_X64 || V8_HOST_ARCH_MIPS64))
174 #error Target architecture mips64 is only supported on mips64 and x64 host
175 #endif
176 #if (V8_TARGET_ARCH_RISCV64 && !(V8_HOST_ARCH_X64 || V8_HOST_ARCH_RISCV64))
177 #error Target architecture riscv64 is only supported on riscv64 and x64 host
178 #endif
179 #if (V8_TARGET_ARCH_LOONG64 && !(V8_HOST_ARCH_X64 || V8_HOST_ARCH_LOONG64))
180 #error Target architecture loong64 is only supported on loong64 and x64 host
181 #endif
182 
183 // Determine architecture endianness.
184 #if V8_TARGET_ARCH_IA32
185 #define V8_TARGET_LITTLE_ENDIAN 1
186 #elif V8_TARGET_ARCH_X64
187 #define V8_TARGET_LITTLE_ENDIAN 1
188 #elif V8_TARGET_ARCH_ARM
189 #define V8_TARGET_LITTLE_ENDIAN 1
190 #elif V8_TARGET_ARCH_ARM64
191 #define V8_TARGET_LITTLE_ENDIAN 1
192 #elif V8_TARGET_ARCH_LOONG64
193 #define V8_TARGET_LITTLE_ENDIAN 1
194 #elif V8_TARGET_ARCH_MIPS
195 #if defined(__MIPSEB__)
196 #define V8_TARGET_BIG_ENDIAN 1
197 #else
198 #define V8_TARGET_LITTLE_ENDIAN 1
199 #endif
200 #elif V8_TARGET_ARCH_MIPS64
201 #if defined(__MIPSEB__) || defined(V8_TARGET_ARCH_MIPS64_BE)
202 #define V8_TARGET_BIG_ENDIAN 1
203 #else
204 #define V8_TARGET_LITTLE_ENDIAN 1
205 #endif
206 #elif __BIG_ENDIAN__  // FOR PPCGR on AIX
207 #define V8_TARGET_BIG_ENDIAN 1
208 #elif V8_TARGET_ARCH_PPC_LE
209 #define V8_TARGET_LITTLE_ENDIAN 1
210 #elif V8_TARGET_ARCH_PPC_BE
211 #define V8_TARGET_BIG_ENDIAN 1
212 #elif V8_TARGET_ARCH_S390
213 #if V8_TARGET_ARCH_S390_LE_SIM
214 #define V8_TARGET_LITTLE_ENDIAN 1
215 #else
216 #define V8_TARGET_BIG_ENDIAN 1
217 #endif
218 #elif V8_TARGET_ARCH_RISCV64
219 #define V8_TARGET_LITTLE_ENDIAN 1
220 #else
221 #error Unknown target architecture endianness
222 #endif
223 
224 // pthread_jit_write_protect is only available on arm64 Mac.
225 #if defined(V8_OS_MACOS) && defined(V8_HOST_ARCH_ARM64)
226 #define V8_HAS_PTHREAD_JIT_WRITE_PROTECT 1
227 #else
228 #define V8_HAS_PTHREAD_JIT_WRITE_PROTECT 0
229 #endif
230 
231 #if defined(V8_TARGET_ARCH_IA32) || defined(V8_TARGET_ARCH_X64)
232 #define V8_TARGET_ARCH_STORES_RETURN_ADDRESS_ON_STACK true
233 #else
234 #define V8_TARGET_ARCH_STORES_RETURN_ADDRESS_ON_STACK false
235 #endif
236 constexpr int kReturnAddressStackSlotCount =
237     V8_TARGET_ARCH_STORES_RETURN_ADDRESS_ON_STACK ? 1 : 0;
238 
239 // Number of bits to represent the page size for paged spaces.
240 #if (defined(V8_HOST_ARCH_PPC) || defined(V8_HOST_ARCH_PPC64)) && !defined(_AIX)
241 // Native PPC linux has large (64KB) physical pages.
242 // Simulator (and Aix) need to use the same value as x64.
243 const int kPageSizeBits = 19;
244 #elif defined(ENABLE_HUGEPAGE)
245 // When enabling huge pages, adjust V8 page size to take up exactly one huge
246 // page. This avoids huge-page-internal fragmentation for unused address ranges.
247 const int kHugePageBits = 21;
248 const int kHugePageSize = (1U) << kHugePageBits;
249 const int kPageSizeBits = kHugePageBits;
250 #else
251 // Arm64 supports up to 64k OS pages on Linux, however 4k pages are more common
252 // so we keep the V8 page size at 256k. Nonetheless, we need to make sure we
253 // don't decrease it further in the future due to reserving 3 OS pages for every
254 // executable V8 page.
255 const int kPageSizeBits = 18;
256 #endif
257 
258 #endif  // V8_BASE_BUILD_CONFIG_H_
259