| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/diy-fp.h" |
| 6 |
| 5 #include <stdint.h> | 7 #include <stdint.h> |
| 6 #include "src/base/logging.h" | |
| 7 #include "src/diy-fp.h" | |
| 8 #include "src/globals.h" | |
| 9 | 8 |
| 10 namespace v8 { | 9 namespace v8 { |
| 11 namespace internal { | 10 namespace internal { |
| 12 | 11 |
| 13 void DiyFp::Multiply(const DiyFp& other) { | 12 void DiyFp::Multiply(const DiyFp& other) { |
| 14 // Simply "emulates" a 128 bit multiplication. | 13 // Simply "emulates" a 128 bit multiplication. |
| 15 // However: the resulting number only contains 64 bits. The least | 14 // However: the resulting number only contains 64 bits. The least |
| 16 // significant 64 bits are only used for rounding the most significant 64 | 15 // significant 64 bits are only used for rounding the most significant 64 |
| 17 // bits. | 16 // bits. |
| 18 const uint64_t kM32 = 0xFFFFFFFFu; | 17 const uint64_t kM32 = 0xFFFFFFFFu; |
| 19 uint64_t a = f_ >> 32; | 18 uint64_t a = f_ >> 32; |
| 20 uint64_t b = f_ & kM32; | 19 uint64_t b = f_ & kM32; |
| 21 uint64_t c = other.f_ >> 32; | 20 uint64_t c = other.f_ >> 32; |
| 22 uint64_t d = other.f_ & kM32; | 21 uint64_t d = other.f_ & kM32; |
| 23 uint64_t ac = a * c; | 22 uint64_t ac = a * c; |
| 24 uint64_t bc = b * c; | 23 uint64_t bc = b * c; |
| 25 uint64_t ad = a * d; | 24 uint64_t ad = a * d; |
| 26 uint64_t bd = b * d; | 25 uint64_t bd = b * d; |
| 27 uint64_t tmp = (bd >> 32) + (ad & kM32) + (bc & kM32); | 26 uint64_t tmp = (bd >> 32) + (ad & kM32) + (bc & kM32); |
| 28 // By adding 1U << 31 to tmp we round the final result. | 27 // By adding 1U << 31 to tmp we round the final result. |
| 29 // Halfway cases will be round up. | 28 // Halfway cases will be round up. |
| 30 tmp += 1U << 31; | 29 tmp += 1U << 31; |
| 31 uint64_t result_f = ac + (ad >> 32) + (bc >> 32) + (tmp >> 32); | 30 uint64_t result_f = ac + (ad >> 32) + (bc >> 32) + (tmp >> 32); |
| 32 e_ += other.e_ + 64; | 31 e_ += other.e_ + 64; |
| 33 f_ = result_f; | 32 f_ = result_f; |
| 34 } | 33 } |
| 35 | 34 |
| 36 } // namespace internal | 35 } // namespace internal |
| 37 } // namespace v8 | 36 } // namespace v8 |
| OLD | NEW |