mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-08-21 13:31:51 +02:00
Update to v106r65 release.
byuu says: This synchronizes bsnes/higan with many recent internal nall changes. This will be the last WIP until I am situated in Japan. Apologies for the bugfixes that didn't get applied yet, I ran out of time.
This commit is contained in:
@@ -2,20 +2,27 @@
|
||||
|
||||
namespace nall {
|
||||
|
||||
struct BarrettReduction {
|
||||
BarrettReduction(uint256_t modulo) : modulo(modulo), factor((1_u1024 << 512) / modulo) {}
|
||||
template<uint Bits> struct BarrettReduction {
|
||||
using type = typename ArithmeticNatural<1 * Bits>::type;
|
||||
using pair = typename ArithmeticNatural<2 * Bits>::type;
|
||||
|
||||
//return = value % modulo
|
||||
inline auto operator()(uint512_t value) const -> uint256_t {
|
||||
uint512_t hi, lo;
|
||||
nall::mul(value, factor, hi, lo);
|
||||
uint512_t remainder = value - hi * modulo;
|
||||
explicit BarrettReduction(type modulo) : modulo(modulo), factor(pair(1) + -pair(modulo) / modulo) {}
|
||||
|
||||
//return => value % modulo
|
||||
inline auto operator()(pair value) const -> type {
|
||||
pair hi, lo;
|
||||
mul(value, factor, hi, lo);
|
||||
pair remainder = value - hi * modulo;
|
||||
return remainder < modulo ? remainder : remainder - modulo;
|
||||
}
|
||||
|
||||
private:
|
||||
const uint512_t modulo;
|
||||
const uint512_t factor;
|
||||
const pair modulo;
|
||||
const pair factor;
|
||||
};
|
||||
|
||||
template<typename T, uint Bits> auto operator%(T value, const BarrettReduction<Bits>& modulo) {
|
||||
return modulo(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user