build_config.h 8.39 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_BASE_BUILD_CONFIG_H_
#define V8_BASE_BUILD_CONFIG_H_

8
#include "include/v8config.h"
9 10 11 12 13 14 15

// Processor architecture detection.  For more info on what's defined, see:
//   http://msdn.microsoft.com/en-us/library/b0084kay.aspx
//   http://www.agner.org/optimize/calling_conventions.pdf
//   or with gcc, run: "echo | gcc -E -dM -"
#if defined(_M_X64) || defined(__x86_64__)
#define V8_HOST_ARCH_X64 1
16
#if defined(__x86_64__) && __SIZEOF_POINTER__ == 4  // Check for x32.
17 18
#define V8_HOST_ARCH_32_BIT 1
#else
19
#define V8_HOST_ARCH_64_BIT 1
20
#endif
21 22 23
#elif defined(_M_IX86) || defined(__i386__)
#define V8_HOST_ARCH_IA32 1
#define V8_HOST_ARCH_32_BIT 1
24
#elif defined(__AARCH64EL__) || defined(_M_ARM64)
25 26 27 28 29
#define V8_HOST_ARCH_ARM64 1
#define V8_HOST_ARCH_64_BIT 1
#elif defined(__ARMEL__)
#define V8_HOST_ARCH_ARM 1
#define V8_HOST_ARCH_32_BIT 1
30 31 32
#elif defined(__mips64)
#define V8_HOST_ARCH_MIPS64 1
#define V8_HOST_ARCH_64_BIT 1
33 34 35
#elif defined(__MIPSEB__) || defined(__MIPSEL__)
#define V8_HOST_ARCH_MIPS 1
#define V8_HOST_ARCH_32_BIT 1
36 37 38
#elif defined(__loongarch64)
#define V8_HOST_ARCH_LOONG64 1
#define V8_HOST_ARCH_64_BIT 1
39 40 41
#elif defined(__PPC64__) || defined(_ARCH_PPC64)
#define V8_HOST_ARCH_PPC64 1
#define V8_HOST_ARCH_64_BIT 1
42 43 44
#elif defined(__PPC__) || defined(_ARCH_PPC)
#define V8_HOST_ARCH_PPC 1
#define V8_HOST_ARCH_32_BIT 1
45 46 47 48 49 50 51
#elif defined(__s390__) || defined(__s390x__)
#define V8_HOST_ARCH_S390 1
#if defined(__s390x__)
#define V8_HOST_ARCH_64_BIT 1
#else
#define V8_HOST_ARCH_32_BIT 1
#endif
Brice Dobry's avatar
Brice Dobry committed
52 53 54 55 56 57 58
#elif defined(__riscv) || defined(__riscv__)
#if __riscv_xlen == 64
#define V8_HOST_ARCH_RISCV64 1
#define V8_HOST_ARCH_64_BIT 1
#else
#error "Cannot detect Riscv's bitwidth"
#endif
59 60 61 62
#else
#error "Host architecture was not detected as supported by v8"
#endif

Brice Dobry's avatar
Brice Dobry committed
63
#if defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || \
64
    defined(__ARM_ARCH_7__)
Brice Dobry's avatar
Brice Dobry committed
65
#define CAN_USE_ARMV7_INSTRUCTIONS 1
66 67 68
#ifdef __ARM_ARCH_EXT_IDIV__
#define CAN_USE_SUDIV 1
#endif
Brice Dobry's avatar
Brice Dobry committed
69
#ifndef CAN_USE_VFP3_INSTRUCTIONS
70
#define CAN_USE_VFP3_INSTRUCTIONS 1
Brice Dobry's avatar
Brice Dobry committed
71
#endif
72 73
#endif

74
#if defined(__ARM_ARCH_8A__)
75 76
#define CAN_USE_ARMV7_INSTRUCTIONS 1
#define CAN_USE_SUDIV 1
Brice Dobry's avatar
Brice Dobry committed
77
#define CAN_USE_ARMV8_INSTRUCTIONS 1
78 79 80
#ifndef CAN_USE_VFP3_INSTRUCTIONS
#define CAN_USE_VFP3_INSTRUCTIONS 1
#endif
81 82
#endif

83 84 85
// Target architecture detection. This may be set externally. If not, detect
// in the same way as the host architecture, that is, target the native
// environment as presented by the compiler.
Jakob Kummerow's avatar
Jakob Kummerow committed
86 87
#if !V8_TARGET_ARCH_X64 && !V8_TARGET_ARCH_IA32 && !V8_TARGET_ARCH_ARM &&      \
    !V8_TARGET_ARCH_ARM64 && !V8_TARGET_ARCH_MIPS && !V8_TARGET_ARCH_MIPS64 && \
