Commit 21cec63d authored by Jacek Oleksy's avatar Jacek Oleksy Committed by Commit Bot

Initialize float constants using bit_cast

This is a compile fix: the constants were defined
as uint32_t/uint64_t while being declared as float/double.

Changed type in the definition to match declaration and
used bit_cast to make sure the bit pattern is as expected.

Bug: chromium:1151843
Change-Id: I129af71cd9a3dc97f01d2b58f14953345be84382
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2551111Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Reviewed-by: 's avatarDan Elphick <delphick@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71496}
parent 61cf4396
......@@ -3,52 +3,79 @@
// found in the LICENSE file.
#include <cstdint>
#include "include/v8config.h"
#include "src/base/macros.h"
#include "src/codegen/arm64/constants-arm64.h"
namespace v8 {
namespace internal {
// ISA constants. --------------------------------------------------------------
// The following code initializes float/double variables with bit patterns
// without using static initializers (which is surprisingly difficult in
// C++). These variables are used by client code as extern float16,
// extern float and extern double types, which works because (I think) the
// linker ignores the types. This is kept in a separate source file to
// avoid breaking jumbo builds.
// The following code initializes float/double variables with bit patterns.
//
// TODO(mostynb): replace these with std::numeric_limits constexpr's where
// possible, and figure out how to replace *DefaultNaN with something clean,
// then move this code back into instructions-arm64.cc with the same types
// that client code uses.
#if defined(V8_OS_WIN)
extern "C" {
#endif
extern const uint16_t kFP16PositiveInfinity = 0x7C00;
extern const uint16_t kFP16NegativeInfinity = 0xFC00;
V8_EXPORT_PRIVATE extern const uint32_t kFP32PositiveInfinity = 0x7F800000;
V8_EXPORT_PRIVATE extern const uint32_t kFP32NegativeInfinity = 0xFF800000;
V8_EXPORT_PRIVATE extern const uint64_t kFP64PositiveInfinity =
0x7FF0000000000000UL;
V8_EXPORT_PRIVATE extern const uint64_t kFP64NegativeInfinity =
0xFFF0000000000000UL;
namespace integer_constants {
constexpr uint16_t kFP16PositiveInfinity = 0x7C00;
constexpr uint16_t kFP16NegativeInfinity = 0xFC00;
constexpr uint32_t kFP32PositiveInfinity = 0x7F800000;
constexpr uint32_t kFP32NegativeInfinity = 0xFF800000;
constexpr uint64_t kFP64PositiveInfinity = 0x7FF0000000000000UL;
constexpr uint64_t kFP64NegativeInfinity = 0xFFF0000000000000UL;
// This value is a signalling NaN as both a double and as a float (taking the
// least-significant word).
V8_EXPORT_PRIVATE extern const uint64_t kFP64SignallingNaN = 0x7FF000007F800001;
V8_EXPORT_PRIVATE extern const uint32_t kFP32SignallingNaN = 0x7F800001;
constexpr uint64_t kFP64SignallingNaN = 0x7FF000007F800001;
constexpr uint32_t kFP32SignallingNaN = 0x7F800001;
// A similar value, but as a quiet NaN.
V8_EXPORT_PRIVATE extern const uint64_t kFP64QuietNaN = 0x7FF800007FC00001;
V8_EXPORT_PRIVATE extern const uint32_t kFP32QuietNaN = 0x7FC00001;
constexpr uint64_t kFP64QuietNaN = 0x7FF800007FC00001;
constexpr uint32_t kFP32QuietNaN = 0x7FC00001;
// The default NaN values (for FPCR.DN=1).
V8_EXPORT_PRIVATE extern const uint64_t kFP64DefaultNaN = 0x7FF8000000000000UL;
V8_EXPORT_PRIVATE extern const uint32_t kFP32DefaultNaN = 0x7FC00000;
constexpr uint64_t kFP64DefaultNaN = 0x7FF8000000000000UL;
constexpr uint32_t kFP32DefaultNaN = 0x7FC00000;
extern const uint16_t kFP16DefaultNaN = 0x7E00;
} // namespace integer_constants
#if defined(V8_OS_WIN)
extern "C" {
#endif
extern const float16 kFP16PositiveInfinity =
bit_cast<float16>(integer_constants::kFP16PositiveInfinity);
extern const float16 kFP16NegativeInfinity =
bit_cast<float16>(integer_constants::kFP16NegativeInfinity);
V8_EXPORT_PRIVATE extern const float kFP32PositiveInfinity =
bit_cast<float>(integer_constants::kFP32PositiveInfinity);
V8_EXPORT_PRIVATE extern const float kFP32NegativeInfinity =
bit_cast<float>(integer_constants::kFP32NegativeInfinity);
V8_EXPORT_PRIVATE extern const double kFP64PositiveInfinity =
bit_cast<double>(integer_constants::kFP64PositiveInfinity);
V8_EXPORT_PRIVATE extern const double kFP64NegativeInfinity =
bit_cast<double>(integer_constants::kFP64NegativeInfinity);
V8_EXPORT_PRIVATE extern const double kFP64SignallingNaN =
bit_cast<double>(integer_constants::kFP64SignallingNaN);
V8_EXPORT_PRIVATE extern const float kFP32SignallingNaN =
bit_cast<float>(integer_constants::kFP32SignallingNaN);
V8_EXPORT_PRIVATE extern const double kFP64QuietNaN =
bit_cast<double>(integer_constants::kFP64QuietNaN);
V8_EXPORT_PRIVATE extern const float kFP32QuietNaN =
bit_cast<float>(integer_constants::kFP32QuietNaN);
V8_EXPORT_PRIVATE extern const double kFP64DefaultNaN =
bit_cast<double>(integer_constants::kFP64DefaultNaN);
V8_EXPORT_PRIVATE extern const float kFP32DefaultNaN =
bit_cast<float>(integer_constants::kFP32DefaultNaN);
extern const float16 kFP16DefaultNaN =
bit_cast<float16>(integer_constants::kFP16DefaultNaN);
#if defined(V8_OS_WIN)
} // end of extern "C"
......
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