upd: trying to optmize
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
set(PROJECT_NAME ${CMAKE_PROJECT_NAME})
|
set(PROJECT_NAME ${CMAKE_PROJECT_NAME})
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_FLAGS "-O2 -pg")
|
set(CMAKE_CXX_FLAGS "-g")
|
||||||
set(ENV{MAKEFLAGS} "-j16")
|
set(ENV{MAKEFLAGS} "-j16")
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/include)
|
include_directories(${PROJECT_SOURCE_DIR}/include)
|
||||||
link_directories(${PROJECT_SOURCE_DIR}/src)
|
link_directories(${PROJECT_SOURCE_DIR}/src)
|
||||||
|
@ -52,6 +52,7 @@ root= 6
|
|||||||
void RightMoveBy(int);
|
void RightMoveBy(int);
|
||||||
void ProcessHalfBlock();
|
void ProcessHalfBlock();
|
||||||
void RestoreHalfBlock();
|
void RestoreHalfBlock();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int2048();
|
int2048();
|
||||||
int2048(long long);
|
int2048(long long);
|
||||||
@ -86,7 +87,7 @@ root= 6
|
|||||||
int2048 &operator-=(const int2048 &);
|
int2048 &operator-=(const int2048 &);
|
||||||
friend int2048 operator-(int2048, const int2048 &);
|
friend int2048 operator-(int2048, const int2048 &);
|
||||||
|
|
||||||
inline friend void UnsignedMultiply(int2048 &, const int2048 *, bool);
|
inline friend void UnsignedMultiply(int2048 &, const int2048 *, bool, int);
|
||||||
int2048 &Multiply(const int2048 &);
|
int2048 &Multiply(const int2048 &);
|
||||||
friend int2048 Multiply(int2048, const int2048 &);
|
friend int2048 Multiply(int2048, const int2048 &);
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
set(PROJECT_NAME ${CMAKE_PROJECT_NAME})
|
set(PROJECT_NAME ${CMAKE_PROJECT_NAME})
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_FLAGS "-O2 -pg")
|
set(CMAKE_CXX_FLAGS "-g")
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/include)
|
include_directories(${PROJECT_SOURCE_DIR}/include)
|
||||||
add_library(int2048 STATIC int2048.cpp)
|
add_library(int2048 STATIC int2048.cpp)
|
@ -501,10 +501,14 @@ void int2048::NTTTransform(__int128_t *a, int NTT_blocks,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
inline void UnsignedMultiply(int2048 &A, const int2048 *pB,
|
inline void UnsignedMultiply(int2048 &A, const int2048 *pB,
|
||||||
bool inverse = false) {
|
bool inverse = false, int lenght_limit = 0) {
|
||||||
if (&A == pB) throw "UnsignedMultiply: A and B are the same object";
|
if (&A == pB) throw "UnsignedMultiply: A and B are the same object";
|
||||||
int blocks_of_A = ((A.num_length + int2048::kNum - 1) / int2048::kNum);
|
int blocks_of_A = ((A.num_length + int2048::kNum - 1) / int2048::kNum);
|
||||||
int blocks_of_B = ((pB->num_length + int2048::kNum - 1) / int2048::kNum);
|
int blocks_of_B = ((pB->num_length + int2048::kNum - 1) / int2048::kNum);
|
||||||
|
if (inverse) {
|
||||||
|
lenght_limit = std::min(lenght_limit, pB->num_length);
|
||||||
|
blocks_of_B = lenght_limit;
|
||||||
|
}
|
||||||
int max_blocks = blocks_of_A + blocks_of_B;
|
int max_blocks = blocks_of_A + blocks_of_B;
|
||||||
int NTT_blocks = 2;
|
int NTT_blocks = 2;
|
||||||
while (NTT_blocks < (max_blocks << 1)) NTT_blocks <<= 1;
|
while (NTT_blocks < (max_blocks << 1)) NTT_blocks <<= 1;
|
||||||
@ -704,7 +708,7 @@ inline void UnsignedDivide(int2048 &A, const int2048 *pB) {
|
|||||||
}
|
}
|
||||||
assert(tmp_x.num_length % int2048::kNum == 0);
|
assert(tmp_x.num_length % int2048::kNum == 0);
|
||||||
assert(inverse_B.num_length % int2048::kNum == 0);
|
assert(inverse_B.num_length % int2048::kNum == 0);
|
||||||
UnsignedMultiply(tmp_x, &inverse_B, true);
|
UnsignedMultiply(tmp_x, &inverse_B, true, inverse_B.num_length);
|
||||||
for (int i = 0; i < tmp_x_error + inverseB_error; i++)
|
for (int i = 0; i < tmp_x_error + inverseB_error; i++)
|
||||||
tmp_x.RestoreHalfBlock();
|
tmp_x.RestoreHalfBlock();
|
||||||
UnsignedMinus(inverse_two, &tmp_x, true);
|
UnsignedMinus(inverse_two, &tmp_x, true);
|
||||||
|
Reference in New Issue
Block a user