Skip to content

Commit 08d26db

Browse files
committed
update git_tag for util dependency, slightly improve MontgomeryForm convertOut
1 parent de32b44 commit 08d26db

File tree

7 files changed

+24
-16
lines changed

7 files changed

+24
-16
lines changed

modular_arithmetic/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ include(FetchContent)
7575
FetchContent_Declare(
7676
hurchalla_util
7777
GIT_REPOSITORY https://github.com/hurchalla/util.git
78-
GIT_TAG 0e5a34dbd1d7b364f54934f8245214386673c509
78+
GIT_TAG b1e9990b4293bfaaa040731fc9ec97edfeeb85cb
7979
)
8080
FetchContent_MakeAvailable(hurchalla_util)
8181

montgomery_arithmetic/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ include(FetchContent)
7878
FetchContent_Declare(
7979
hurchalla_util
8080
GIT_REPOSITORY https://github.com/hurchalla/util.git
81-
GIT_TAG 0e5a34dbd1d7b364f54934f8245214386673c509
81+
GIT_TAG b1e9990b4293bfaaa040731fc9ec97edfeeb85cb
8282
)
8383
FetchContent_MakeAvailable(hurchalla_util)
8484

montgomery_arithmetic/include/hurchalla/montgomery_arithmetic/detail/MontyCommonBase.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,15 @@ class MontyCommonBase {
9797
// get a Natural number (i.e. number >= 0) congruent to x (mod n)
9898
T u_lo = static_cast<const D*>(this)->getNaturalEquivalence(x);
9999
namespace hc = ::hurchalla;
100-
T result = hc::REDC_standard(u_hi, u_lo, n_, inv_n_, LowlatencyTag());
100+
bool isNegative;
101+
T result = hc::REDC_incomplete(isNegative, u_hi, u_lo, n_, inv_n_);
102+
HPBC_CLOCKWORK_ASSERT2(result == 0 ?
103+
isNegative == false : isNegative == true);
104+
// We would expect that result == 0 is usually very rare, so going by
105+
// the assert above, the next 'if' should be well predicted.
106+
if (isNegative)
107+
result = static_cast<T>(result + n_);
108+
HPBC_CLOCKWORK_ASSERT2(result==hc::REDC_standard(u_hi,u_lo,n_,inv_n_));
101109

102110
HPBC_CLOCKWORK_POSTCONDITION2(result < n_);
103111
return result;

montgomery_arithmetic/include/hurchalla/montgomery_arithmetic/detail/experimental/montgomery_two_pow/experimental_montgomery_two_pow.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ if HURCHALLA_CPP17_CONSTEXPR (CODE_SECTION == 0) {
114114
RU num = static_cast<RU>(static_cast<RU>(1) << index);
115115
V result = MFE::convertInExtended(mf, num);
116116
while (shift >= P2) {
117-
if (USE_SLIDING_WINDOW_OPTIMIZATION) {
117+
if HURCHALLA_CPP17_CONSTEXPR (USE_SLIDING_WINDOW_OPTIMIZATION) {
118118
while (shift > P2 && (static_cast<size_t>(n>>(shift-1)) & 1u) == 0) {
119119
result = mf.square(result);
120120
--shift;
@@ -235,7 +235,7 @@ goto break_0_1;
235235
HPBC_CLOCKWORK_ASSERT2(index <= MASK);
236236
V result = MFE::twoPowLimited(mf, index);
237237
while (shift >= P2) {
238-
if (USE_SLIDING_WINDOW_OPTIMIZATION) {
238+
if HURCHALLA_CPP17_CONSTEXPR (USE_SLIDING_WINDOW_OPTIMIZATION) {
239239
while (shift > P2 && (static_cast<size_t>(n>>(shift-1)) & 1u) == 0) {
240240
result = mf.square(result);
241241
--shift;

montgomery_arithmetic/include/hurchalla/montgomery_arithmetic/detail/experimental/montgomery_two_pow/testbench.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,9 @@ cppcompiler=$1
462462
#optimization_level=O3
463463
optimization_level=$2
464464

465-
#define_mont_type=-DPREDEF_MONT_TYPE=MontgomeryQuarter<U>
466-
define_mont_type=-DPREDEF_MONT_TYPE=$3
467-
define_uint_type=-DPREDEF_UINT_TYPE=$4
465+
#define_mont_type=-DDEF_MONT_TYPE=MontgomeryQuarter<U>
466+
define_mont_type=-DDEF_MONT_TYPE=$3
467+
define_uint_type=-DDEF_UINT_TYPE=$4
468468

469469
define_use_asm=$8
470470

montgomery_arithmetic/include/hurchalla/montgomery_arithmetic/detail/experimental/montgomery_two_pow/testbench_montgomery_two_pow.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -879,15 +879,15 @@ using namespace hurchalla;
879879

880880

881881

882-
#ifndef PREDEF_UINT_TYPE
883-
# error "PREDEF_UINT_TYPE was not defined"
882+
#ifndef DEF_UINT_TYPE
883+
# error "DEF_UINT_TYPE was not defined"
884884
#else
885-
using U = PREDEF_UINT_TYPE;
885+
using U = DEF_UINT_TYPE;
886886
#endif
887887

888888
//#define XSTR(x) STR(x)
889889
//#define STR(x) #x
890-
//#pragma message "The value of PREDEF_UINT_TYPE: " XSTR(PREDEF_UINT_TYPE)
890+
//#pragma message "The value of DEF_UINT_TYPE: " XSTR(DEF_UINT_TYPE)
891891

892892

893893
/*
@@ -898,10 +898,10 @@ using namespace hurchalla;
898898
#endif
899899
*/
900900

901-
#ifndef PREDEF_MONT_TYPE
902-
# error "PREDEF_MONT_TYPE was not defined"
901+
#ifndef DEF_MONT_TYPE
902+
# error "DEF_MONT_TYPE was not defined"
903903
#else
904-
using MontType = PREDEF_MONT_TYPE<U>; // MontgomeryQuarter<U>;
904+
using MontType = DEF_MONT_TYPE<U>; // MontgomeryQuarter<U>;
905905
#endif
906906
/*
907907
# if 1

montgomery_arithmetic/include/hurchalla/montgomery_arithmetic/detail/impl_montgomery_two_pow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ goto break_0_1;
170170
HPBC_CLOCKWORK_ASSERT2(index <= MASK);
171171
V result = MFE::twoPowLimited(mf, index);
172172
while (shift >= P2) {
173-
if (USE_SLIDING_WINDOW_OPTIMIZATION) {
173+
if HURCHALLA_CPP17_CONSTEXPR (USE_SLIDING_WINDOW_OPTIMIZATION) {
174174
while (shift > P2 && (static_cast<size_t>(n>>(shift-1)) & 1u) == 0) {
175175
result = mf.square(result);
176176
--shift;

0 commit comments

Comments
 (0)