ReciprocalMulConstants.h (1478B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * vim: set ts=8 sts=2 et sw=2 tw=80: 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef jit_ReciprocalMulConstants_h 8 #define jit_ReciprocalMulConstants_h 9 10 #include "mozilla/MathAlgorithms.h" 11 12 #include <stdint.h> 13 14 #include "vm/Int128.h" 15 16 namespace js::jit { 17 18 struct ReciprocalMulConstants { 19 template <typename Multiplier, typename ShiftAmount> 20 struct DivConstants { 21 Multiplier multiplier; 22 ShiftAmount shiftAmount; 23 }; 24 25 using Div32Constants = DivConstants<int64_t, int32_t>; 26 27 static auto computeSignedDivisionConstants(int32_t d) { 28 return computeDivisionConstants(mozilla::Abs(d), 31); 29 } 30 31 static auto computeUnsignedDivisionConstants(uint32_t d) { 32 return computeDivisionConstants(d, 32); 33 } 34 35 using Div64Constants = DivConstants<Int128, int32_t>; 36 37 static auto computeSignedDivisionConstants(int64_t d) { 38 return computeDivisionConstants(mozilla::Abs(d), 63); 39 } 40 41 static auto computeUnsignedDivisionConstants(uint64_t d) { 42 return computeDivisionConstants(d, 64); 43 } 44 45 private: 46 static Div32Constants computeDivisionConstants(uint32_t d, int maxLog); 47 static Div64Constants computeDivisionConstants(uint64_t d, int maxLog); 48 }; 49 50 } // namespace js::jit 51 52 #endif /* jit_ReciprocalMulConstants_h */