From 515e5b5194bada3a41a9026a02a9cb1773893fdd Mon Sep 17 00:00:00 2001 From: Jonathan Liu Date: Sun, 20 May 2012 00:25:37 +1000 Subject: [PATCH] [V8] Add support for MinGW-w64 This includes several upstream patches to allow V8 to work properly with MinGW-w64. Upstream patches: - https://chromiumcodereview.appspot.com/9959050 - https://chromiumcodereview.appspot.com/10103030 - https://chromiumcodereview.appspot.com/10019012 - https://chromiumcodereview.appspot.com/10108022 - https://chromiumcodereview.appspot.com/10116001 Change-Id: I86876aa67a5bdea1208c7ee33a739eb7c00fd72b Reviewed-by: Peter Varga Reviewed-by: Kent Hansen --- src/3rdparty/v8/src/assembler.cc | 14 +++++++++++ src/3rdparty/v8/src/conversions-inl.h | 4 +-- src/3rdparty/v8/src/platform-win32.cc | 34 +++++++++++++------------- src/3rdparty/v8/src/x64/macro-assembler-x64.cc | 4 +-- src/3rdparty/v8/src/x64/stub-cache-x64.cc | 9 +++++-- src/3rdparty/v8/test/cctest/test-disasm-x64.cc | 1 + 6 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/3rdparty/v8/src/assembler.cc b/src/3rdparty/v8/src/assembler.cc index 40765b3..be25649 100644 --- a/src/3rdparty/v8/src/assembler.cc +++ b/src/3rdparty/v8/src/assembler.cc @@ -1153,6 +1153,20 @@ double power_double_int(double x, int y) { double power_double_double(double x, double y) { +#ifdef __MINGW64_VERSION_MAJOR + // MinGW64 has a custom implementation for pow. This handles certain + // special cases that are different. + if ((x == 0.0 || isinf(x)) && isfinite(y)) { + double f; + if (modf(y, &f) != 0.0) return ((x == 0.0) ^ (y > 0)) ? V8_INFINITY : 0; + } + + if (x == 2.0) { + int y_int = static_cast(y); + if (y == y_int) return ldexp(1.0, y_int); + } +#endif + // The checks for special cases can be dropped in ia32 because it has already // been done in generated code before bailing out here. if (isnan(y) || ((x == 1 || x == -1) && isinf(y))) return OS::nan_value(); diff --git a/src/3rdparty/v8/src/conversions-inl.h b/src/3rdparty/v8/src/conversions-inl.h index b098a1c..77b260f 100644 --- a/src/3rdparty/v8/src/conversions-inl.h +++ b/src/3rdparty/v8/src/conversions-inl.h @@ -228,9 +228,7 @@ double InternalStringToIntDouble(UnicodeCache* unicode_cache, } ASSERT(number != 0); - // The double could be constructed faster from number (mantissa), exponent - // and sign. Assuming it's a rare case more simple code is used. - return static_cast(negative ? -number : number) * pow(2.0, exponent); + return ldexp(static_cast(negative ? -number : number), exponent); } diff --git a/src/3rdparty/v8/src/platform-win32.cc b/src/3rdparty/v8/src/platform-win32.cc index e36fc87..aa16c85 100644 --- a/src/3rdparty/v8/src/platform-win32.cc +++ b/src/3rdparty/v8/src/platform-win32.cc @@ -51,6 +51,22 @@ int strncasecmp(const char* s1, const char* s2, int n) { // the Microsoft Visual Studio C++ CRT. #ifdef __MINGW32__ + +#ifndef __MINGW64_VERSION_MAJOR + +#define _TRUNCATE 0 +#define STRUNCATE 80 + +inline void MemoryBarrier() { + int barrier = 0; + __asm__ __volatile__("xchgl %%eax,%0 ":"=r" (barrier)); +} + +#endif // __MINGW64_VERSION_MAJOR + + +#ifndef MINGW_HAS_SECURE_API + int localtime_s(tm* out_tm, const time_t* time) { tm* posix_local_time_struct = localtime(time); if (posix_local_time_struct == NULL) return 1; @@ -64,13 +80,6 @@ int fopen_s(FILE** pFile, const char* filename, const char* mode) { return *pFile != NULL ? 0 : 1; } - -#ifndef __MINGW64_VERSION_MAJOR -#define _TRUNCATE 0 -#define STRUNCATE 80 -#endif // __MINGW64_VERSION_MAJOR - - int _vsnprintf_s(char* buffer, size_t sizeOfBuffer, size_t count, const char* format, va_list argptr) { ASSERT(count == _TRUNCATE); @@ -104,16 +113,7 @@ int strncpy_s(char* dest, size_t dest_size, const char* source, size_t count) { return 0; } - -#ifndef __MINGW64_VERSION_MAJOR - -inline void MemoryBarrier() { - int barrier = 0; - __asm__ __volatile__("xchgl %%eax,%0 ":"=r" (barrier)); -} - -#endif // __MINGW64_VERSION_MAJOR - +#endif // MINGW_HAS_SECURE_API #endif // __MINGW32__ diff --git a/src/3rdparty/v8/src/x64/macro-assembler-x64.cc b/src/3rdparty/v8/src/x64/macro-assembler-x64.cc index f7db250..12e653c 100644 --- a/src/3rdparty/v8/src/x64/macro-assembler-x64.cc +++ b/src/3rdparty/v8/src/x64/macro-assembler-x64.cc @@ -657,7 +657,7 @@ static int Offset(ExternalReference ref0, ExternalReference ref1) { void MacroAssembler::PrepareCallApiFunction(int arg_stack_space) { -#ifdef _WIN64 +#if defined(_WIN64) && !defined(__MINGW64__) // We need to prepare a slot for result handle on stack and put // a pointer to it into 1st arg register. EnterApiExitFrame(arg_stack_space + 1); @@ -705,7 +705,7 @@ void MacroAssembler::CallApiFunctionAndReturn(Address function_address, RelocInfo::RUNTIME_ENTRY); call(rax); -#ifdef _WIN64 +#if defined(_WIN64) && !defined(__MINGW64__) // rax keeps a pointer to v8::Handle, unpack it. movq(rax, Operand(rax, 0)); #endif diff --git a/src/3rdparty/v8/src/x64/stub-cache-x64.cc b/src/3rdparty/v8/src/x64/stub-cache-x64.cc index f07f6b6..9dfcf7a 100644 --- a/src/3rdparty/v8/src/x64/stub-cache-x64.cc +++ b/src/3rdparty/v8/src/x64/stub-cache-x64.cc @@ -477,7 +477,9 @@ static void GenerateFastApiCall(MacroAssembler* masm, // Prepare arguments. __ lea(rbx, Operand(rsp, 3 * kPointerSize)); -#ifdef _WIN64 +#if defined(__MINGW64__) + Register arguments_arg = rcx; +#elif defined(_WIN64) // Win64 uses first register--rcx--for returned value. Register arguments_arg = rdx; #else @@ -1007,7 +1009,10 @@ void StubCompiler::GenerateLoadCallback(Handle object, // Save a pointer to where we pushed the arguments pointer. // This will be passed as the const AccessorInfo& to the C++ callback. -#ifdef _WIN64 +#if defined(__MINGW64__) + Register accessor_info_arg = rdx; + Register name_arg = rcx; +#elif defined(_WIN64) // Win64 uses first register--rcx--for returned value. Register accessor_info_arg = r8; Register name_arg = rdx; diff --git a/src/3rdparty/v8/test/cctest/test-disasm-x64.cc b/src/3rdparty/v8/test/cctest/test-disasm-x64.cc index da85eb9..c6332e2 100644 --- a/src/3rdparty/v8/test/cctest/test-disasm-x64.cc +++ b/src/3rdparty/v8/test/cctest/test-disasm-x64.cc @@ -264,6 +264,7 @@ TEST(DisasmX64) { ExternalReference after_break_target = ExternalReference(Debug_Address::AfterBreakTarget(), assm.isolate()); + USE(after_break_target); #endif // ENABLE_DEBUGGER_SUPPORT __ jmp(ic, RelocInfo::CODE_TARGET); __ nop(); -- 2.7.4