Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / v8 / src / arm64 / utils-arm64.h
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_ARM64_UTILS_ARM64_H_
6 #define V8_ARM64_UTILS_ARM64_H_
7
8 #include <cmath>
9 #include "src/v8.h"
10
11 #include "src/arm64/constants-arm64.h"
12
13 #define REGISTER_CODE_LIST(R)                                                  \
14 R(0)  R(1)  R(2)  R(3)  R(4)  R(5)  R(6)  R(7)                                 \
15 R(8)  R(9)  R(10) R(11) R(12) R(13) R(14) R(15)                                \
16 R(16) R(17) R(18) R(19) R(20) R(21) R(22) R(23)                                \
17 R(24) R(25) R(26) R(27) R(28) R(29) R(30) R(31)
18
19 namespace v8 {
20 namespace internal {
21
22 // These are global assumptions in v8.
23 STATIC_ASSERT((static_cast<int32_t>(-1) >> 1) == -1);
24 STATIC_ASSERT((static_cast<uint32_t>(-1) >> 1) == 0x7FFFFFFF);
25
26 // Floating point representation.
27 static inline uint32_t float_to_rawbits(float value) {
28   uint32_t bits = 0;
29   memcpy(&bits, &value, 4);
30   return bits;
31 }
32
33
34 static inline uint64_t double_to_rawbits(double value) {
35   uint64_t bits = 0;
36   memcpy(&bits, &value, 8);
37   return bits;
38 }
39
40
41 static inline float rawbits_to_float(uint32_t bits) {
42   float value = 0.0;
43   memcpy(&value, &bits, 4);
44   return value;
45 }
46
47
48 static inline double rawbits_to_double(uint64_t bits) {
49   double value = 0.0;
50   memcpy(&value, &bits, 8);
51   return value;
52 }
53
54
55 // Bit counting.
56 int CountLeadingZeros(uint64_t value, int width);
57 int CountLeadingSignBits(int64_t value, int width);
58 int CountTrailingZeros(uint64_t value, int width);
59 int CountSetBits(uint64_t value, int width);
60 uint64_t LargestPowerOf2Divisor(uint64_t value);
61 int MaskToBit(uint64_t mask);
62
63
64 // NaN tests.
65 inline bool IsSignallingNaN(double num) {
66   uint64_t raw = double_to_rawbits(num);
67   if (std::isnan(num) && ((raw & kDQuietNanMask) == 0)) {
68     return true;
69   }
70   return false;
71 }
72
73
74 inline bool IsSignallingNaN(float num) {
75   uint32_t raw = float_to_rawbits(num);
76   if (std::isnan(num) && ((raw & kSQuietNanMask) == 0)) {
77     return true;
78   }
79   return false;
80 }
81
82
83 template <typename T>
84 inline bool IsQuietNaN(T num) {
85   return std::isnan(num) && !IsSignallingNaN(num);
86 }
87
88
89 // Convert the NaN in 'num' to a quiet NaN.
90 inline double ToQuietNaN(double num) {
91   DCHECK(std::isnan(num));
92   return rawbits_to_double(double_to_rawbits(num) | kDQuietNanMask);
93 }
94
95
96 inline float ToQuietNaN(float num) {
97   DCHECK(std::isnan(num));
98   return rawbits_to_float(float_to_rawbits(num) | kSQuietNanMask);
99 }
100
101
102 // Fused multiply-add.
103 inline double FusedMultiplyAdd(double op1, double op2, double a) {
104   return fma(op1, op2, a);
105 }
106
107
108 inline float FusedMultiplyAdd(float op1, float op2, float a) {
109   return fmaf(op1, op2, a);
110 }
111
112 } }  // namespace v8::internal
113
114 #endif  // V8_ARM64_UTILS_ARM64_H_