codegen.cc 1.17 KB
Newer Older
1
// Copyright 2012 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5
#include "src/codegen.h"
6

7
#include <cmath>
8 9
#include <memory>

10 11
#include "src/flags.h"

12 13
namespace v8 {
namespace internal {
14

15 16 17 18 19 20 21 22 23 24 25
#define UNARY_MATH_FUNCTION(name, generator)                          \
  static UnaryMathFunction fast_##name##_function = nullptr;          \
  double std_##name(double x) { return std::name(x); }                \
  void init_fast_##name##_function() {                                \
    if (FLAG_fast_math) fast_##name##_function = generator();         \
    if (!fast_##name##_function) fast_##name##_function = std_##name; \
  }                                                                   \
  void lazily_initialize_fast_##name() {                              \
    if (!fast_##name##_function) init_fast_##name##_function();       \
  }                                                                   \
  double fast_##name(double x) { return (*fast_##name##_function)(x); }
26

27
UNARY_MATH_FUNCTION(sqrt, CreateSqrtFunction)
28 29 30

#undef UNARY_MATH_FUNCTION

31 32
}  // namespace internal
}  // namespace v8