Brice Dobry's avatar
Brice Dobry committed
88
    !V8_TARGET_ARCH_PPC && !V8_TARGET_ARCH_PPC64 && !V8_TARGET_ARCH_S390 &&    \
89
    !V8_TARGET_ARCH_RISCV64 && !V8_TARGET_ARCH_LOONG64
90 91 92 93
#if defined(_M_X64) || defined(__x86_64__)
#define V8_TARGET_ARCH_X64 1
#elif defined(_M_IX86) || defined(__i386__)
#define V8_TARGET_ARCH_IA32 1
94
#elif defined(__AARCH64EL__) || defined(_M_ARM64)
95 96 97
#define V8_TARGET_ARCH_ARM64 1
#elif defined(__ARMEL__)
#define V8_TARGET_ARCH_ARM 1
98 99
#elif defined(__mips64)
#define V8_TARGET_ARCH_MIPS64 1
100 101
#elif defined(__MIPSEB__) || defined(__MIPSEL__)
#define V8_TARGET_ARCH_MIPS 1
102 103
#elif defined(_ARCH_PPC64)
#define V8_TARGET_ARCH_PPC64 1
104 105
#elif defined(_ARCH_PPC)
#define V8_TARGET_ARCH_PPC 1
Brice Dobry's avatar
Brice Dobry committed
106 107 108 109
#elif defined(__riscv) || defined(__riscv__)
#if __riscv_xlen == 64
#define V8_TARGET_ARCH_RISCV64 1
#endif
110 111 112 113 114
#else
#error Target architecture was not detected as supported by v8
#endif
#endif

115 116 117 118 119
// Determine architecture pointer size.
#if V8_TARGET_ARCH_IA32
#define V8_TARGET_ARCH_32_BIT 1
#elif V8_TARGET_ARCH_X64
#if !V8_TARGET_ARCH_32_BIT && !V8_TARGET_ARCH_64_BIT
120
#if defined(__x86_64__) && __SIZEOF_POINTER__ == 4  // Check for x32.
121 122 123 124 125 126 127 128 129 130 131
#define V8_TARGET_ARCH_32_BIT 1
#else
#define V8_TARGET_ARCH_64_BIT 1
#endif
#endif
#elif V8_TARGET_ARCH_ARM
#define V8_TARGET_ARCH_32_BIT 1
#elif V8_TARGET_ARCH_ARM64
#define V8_TARGET_ARCH_64_BIT 1
#elif V8_TARGET_ARCH_MIPS
#define V8_TARGET_ARCH_32_BIT 1
132 133
#elif V8_TARGET_ARCH_MIPS64
#define V8_TARGET_ARCH_64_BIT 1
134 135
#elif V8_TARGET_ARCH_LOONG64
#define V8_TARGET_ARCH_64_BIT 1
136 137
#elif V8_TARGET_ARCH_PPC
#define V8_TARGET_ARCH_32_BIT 1
138 139
#elif V8_TARGET_ARCH_PPC64
#define V8_TARGET_ARCH_64_BIT 1
140 141 142 143 144 145
#elif V8_TARGET_ARCH_S390
#if V8_TARGET_ARCH_S390X
#define V8_TARGET_ARCH_64_BIT 1
#else
#define V8_TARGET_ARCH_32_BIT 1
#endif
Brice Dobry's avatar
Brice Dobry committed
146 147
#elif V8_TARGET_ARCH_RISCV64
#define V8_TARGET_ARCH_64_BIT 1
148 149 150 151
#else
#error Unknown target architecture pointer size
#endif

152 153 154 155
// Check for supported combinations of host and target architectures.
#if V8_TARGET_ARCH_IA32 && !V8_HOST_ARCH_IA32
#error Target architecture ia32 is only supported on ia32 host
#endif
156
#if (V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_64_BIT && \
157 158
     !((V8_HOST_ARCH_X64 || V8_HOST_ARCH_ARM64) && V8_HOST_ARCH_64_BIT))
#error Target architecture x64 is only supported on x64 and arm64 host
159
#endif
160 161 162 163
#if (V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT && \
     !(V8_HOST_ARCH_X64 && V8_HOST_ARCH_32_BIT))
