OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
| 28 #ifndef V8_A64_UTILS_A64_H_ |
| 29 #define V8_A64_UTILS_A64_H_ |
| 30 |
| 31 #include <cmath> |
| 32 #include "v8.h" |
| 33 #include "a64/constants-a64.h" |
| 34 |
| 35 #define REGISTER_CODE_LIST(R) \ |
| 36 R(0) R(1) R(2) R(3) R(4) R(5) R(6) R(7) \ |
| 37 R(8) R(9) R(10) R(11) R(12) R(13) R(14) R(15) \ |
| 38 R(16) R(17) R(18) R(19) R(20) R(21) R(22) R(23) \ |
| 39 R(24) R(25) R(26) R(27) R(28) R(29) R(30) R(31) |
| 40 |
| 41 namespace v8 { |
| 42 namespace internal { |
| 43 |
| 44 // Floating point representation. |
| 45 static inline uint32_t float_to_rawbits(float value) { |
| 46 uint32_t bits = 0; |
| 47 memcpy(&bits, &value, 4); |
| 48 return bits; |
| 49 } |
| 50 |
| 51 |
| 52 static inline uint64_t double_to_rawbits(double value) { |
| 53 uint64_t bits = 0; |
| 54 memcpy(&bits, &value, 8); |
| 55 return bits; |
| 56 } |
| 57 |
| 58 |
| 59 static inline float rawbits_to_float(uint32_t bits) { |
| 60 float value = 0.0; |
| 61 memcpy(&value, &bits, 4); |
| 62 return value; |
| 63 } |
| 64 |
| 65 |
| 66 static inline double rawbits_to_double(uint64_t bits) { |
| 67 double value = 0.0; |
| 68 memcpy(&value, &bits, 8); |
| 69 return value; |
| 70 } |
| 71 |
| 72 |
| 73 // Bits counting. |
| 74 int CountLeadingZeros(uint64_t value, int width); |
| 75 int CountLeadingSignBits(int64_t value, int width); |
| 76 int CountTrailingZeros(uint64_t value, int width); |
| 77 int CountSetBits(uint64_t value, int width); |
| 78 int MaskToBit(uint64_t mask); |
| 79 |
| 80 |
| 81 // NaN tests. |
| 82 inline bool IsSignallingNaN(double num) { |
| 83 const uint64_t kFP64QuietNaNMask = 0x0008000000000000UL; |
| 84 uint64_t raw = double_to_rawbits(num); |
| 85 if (std::isnan(num) && ((raw & kFP64QuietNaNMask) == 0)) { |
| 86 return true; |
| 87 } |
| 88 return false; |
| 89 } |
| 90 |
| 91 |
| 92 inline bool IsSignallingNaN(float num) { |
| 93 const uint64_t kFP32QuietNaNMask = 0x00400000UL; |
| 94 uint32_t raw = float_to_rawbits(num); |
| 95 if (std::isnan(num) && ((raw & kFP32QuietNaNMask) == 0)) { |
| 96 return true; |
| 97 } |
| 98 return false; |
| 99 } |
| 100 |
| 101 |
| 102 template <typename T> |
| 103 inline bool IsQuietNaN(T num) { |
| 104 return std::isnan(num) && !IsSignallingNaN(num); |
| 105 } |
| 106 |
| 107 } } // namespace v8::internal |
| 108 |
| 109 #endif // V8_A64_UTILS_A64_H_ |
OLD | NEW |