Skip to content

Commit

Permalink
Reorder jump table
Browse files Browse the repository at this point in the history
  • Loading branch information
Admiral-Fish committed Jul 9, 2023
1 parent 9086370 commit 3a5c07f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
8 changes: 4 additions & 4 deletions Source/Core/RNG/LCRNG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ template <class RNG>
static consteval JumpTable computeJumpTable()
{
JumpTable table;
table.add[0] = RNG::getAdd();
table.mult[0] = RNG::getMult();
table.jump[0].add = RNG::getAdd();
table.jump[0].mult = RNG::getMult();

for (int i = 1; i < 32; i++)
{
table.add[i] = table.add[i - 1] * (table.mult[i - 1] + 1);
table.mult[i] = table.mult[i - 1] * table.mult[i - 1];
table.jump[i].add = table.jump[i - 1].add * (table.jump[i - 1].mult + 1);
table.jump[i].mult = table.jump[i - 1].mult * table.jump[i - 1].mult;
}

return table;
Expand Down
9 changes: 6 additions & 3 deletions Source/Core/RNG/LCRNG.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@

struct JumpTable
{
u32 add[32];
u32 mult[32];
struct
{
u32 mult;
u32 add;
} jump[32];
};

extern const JumpTable ARNGTable;
Expand Down Expand Up @@ -165,7 +168,7 @@ class LCRNG
{
if (advances & 1)
{
seed = seed * table->mult[i] + table->add[i];
seed = seed * table->jump[i].mult + table->jump[i].add;
}
}

Expand Down
8 changes: 4 additions & 4 deletions Source/Core/RNG/LCRNG64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ template <class RNG>
static consteval JumpTable64 computeJumpTable64()
{
JumpTable64 table;
table.add[0] = RNG::getAdd();
table.mult[0] = RNG::getMult();
table.jump[0].add = RNG::getAdd();
table.jump[0].mult = RNG::getMult();

for (int i = 1; i < 32; i++)
{
table.add[i] = table.add[i - 1] * (table.mult[i - 1] + 1);
table.mult[i] = table.mult[i - 1] * table.mult[i - 1];
table.jump[i].add = table.jump[i - 1].add * (table.jump[i - 1].mult + 1);
table.jump[i].mult = table.jump[i - 1].mult * table.jump[i - 1].mult;
}

return table;
Expand Down
9 changes: 6 additions & 3 deletions Source/Core/RNG/LCRNG64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@

struct JumpTable64
{
u64 add[32];
u64 mult[32];
struct
{
u64 mult;
u64 add;
} jump[32];
};

extern const JumpTable64 BWRNGTable;
Expand Down Expand Up @@ -154,7 +157,7 @@ class LCRNG64
{
if (advances & 1)
{
seed = seed * table->mult[i] + table->add[i];
seed = seed * table->jump[i].mult + table->jump[i].add;
}
}

Expand Down

0 comments on commit 3a5c07f

Please sign in to comment.