#error Target architecture x32 is only supported on x64 host with x32 support
#endif
164 165 166 167 168 169 170 171 172
#if (V8_TARGET_ARCH_ARM && !(V8_HOST_ARCH_IA32 || V8_HOST_ARCH_ARM))
#error Target architecture arm is only supported on arm and ia32 host
#endif
#if (V8_TARGET_ARCH_ARM64 && !(V8_HOST_ARCH_X64 || V8_HOST_ARCH_ARM64))
#error Target architecture arm64 is only supported on arm64 and x64 host
#endif
#if (V8_TARGET_ARCH_MIPS && !(V8_HOST_ARCH_IA32 || V8_HOST_ARCH_MIPS))
#error Target architecture mips is only supported on mips and ia32 host
#endif
173 174 175
#if (V8_TARGET_ARCH_MIPS64 && !(V8_HOST_ARCH_X64 || V8_HOST_ARCH_MIPS64))
#error Target architecture mips64 is only supported on mips64 and x64 host
#endif
Brice Dobry's avatar
Brice Dobry committed
176 177 178
#if (V8_TARGET_ARCH_RISCV64 && !(V8_HOST_ARCH_X64 || V8_HOST_ARCH_RISCV64))
#error Target architecture riscv64 is only supported on riscv64 and x64 host
#endif
179 180 181
#if (V8_TARGET_ARCH_LOONG64 && !(V8_HOST_ARCH_X64 || V8_HOST_ARCH_LOONG64))
#error Target architecture loong64 is only supported on loong64 and x64 host
#endif
182 183 184 185 186 187 188 189 190 191

// Determine architecture endianness.
#if V8_TARGET_ARCH_IA32
#define V8_TARGET_LITTLE_ENDIAN 1
#elif V8_TARGET_ARCH_X64
#define V8_TARGET_LITTLE_ENDIAN 1
#elif V8_TARGET_ARCH_ARM
#define V8_TARGET_LITTLE_ENDIAN 1
#elif V8_TARGET_ARCH_ARM64
#define V8_TARGET_LITTLE_ENDIAN 1
192 193
#elif V8_TARGET_ARCH_LOONG64
#define V8_TARGET_LITTLE_ENDIAN 1
194 195 196 197 198 199
#elif V8_TARGET_ARCH_MIPS
#if defined(__MIPSEB__)
#define V8_TARGET_BIG_ENDIAN 1
#else
#define V8_TARGET_LITTLE_ENDIAN 1
#endif
200
#elif V8_TARGET_ARCH_MIPS64
201 202 203
#if defined(__MIPSEB__) || defined(V8_TARGET_ARCH_MIPS64_BE)
#define V8_TARGET_BIG_ENDIAN 1
#else
204
#define V8_TARGET_LITTLE_ENDIAN 1
205
#endif
206 207
#elif __BIG_ENDIAN__  // FOR PPCGR on AIX
#define V8_TARGET_BIG_ENDIAN 1
208 209 210 211
#elif V8_TARGET_ARCH_PPC_LE
#define V8_TARGET_LITTLE_ENDIAN 1
#elif V8_TARGET_ARCH_PPC_BE
#define V8_TARGET_BIG_ENDIAN 1
212 213 214 215 216 217
#elif V8_TARGET_ARCH_S390
#if V8_TARGET_ARCH_S390_LE_SIM
#define V8_TARGET_LITTLE_ENDIAN 1
#else
#define V8_TARGET_BIG_ENDIAN 1
#endif
Brice Dobry's avatar
Brice Dobry committed
218 219
#elif V8_TARGET_ARCH_RISCV64
#define V8_TARGET_LITTLE_ENDIAN 1
220 221 222 223
#else
#error Unknown target architecture endianness
#endif

224 225 226 227 228 229 230
// pthread_jit_write_protect is only available on arm64 Mac.
#if defined(V8_OS_MACOSX) && !defined(V8_OS_IOS) && defined(V8_HOST_ARCH_ARM64)
#define V8_HAS_PTHREAD_JIT_WRITE_PROTECT 1
#else
#define V8_HAS_PTHREAD_JIT_WRITE_PROTECT 0
#endif

Jakob Kummerow's avatar
Jakob Kummerow committed
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 237
constexpr int kReturnAddressStackSlotCount =
    V8_TARGET_ARCH_STORES_RETURN_ADDRESS_ON_STACK ? 1 : 0;
238

239 240 241
// Number of bits to represent the page size for paged spaces.
#if defined(V8_TARGET_ARCH_PPC) || defined(V8_TARGET_ARCH_PPC64)
// PPC has large (64KB) physical pages.
242
const int kPageSizeBits = 19;
243 244 245 246 247 248
#elif defined(ENABLE_HUGEPAGE)
// When enabling huge pages, adjust V8 page size to take up exactly one huge
// page. This avoids huge-page-internal fragmentation for unused address ranges.
const int kHugePageBits = 21;
const int kHugePageSize = (1U) << kHugePageBits;
const int kPageSizeBits = kHugePageBits;
249
#else
250 251 252 253
// Arm64 supports up to 64k OS pages on Linux, however 4k pages are more common
// so we keep the V8 page size at 256k. Nonetheless, we need to make sure we
// don't decrease it further in the future due to reserving 3 OS pages for every
// executable V8 page.
254 255
const int kPageSizeBits = 18;
#endif
256

257
#endif  // V8_BASE_BUILD_CONFIG_H_