Commit 2b56660a authored by deanm@chromium.org's avatar deanm@chromium.org

Introduce two separate classes of processor detection:

- TARGET, the architecture we will generate code for.
  This is brought it from the build system.
- HOST, the architecture our C++ compiler is building for.
  This is detected automatically based on compiler defines.

This adds macros for 32 or 64 bit, and cleans up some
include conditionals, etc.

Review URL: http://codereview.chromium.org/99355


git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1864 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent b11b61c4
......@@ -149,13 +149,13 @@ LIBRARY_FLAGS = {
}
},
'arch:ia32': {
'CPPDEFINES': ['V8_ARCH_IA32', 'ILP32']
'CPPDEFINES': ['V8_TARGET_ARCH_IA32']
},
'arch:arm': {
'CPPDEFINES': ['V8_ARCH_ARM', 'ILP32']
'CPPDEFINES': ['V8_TARGET_ARCH_ARM']
},
'arch:x64': {
'CPPDEFINES': ['V8_ARCH_X64', 'LP64']
'CPPDEFINES': ['V8_TARGET_ARCH_X64']
},
'prof:oprofile': {
'CPPDEFINES': ['ENABLE_OPROFILE_AGENT']
......@@ -173,7 +173,7 @@ LIBRARY_FLAGS = {
'CCPDBFLAGS': ['/Zi']
},
'arch:ia32': {
'CPPDEFINES': ['V8_ARCH_IA32']
'CPPDEFINES': ['V8_TARGET_ARCH_IA32']
},
'mode:debug': {
'CCFLAGS': ['/Od', '/Gm'],
......@@ -239,7 +239,7 @@ V8_EXTRA_FLAGS = {
'LIBS': ['winmm', 'ws2_32']
},
'arch:arm': {
'CPPDEFINES': ['V8_ARCH_ARM'],
'CPPDEFINES': ['V8_TARGET_ARCH_ARM'],
# /wd4996 is to silence the warning about sscanf
# used by the arm simulator.
'WARNINGFLAGS': ['/wd4996']
......@@ -348,7 +348,7 @@ CCTEST_EXTRA_FLAGS = {
'CPPDEFINES': ['USING_V8_SHARED']
},
'arch:ia32': {
'CPPDEFINES': ['V8_ARCH_IA32']
'CPPDEFINES': ['V8_TARGET_ARCH_IA32']
}
}
}
......@@ -442,7 +442,7 @@ SAMPLE_FLAGS = {
}
},
'arch:ia32': {
'CPPDEFINES': ['V8_ARCH_IA32']
'CPPDEFINES': ['V8_TARGET_ARCH_IA32']
},
'mode:debug': {
'CCFLAGS': ['/Od'],
......
......@@ -76,16 +76,12 @@
enum OverwriteMode { NO_OVERWRITE, OVERWRITE_LEFT, OVERWRITE_RIGHT };
#ifdef V8_ARCH_ARM
#include "arm/codegen-arm.h"
#endif
#ifdef V8_ARCH_X64
#include "x64/codegen-x64.h"
#endif
#ifdef V8_ARCH_IA32
#if V8_TARGET_ARCH_IA32
#include "ia32/codegen-ia32.h"
#elif V8_TARGET_ARCH_X64
#include "x64/codegen-x64.h"
#elif V8_TARGET_ARCH_ARM
#include "arm/codegen-arm.h"
#endif
namespace v8 { namespace internal {
......
......@@ -32,16 +32,12 @@
#include "api.h"
#include "codegen-inl.h"
#ifdef V8_ARCH_ARM
#include "arm/simulator-arm.h"
#endif
#ifdef V8_ARCH_X64
#include "x64/simulator-x64.h"
#endif
#ifdef V8_ARCH_IA32
#if V8_TARGET_ARCH_IA32
#include "ia32/simulator-ia32.h"
#elif V8_TARGET_ARCH_X64
#include "x64/simulator-x64.h"
#elif V8_TARGET_ARCH_ARM
#include "arm/simulator-arm.h"
#endif
#include "debug.h"
......
......@@ -29,19 +29,15 @@
#define V8_FRAMES_INL_H_
#include "frames.h"
#ifdef V8_ARCH_ARM
#include "arm/frames-arm.h"
#endif
#ifdef V8_ARCH_X64
#include "x64/frames-x64.h"
#endif
#ifdef V8_ARCH_IA32
#if V8_TARGET_ARCH_IA32
#include "ia32/frames-ia32.h"
#elif V8_TARGET_ARCH_X64
#include "x64/frames-x64.h"
#elif V8_TARGET_ARCH_ARM
#include "arm/frames-arm.h"
#endif
namespace v8 { namespace internal {
......
......@@ -30,6 +30,25 @@
namespace v8 { namespace internal {
// 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
#define V8_HOST_ARCH_64_BIT 1
#define V8_HOST_CAN_READ_UNALIGNED 1
#elif defined(_M_IX86) || defined(__i386__)
#define V8_HOST_ARCH_IA32 1
#define V8_HOST_ARCH_32_BIT 1
#define V8_HOST_CAN_READ_UNALIGNED 1
#elif defined(__ARMEL__)
#define V8_HOST_ARCH_ARM 1
#define V8_HOST_ARCH_32_BIT 1
#else
#error Your architecture was not detected as supported by v8
#endif
// Support for alternative bool type. This is only enabled if the code is
// compiled with USE_MYBOOL defined. This catches some nasty type bugs.
// For instance, 'bool b = "false";' results in b == true! This is a hidden
......@@ -53,22 +72,20 @@ typedef byte* Address;
// Define our own macros for writing 64-bit constants. This is less fragile
// than defining __STDC_CONSTANT_MACROS before including <stdint.h>, and it
// works on compilers that don't have it (like MSVC).
#if V8_HOST_ARCH_64_BIT
#ifdef _MSC_VER
#define V8_UINT64_C(x) (x ## UI64)
#define V8_INT64_C(x) (x ## I64)
#else
#define V8_UINT64_C(x) (x ## ULL)
#define V8_INT64_C(x) (x ## LL)
#define V8_UINT64_C(x) (x ## UL)
#define V8_INT64_C(x) (x ## L)
#endif
#endif // V8_HOST_ARCH_64_BIT
// Code-point values in Unicode 4.0 are 21 bits wide.
typedef uint16_t uc16;
typedef int32_t uc32;
#if defined(V8_ARCH_IA32) || defined(V8_ARCH_X64)
#define CAN_READ_UNALIGNED 1
#endif
// -----------------------------------------------------------------------------
// Constants
......@@ -86,7 +103,7 @@ const int kIntSize = sizeof(int); // NOLINT
const int kDoubleSize = sizeof(double); // NOLINT
const int kPointerSize = sizeof(void*); // NOLINT
#ifdef V8_ARCH_X64
#if V8_HOST_ARCH_64_BIT
const int kPointerSizeLog2 = 3;
#else
const int kPointerSizeLog2 = 2;
......@@ -123,7 +140,7 @@ const int kBitsPerInt = kIntSize * kBitsPerByte;
// Zap-value: The value used for zapping dead objects.
// Should be a recognizable hex value tagged as a heap object pointer.
#ifdef V8_ARCH_X64
#ifdef V8_HOST_ARCH_64_BIT
const Address kZapValue =
reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeed));
const Address kHandleZapValue =
......@@ -493,7 +510,7 @@ F FUNCTION_CAST(Address addr) {
// exception'.
//
// Bit_cast uses the memcpy exception to move the bits from a variable of one
// type o a variable of another type. Of course the end result is likely to
// type of a variable of another type. Of course the end result is likely to
// be implementation dependent. Most compilers (gcc-4.2 and MSVC 2005)
// will completely optimize bit_cast away.
//
......
......@@ -42,18 +42,14 @@
#include "regexp-macro-assembler-irregexp.h"
#include "regexp-stack.h"
#ifdef V8_ARCH_ARM
#include "arm/regexp-macro-assembler-arm.h"
#endif
#ifdef V8_ARCH_X64
#include "x64/macro-assembler-x64.h"
#include "x64/regexp-macro-assembler-x64.h"
#endif
#ifdef V8_ARCH_IA32
#ifdef V8_TARGET_ARCH_IA32
#include "ia32/macro-assembler-ia32.h"
#include "ia32/regexp-macro-assembler-ia32.h"
#elif V8_TARGET_ARCH_X64
#include "x64/macro-assembler-x64.h"
#include "x64/regexp-macro-assembler-x64.h"
#elif V8_TARGET_ARCH_ARM
#include "arm/regexp-macro-assembler-arm.h"
#endif
#include "interpreter-irregexp.h"
......@@ -431,13 +427,7 @@ Handle<Object> RegExpImpl::IrregexpExec(Handle<JSRegExp> jsregexp,
Handle<String> original_subject = subject;
Handle<FixedArray> regexp(FixedArray::cast(jsregexp->data()));
if (UseNativeRegexp()) {
#ifdef V8_ARCH_ARM
UNREACHABLE();
#endif
#ifdef V8_ARCH_X64
UNIMPLEMENTED();
#endif
#ifdef V8_ARCH_IA32
#if V8_TARGET_ARCH_IA32
RegExpMacroAssemblerIA32::Result res;
do {
bool is_ascii = subject->IsAsciiRepresentation();
......@@ -461,6 +451,8 @@ Handle<Object> RegExpImpl::IrregexpExec(Handle<JSRegExp> jsregexp,
|| res == RegExpMacroAssemblerIA32::FAILURE);
rc = (res == RegExpMacroAssemblerIA32::SUCCESS);
#else
UNREACHABLE();
#endif
} else {
bool is_ascii = subject->IsAsciiRepresentation();
......@@ -2521,7 +2513,7 @@ void LoopChoiceNode::Emit(RegExpCompiler* compiler, Trace* trace) {
int ChoiceNode::CalculatePreloadCharacters(RegExpCompiler* compiler) {
int preload_characters = EatsAtLeast(4, 0);
#ifdef CAN_READ_UNALIGNED
#ifdef V8_HOST_CAN_READ_UNALIGNED
bool ascii = compiler->ascii();
if (ascii) {
if (preload_characters > 4) preload_characters = 4;
......@@ -4445,13 +4437,13 @@ RegExpEngine::CompilationResult RegExpEngine::Compile(RegExpCompileData* data,
NodeInfo info = *node->info();
if (RegExpImpl::UseNativeRegexp()) {
#ifdef V8_ARCH_ARM
#ifdef V8_TARGET_ARCH_ARM
UNREACHABLE();
#endif
#ifdef V8_ARCH_X64
#ifdef V8_TARGET_ARCH_X64
UNREACHABLE();
#endif
#ifdef V8_ARCH_IA32
#ifdef V8_TARGET_ARCH_IA32
RegExpMacroAssemblerIA32::Mode mode;
if (is_ascii) {
mode = RegExpMacroAssemblerIA32::ASCII;
......
......@@ -37,14 +37,10 @@ class RegExpMacroAssembler;
class RegExpImpl {
public:
static inline bool UseNativeRegexp() {
#ifdef V8_ARCH_ARM
return false;
#endif
#ifdef V8_ARCH_X64
return false;
#endif
#ifdef V8_ARCH_IA32
#ifdef V8_TARGET_ARCH_IA32
return FLAG_regexp_native;
#else
return false;
#endif
}
// Creates a regular expression literal in the old space.
......
......@@ -28,29 +28,25 @@
#ifndef V8_MACRO_ASSEMBLER_H_
#define V8_MACRO_ASSEMBLER_H_
#ifdef V8_ARCH_ARM
#include "arm/constants-arm.h"
#if V8_TARGET_ARCH_IA32
#include "assembler.h"
#include "arm/assembler-arm.h"
#include "arm/assembler-arm-inl.h"
#include "ia32/assembler-ia32.h"
#include "ia32/assembler-ia32-inl.h"
#include "code.h" // must be after assembler_*.h
#include "arm/macro-assembler-arm.h"
#endif
#ifdef V8_ARCH_X64
#include "ia32/macro-assembler-ia32.h"
#elif V8_TARGET_ARCH_X64
#include "assembler.h"
#include "x64/assembler-x64.h"
#include "x64/assembler-x64-inl.h"
#include "code.h" // must be after assembler_*.h
#include "x64/macro-assembler-x64.h"
#endif
#ifdef V8_ARCH_IA32
#elif V8_TARGET_ARCH_ARM
#include "arm/constants-arm.h"
#include "assembler.h"
#include "ia32/assembler-ia32.h"
#include "ia32/assembler-ia32-inl.h"
#include "arm/assembler-arm.h"
#include "arm/assembler-arm-inl.h"
#include "code.h" // must be after assembler_*.h
#include "ia32/macro-assembler-ia32.h"
#include "arm/macro-assembler-arm.h"
#endif
#endif // V8_MACRO_ASSEMBLER_H_
......@@ -4089,7 +4089,7 @@ static inline bool CompareRawStringContents(Vector<Char> a, Vector<Char> b) {
const Char* pa = a.start();
const Char* pb = b.start();
int i = 0;
#ifndef CAN_READ_UNALIGNED
#ifndef V8_HOST_CAN_READ_UNALIGNED
// If this architecture isn't comfortable reading unaligned ints
// then we have to check that the strings are aligned before
// comparing them blockwise.
......@@ -4108,7 +4108,7 @@ static inline bool CompareRawStringContents(Vector<Char> a, Vector<Char> b) {
return false;
}
}
#ifndef CAN_READ_UNALIGNED
#ifndef V8_HOST_CAN_READ_UNALIGNED
}
#endif
// Compare the remaining characters that didn't fit into a block.
......
......@@ -527,7 +527,7 @@ class StringBuilder {
template <typename sourcechar, typename sinkchar>
static inline void CopyChars(sinkchar* dest, const sourcechar* src, int chars) {
sinkchar* limit = dest + chars;
#ifdef CAN_READ_UNALIGNED
#ifdef V8_HOST_CAN_READ_UNALIGNED
if (sizeof(*dest) == sizeof(*src)) {
// Number of characters in a uint32_t.
static const int kStepSize = sizeof(uint32_t) / sizeof(*dest); // NOLINT
......
......@@ -202,16 +202,12 @@ class FrameElement BASE_EMBEDDED {
} } // namespace v8::internal
#ifdef V8_ARCH_ARM
#include "arm/virtual-frame-arm.h"
#endif
#ifdef V8_ARCH_X64
#include "x64/virtual-frame-x64.h"
#endif
#ifdef V8_ARCH_IA32
#if V8_TARGET_ARCH_IA32
#include "ia32/virtual-frame-ia32.h"
#elif V8_TARGET_ARCH_X64
#include "x64/virtual-frame-x64.h"
#elif V8_TARGET_ARCH_ARM
#include "arm/virtual-frame-arm.h"
#endif
#endif // V8_VIRTUAL_FRAME_H_
......@@ -38,13 +38,13 @@
#include "jsregexp-inl.h"
#include "regexp-macro-assembler.h"
#include "regexp-macro-assembler-irregexp.h"
#ifdef V8_ARCH_ARM
#ifdef V8_TARGET_ARCH_ARM
#include "arm/regexp-macro-assembler-arm.h"
#endif
#ifdef V8_ARCH_X64
#ifdef V8_TARGET_ARCH_X64
// No X64-implementation yet.
#endif
#ifdef V8_ARCH_IA32
#ifdef V8_TARGET_ARCH_IA32
#include "ia32/macro-assembler-ia32.h"
#include "ia32/regexp-macro-assembler-ia32.h"
#endif
......@@ -661,7 +661,7 @@ TEST(MacroAssembler) {
}
#ifdef V8_ARCH_IA32 // IA32 only tests.
#ifdef V8_TARGET_ARCH_IA32 // IA32 only tests.
class ContextInitializer {
public:
......
......@@ -403,7 +403,7 @@
'target_name': 'v8_base',
'type': '<(library)',
'defines': [
'V8_ARCH_IA32'
'V8_TARGET_ARCH_IA32'
],
'include_dirs+': [
'../../src',
......@@ -461,7 +461,7 @@
'target_name': 'v8_nosnapshot',
'type': '<(library)',
'defines': [
'V8_ARCH_IA32'
'V8_TARGET_ARCH_IA32'
],
'dependencies': [
'js2c',
......@@ -493,7 +493,7 @@
'target_name': 'v8',
'type': '<(library)',
'defines': [
'V8_ARCH_IA32'
'V8_TARGET_ARCH_IA32'
],
'dependencies': [
'js2c',
......@@ -533,7 +533,7 @@
'target_name': 'v8_shell',
'type': 'executable',
'defines': [
'V8_ARCH_IA32'
'V8_TARGET_ARCH_IA32'
],
'dependencies': [
'v8',
......@@ -563,7 +563,7 @@
'v8',
],
'defines': [
'V8_ARCH_IA32'
'V8_TARGET_ARCH_IA32'
],
'include_dirs': [
'../../src',
......@@ -602,7 +602,7 @@
'js2c',
],
'defines': [
'V8_ARCH_ARM',
'V8_TARGET_ARCH_ARM',
],
'include_dirs+': [
'../../src',
......@@ -660,7 +660,7 @@
'v8_arm',
],
'defines': [
'V8_ARCH_ARM',
'V8_TARGET_ARCH_ARM',
],
'sources': [
'../../samples/shell.cc',
......@@ -680,7 +680,7 @@
'v8_arm',
],
'defines': [
'V8_ARCH_ARM',
'V8_TARGET_ARCH_ARM',
],
'include_dirs': [
'../../src',
......
......@@ -1438,7 +1438,7 @@
buildSettings = {
GCC_PREPROCESSOR_DEFINITIONS = (
"$(GCC_PREPROCESSOR_DEFINITIONS)",
V8_ARCH_IA32,
V8_TARGET_ARCH_IA32,
DEBUG,
);
HEADER_SEARCH_PATHS = ../src;
......@@ -1451,7 +1451,7 @@
buildSettings = {
GCC_PREPROCESSOR_DEFINITIONS = (
"$(GCC_PREPROCESSOR_DEFINITIONS)",
V8_ARCH_IA32,
V8_TARGET_ARCH_IA32,
NDEBUG,
);
HEADER_SEARCH_PATHS = ../src;
......@@ -1466,7 +1466,7 @@
GCC_PREPROCESSOR_DEFINITIONS = (
"$(GCC_PREPROCESSOR_DEFINITIONS)",
ENABLE_DISASSEMBLER,
V8_ARCH_IA32,
V8_TARGET_ARCH_IA32,
ENABLE_LOGGING_AND_PROFILING,
);
HEADER_SEARCH_PATHS = ../src;
......@@ -1481,7 +1481,7 @@
DEPLOYMENT_POSTPROCESSING = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(GCC_PREPROCESSOR_DEFINITIONS)",
V8_ARCH_IA32,
V8_TARGET_ARCH_IA32,
NDEBUG,
);
HEADER_SEARCH_PATHS = ../src;
......@@ -1512,7 +1512,7 @@
DEPLOYMENT_POSTPROCESSING = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(GCC_PREPROCESSOR_DEFINITIONS)",
V8_ARCH_ARM,
V8_TARGET_ARCH_ARM,
ENABLE_DISASSEMBLER,
ENABLE_LOGGING_AND_PROFILING,
);
......@@ -1528,7 +1528,7 @@
DEPLOYMENT_POSTPROCESSING = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(GCC_PREPROCESSOR_DEFINITIONS)",
V8_ARCH_ARM,
V8_TARGET_ARCH_ARM,
);
HEADER_SEARCH_PATHS = ../src;
PRODUCT_NAME = "v8-arm";
......
......@@ -6,7 +6,7 @@
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="V8_ARCH_ARM"
PreprocessorDefinitions="V8_TARGET_ARCH_ARM"
DisableSpecificWarnings="4996"
/>
</VisualStudioPropertySheet>
......@@ -6,6 +6,6 @@
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="V8_ARCH_IA32"
PreprocessorDefinitions="V8_TARGET_ARCH_IA32"
/>
</VisualStudioPropertySheet>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment