From 0070272321d380d363c03024dbcfe29ad4d43a82 Mon Sep 17 00:00:00 2001 From: "jochen@chromium.org" Date: Tue, 6 May 2014 11:14:37 +0000 Subject: [PATCH] Move generated math methods from platform to codegen BUG=none R=mstarzinger@chromium.org LOG=n Review URL: https://codereview.chromium.org/269823006 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21163 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/codegen.cc | 59 +++++++++++++++++++++++++++++++++++++++++++++ src/codegen.h | 12 ++++++++++ src/platform-posix.cc | 30 ----------------------- src/platform-win32.cc | 66 --------------------------------------------------- src/platform.h | 10 -------- src/v8.cc | 6 +++++ 6 files changed, 77 insertions(+), 106 deletions(-) diff --git a/src/codegen.cc b/src/codegen.cc index 42e02a0..9da4ea2 100644 --- a/src/codegen.cc +++ b/src/codegen.cc @@ -17,6 +17,65 @@ namespace v8 { namespace internal { + +#if defined(_WIN64) +typedef double (*ModuloFunction)(double, double); +static ModuloFunction modulo_function = NULL; +// Defined in codegen-x64.cc. +ModuloFunction CreateModuloFunction(); + +void init_modulo_function() { + modulo_function = CreateModuloFunction(); +} + + +double modulo(double x, double y) { + // Note: here we rely on dependent reads being ordered. This is true + // on all architectures we currently support. + return (*modulo_function)(x, y); +} +#elif defined(_WIN32) + +double modulo(double x, double y) { + // Workaround MS fmod bugs. ECMA-262 says: + // dividend is finite and divisor is an infinity => result equals dividend + // dividend is a zero and divisor is nonzero finite => result equals dividend + if (!(std::isfinite(x) && (!std::isfinite(y) && !std::isnan(y))) && + !(x == 0 && (y != 0 && std::isfinite(y)))) { + x = fmod(x, y); + } + return x; +} +#else // POSIX + +double modulo(double x, double y) { + return std::fmod(x, y); +} +#endif // defined(_WIN64) + + +#define UNARY_MATH_FUNCTION(name, generator) \ +static UnaryMathFunction fast_##name##_function = NULL; \ +void init_fast_##name##_function() { \ + fast_##name##_function = generator; \ +} \ +double fast_##name(double x) { \ + return (*fast_##name##_function)(x); \ +} + +UNARY_MATH_FUNCTION(exp, CreateExpFunction()) +UNARY_MATH_FUNCTION(sqrt, CreateSqrtFunction()) + +#undef UNARY_MATH_FUNCTION + + +void lazily_initialize_fast_exp() { + if (fast_exp_function == NULL) { + init_fast_exp_function(); + } +} + + #define __ ACCESS_MASM(masm_) #ifdef DEBUG diff --git a/src/codegen.h b/src/codegen.h index 9b58930..cf84e6a 100644 --- a/src/codegen.h +++ b/src/codegen.h @@ -97,6 +97,18 @@ UnaryMathFunction CreateExpFunction(); UnaryMathFunction CreateSqrtFunction(); +double modulo(double x, double y); + +// Custom implementation of math functions. +double fast_exp(double input); +double fast_sqrt(double input); +#ifdef _WIN64 +void init_modulo_function(); +#endif +void lazily_initialize_fast_exp(); +void init_fast_sqrt_function(); + + class ElementsTransitionGenerator : public AllStatic { public: // If |mode| is set to DONT_TRACK_ALLOCATION_SITE, diff --git a/src/platform-posix.cc b/src/platform-posix.cc index 6375fdd..143bf3c 100644 --- a/src/platform-posix.cc +++ b/src/platform-posix.cc @@ -43,7 +43,6 @@ #include "v8.h" -#include "codegen.h" #include "isolate-inl.h" #include "platform.h" @@ -285,33 +284,6 @@ void OS::DebugBreak() { // ---------------------------------------------------------------------------- // Math functions -double modulo(double x, double y) { - return std::fmod(x, y); -} - - -#define UNARY_MATH_FUNCTION(name, generator) \ -static UnaryMathFunction fast_##name##_function = NULL; \ -void init_fast_##name##_function() { \ - fast_##name##_function = generator; \ -} \ -double fast_##name(double x) { \ - return (*fast_##name##_function)(x); \ -} - -UNARY_MATH_FUNCTION(exp, CreateExpFunction()) -UNARY_MATH_FUNCTION(sqrt, CreateSqrtFunction()) - -#undef UNARY_MATH_FUNCTION - - -void lazily_initialize_fast_exp() { - if (fast_exp_function == NULL) { - init_fast_exp_function(); - } -} - - double OS::nan_value() { // NAN from math.h is defined in C99 and not in POSIX. return NAN; @@ -541,8 +513,6 @@ void OS::PostSetUp() { OS::memcopy_uint8_function = CreateMemCopyUint8Function(&OS::MemCopyUint8Wrapper); #endif - // fast_exp is initialized lazily. - init_fast_sqrt_function(); } diff --git a/src/platform-win32.cc b/src/platform-win32.cc index 11dcdcc..08d03e1 100644 --- a/src/platform-win32.cc +++ b/src/platform-win32.cc @@ -19,7 +19,6 @@ #include "v8.h" -#include "codegen.h" #include "isolate-inl.h" #include "platform.h" @@ -130,68 +129,6 @@ void OS::MemMove(void* dest, const void* src, size_t size) { #endif // V8_TARGET_ARCH_IA32 -#ifdef _WIN64 -typedef double (*ModuloFunction)(double, double); -static ModuloFunction modulo_function = NULL; -// Defined in codegen-x64.cc. -ModuloFunction CreateModuloFunction(); - -void init_modulo_function() { - modulo_function = CreateModuloFunction(); -} - - -double modulo(double x, double y) { - // Note: here we rely on dependent reads being ordered. This is true - // on all architectures we currently support. - return (*modulo_function)(x, y); -} -#else // Win32 - -double modulo(double x, double y) { - // Workaround MS fmod bugs. ECMA-262 says: - // dividend is finite and divisor is an infinity => result equals dividend - // dividend is a zero and divisor is nonzero finite => result equals dividend - if (!(std::isfinite(x) && (!std::isfinite(y) && !std::isnan(y))) && - !(x == 0 && (y != 0 && std::isfinite(y)))) { - x = fmod(x, y); - } - return x; -} - -#endif // _WIN64 - - -#define UNARY_MATH_FUNCTION(name, generator) \ -static UnaryMathFunction fast_##name##_function = NULL; \ -void init_fast_##name##_function() { \ - fast_##name##_function = generator; \ -} \ -double fast_##name(double x) { \ - return (*fast_##name##_function)(x); \ -} - -UNARY_MATH_FUNCTION(exp, CreateExpFunction()) -UNARY_MATH_FUNCTION(sqrt, CreateSqrtFunction()) - -#undef UNARY_MATH_FUNCTION - - -void lazily_initialize_fast_exp() { - if (fast_exp_function == NULL) { - init_fast_exp_function(); - } -} - - -void MathSetup() { -#ifdef _WIN64 - init_modulo_function(); -#endif - // fast_exp is initialized lazily. - init_fast_sqrt_function(); -} - class TimezoneCache { public: @@ -516,9 +453,6 @@ char* Win32Time::LocalTimezone(TimezoneCache* cache) { void OS::PostSetUp() { - // Math functions depend on CPU features therefore they are initialized after - // CPU. - MathSetup(); #if V8_TARGET_ARCH_IA32 OS::MemMoveFunction generated_memmove = CreateMemMoveFunction(); if (generated_memmove != NULL) { diff --git a/src/platform.h b/src/platform.h index 31b7bdf..764bd54 100644 --- a/src/platform.h +++ b/src/platform.h @@ -73,16 +73,6 @@ inline int lrint(double flt) { namespace v8 { namespace internal { -double modulo(double x, double y); - -// Custom implementation of math functions. -double fast_exp(double input); -double fast_sqrt(double input); -// The custom exp implementation needs 16KB of lookup data; initialize it -// on demand. -void lazily_initialize_fast_exp(); - - // ---------------------------------------------------------------------------- // Fast TLS support diff --git a/src/v8.cc b/src/v8.cc index 4050e34..f8156ec 100644 --- a/src/v8.cc +++ b/src/v8.cc @@ -110,6 +110,12 @@ void V8::InitializeOncePerProcessImpl() { bool serializer_enabled = Serializer::enabled(NULL); CpuFeatures::Probe(serializer_enabled); OS::PostSetUp(); + // The custom exp implementation needs 16KB of lookup data; initialize it + // on demand. + init_fast_sqrt_function(); +#ifdef _WIN64 + init_modulo_function(); +#endif ElementsAccessor::InitializeOncePerProcess(); LOperand::SetUpCaches(); SetUpJSCallerSavedCodeData(); -- 2.7.4