| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 } | 63 } |
| 64 | 64 |
| 65 | 65 |
| 66 static inline double rawbits_to_double(uint64_t bits) { | 66 static inline double rawbits_to_double(uint64_t bits) { |
| 67 double value = 0.0; | 67 double value = 0.0; |
| 68 memcpy(&value, &bits, 8); | 68 memcpy(&value, &bits, 8); |
| 69 return value; | 69 return value; |
| 70 } | 70 } |
| 71 | 71 |
| 72 | 72 |
| 73 // Bits counting. | 73 // Bit counting. |
| 74 int CountLeadingZeros(uint64_t value, int width); | 74 int CountLeadingZeros(uint64_t value, int width); |
| 75 int CountLeadingSignBits(int64_t value, int width); | 75 int CountLeadingSignBits(int64_t value, int width); |
| 76 int CountTrailingZeros(uint64_t value, int width); | 76 int CountTrailingZeros(uint64_t value, int width); |
| 77 int CountSetBits(uint64_t value, int width); | 77 int CountSetBits(uint64_t value, int width); |
| 78 int MaskToBit(uint64_t mask); | 78 int MaskToBit(uint64_t mask); |
| 79 | 79 |
| 80 | 80 |
| 81 // NaN tests. | 81 // NaN tests. |
| 82 inline bool IsSignallingNaN(double num) { | 82 inline bool IsSignallingNaN(double num) { |
| 83 const uint64_t kFP64QuietNaNMask = 0x0008000000000000UL; | |
| 84 uint64_t raw = double_to_rawbits(num); | 83 uint64_t raw = double_to_rawbits(num); |
| 85 if (std::isnan(num) && ((raw & kFP64QuietNaNMask) == 0)) { | 84 if (std::isnan(num) && ((raw & kDQuietNanMask) == 0)) { |
| 86 return true; | 85 return true; |
| 87 } | 86 } |
| 88 return false; | 87 return false; |
| 89 } | 88 } |
| 90 | 89 |
| 91 | 90 |
| 92 inline bool IsSignallingNaN(float num) { | 91 inline bool IsSignallingNaN(float num) { |
| 93 const uint64_t kFP32QuietNaNMask = 0x00400000UL; | |
| 94 uint32_t raw = float_to_rawbits(num); | 92 uint32_t raw = float_to_rawbits(num); |
| 95 if (std::isnan(num) && ((raw & kFP32QuietNaNMask) == 0)) { | 93 if (std::isnan(num) && ((raw & kSQuietNanMask) == 0)) { |
| 96 return true; | 94 return true; |
| 97 } | 95 } |
| 98 return false; | 96 return false; |
| 99 } | 97 } |
| 100 | 98 |
| 101 | 99 |
| 102 template <typename T> | 100 template <typename T> |
| 103 inline bool IsQuietNaN(T num) { | 101 inline bool IsQuietNaN(T num) { |
| 104 return std::isnan(num) && !IsSignallingNaN(num); | 102 return std::isnan(num) && !IsSignallingNaN(num); |
| 105 } | 103 } |
| 106 | 104 |
| 105 |
| 106 // Convert the NaN in 'num' to a quiet NaN. |
| 107 inline double ToQuietNaN(double num) { |
| 108 ASSERT(isnan(num)); |
| 109 return rawbits_to_double(double_to_rawbits(num) | kDQuietNanMask); |
| 110 } |
| 111 |
| 112 |
| 113 inline float ToQuietNaN(float num) { |
| 114 ASSERT(isnan(num)); |
| 115 return rawbits_to_float(float_to_rawbits(num) | kSQuietNanMask); |
| 116 } |
| 117 |
| 118 |
| 119 // Fused multiply-add. |
| 120 inline double FusedMultiplyAdd(double op1, double op2, double a) { |
| 121 return fma(op1, op2, a); |
| 122 } |
| 123 |
| 124 |
| 125 inline float FusedMultiplyAdd(float op1, float op2, float a) { |
| 126 return fmaf(op1, op2, a); |
| 127 } |
| 128 |
| 107 } } // namespace v8::internal | 129 } } // namespace v8::internal |
| 108 | 130 |
| 109 #endif // V8_A64_UTILS_A64_H_ | 131 #endif // V8_A64_UTILS_A64_H_ |
| OLD | NEW |