mirror of
https://github.com/aicodix/code.git
synced 2026-04-27 14:30:36 +00:00
experimenting with 3 times faster EEA
https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Simple_algebraic_field_extensions
This commit is contained in:
parent
9774948cd3
commit
9570346a59
1 changed files with 22 additions and 0 deletions
|
|
@ -392,10 +392,32 @@ template <int M, int64_t POLY, typename TYPE>
|
|||
GaloisFieldReference<M, POLY, TYPE> rcp(GaloisFieldReference<M, POLY, TYPE> a)
|
||||
{
|
||||
assert(a.v);
|
||||
#if 1
|
||||
uint32_t r = POLY, newr = a.v;
|
||||
uint32_t t = 0, newt = 1;
|
||||
auto degree = [](uint32_t a) {
|
||||
int d = 0;
|
||||
while (a >>= 1)
|
||||
++d;
|
||||
return d;
|
||||
};
|
||||
while (newr != 1) {
|
||||
int j = degree(newr) - degree(r);
|
||||
if (j < 0) {
|
||||
j = -j;
|
||||
std::swap(newr, r);
|
||||
std::swap(newt, t);
|
||||
}
|
||||
newr ^= r << j;
|
||||
newt ^= t << j;
|
||||
}
|
||||
return GaloisFieldReference<M, POLY, TYPE>(newt);
|
||||
#else
|
||||
GaloisFieldReference<M, POLY, TYPE> t(a *= a);
|
||||
for (int i = 0; i < M - 2; ++i)
|
||||
t *= a *= a;
|
||||
return t;
|
||||
#endif
|
||||
}
|
||||
|
||||
template <int M, int64_t POLY, typename TYPE>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue