Skip to content

Commit e5077b5

Browse files
committed
call new multiply_to_hi_product function in util library instead of multiply_to_hilo_product, where possible
1 parent b8d995f commit e5077b5

File tree

7 files changed

+24
-22
lines changed

7 files changed

+24
-22
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 5ff4af01d0a769968e56bc668f4c9a9ad1896749
78+
GIT_TAG ba38c2c5e1164e0e7ab480e4fc959c3a43183c0e
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
@@ -79,7 +79,7 @@ include(FetchContent)
7979
FetchContent_Declare(
8080
hurchalla_util
8181
GIT_REPOSITORY https://github.com/hurchalla/util.git
82-
GIT_TAG 5ff4af01d0a769968e56bc668f4c9a9ad1896749
82+
GIT_TAG ba38c2c5e1164e0e7ab480e4fc959c3a43183c0e
8383
)
8484
FetchContent_MakeAvailable(hurchalla_util)
8585

montgomery_arithmetic/include/hurchalla/montgomery_arithmetic/detail/MontyFullRange.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,12 @@ class MontyFullRange final :
350350

351351
// return the high word of the product, and write the low word of the
352352
// product to u_lo.
353-
HURCHALLA_FORCE_INLINE T multiplyToHiLo(T& u_lo, V x, V y) const
353+
HURCHALLA_FORCE_INLINE T multiplyToHiLo(T& HURCHALLA_RESTRICT u_lo, V x, V y) const
354354
{
355355
namespace hc = ::hurchalla;
356356
return hc::unsigned_multiply_to_hilo_product(u_lo, x.get(), y.get());
357357
}
358-
HURCHALLA_FORCE_INLINE T squareToHiLo(T& u_lo, V x) const
358+
HURCHALLA_FORCE_INLINE T squareToHiLo(T& HURCHALLA_RESTRICT u_lo, V x) const
359359
{
360360
namespace hc = ::hurchalla;
361361
return hc::unsigned_square_to_hilo_product(u_lo, x.get());

montgomery_arithmetic/include/hurchalla/montgomery_arithmetic/detail/MontyHalfRange.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ class MontyHalfRange final :
700700
HPBC_CLOCKWORK_POSTCONDITION2(0 <= u_hi && u_hi < n_);
701701
return u_hi;
702702
}
703-
HURCHALLA_FORCE_INLINE T squareToHiLo(T& u_lo, V x) const
703+
HURCHALLA_FORCE_INLINE T squareToHiLo(T& HURCHALLA_RESTRICT u_lo, V x) const
704704
{
705705
HPBC_CLOCKWORK_PRECONDITION2(isValid(x));
706706
namespace hc = ::hurchalla;

montgomery_arithmetic/include/hurchalla/montgomery_arithmetic/detail/MontyQuarterRange.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,12 +491,12 @@ class MontyQuarterRange final : public
491491

492492
// return the high word of the product, and write the low word of the
493493
// product to u_lo.
494-
HURCHALLA_FORCE_INLINE T multiplyToHiLo(T& u_lo, V x, V y) const
494+
HURCHALLA_FORCE_INLINE T multiplyToHiLo(T& HURCHALLA_RESTRICT u_lo, V x, V y) const
495495
{
496496
namespace hc = ::hurchalla;
497497
return hc::unsigned_multiply_to_hilo_product(u_lo, x.get(), y.get());
498498
}
499-
HURCHALLA_FORCE_INLINE T squareToHiLo(T& u_lo, V x) const
499+
HURCHALLA_FORCE_INLINE T squareToHiLo(T& HURCHALLA_RESTRICT u_lo, V x) const
500500
{
501501
namespace hc = ::hurchalla;
502502
return hc::unsigned_square_to_hilo_product(u_lo, x.get());

montgomery_arithmetic/include/hurchalla/montgomery_arithmetic/detail/experimental/MontyFullRangeMasked.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ class MontyFullRangeMasked final :
424424

425425
// This function computes the full two-word product of x*x. It returns the
426426
// high word of x*x, and writes the low word of x*x to u_lo.
427-
HURCHALLA_FORCE_INLINE T squareToHiLo(T& u_lo, V x) const
427+
HURCHALLA_FORCE_INLINE T squareToHiLo(T& HURCHALLA_RESTRICT u_lo, V x) const
428428
{
429429
HPBC_CLOCKWORK_PRECONDITION2(isValid(x));
430430
T a = x.getbits();

montgomery_arithmetic/include/hurchalla/montgomery_arithmetic/low_level_api/detail/platform_specific/ImplRedc.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "hurchalla/modular_arithmetic/modular_subtraction.h"
1414
#include "hurchalla/util/traits/ut_numeric_limits.h"
1515
#include "hurchalla/util/traits/safely_promote_unsigned.h"
16-
#include "hurchalla/util/unsigned_multiply_to_hilo_product.h"
16+
#include "hurchalla/util/unsigned_multiply_to_hi_product.h"
1717
#include "hurchalla/util/conditional_select.h"
1818
#include "hurchalla/util/compiler_macros.h"
1919
#include "hurchalla/modular_arithmetic/detail/clockwork_programming_by_contract.h"
@@ -105,8 +105,13 @@ struct RedcIncomplete {
105105
// compute m = (u * inv_n) % R
106106
T m = static_cast<T>(static_cast<P>(u_lo) * static_cast<P>(inv_n));
107107

108-
T mn_lo;
109-
T mn_hi = ::hurchalla::unsigned_multiply_to_hilo_product(mn_lo, m, n);
108+
//T mn_lo;
109+
// since we now skip calculating mn_lo (it's not used anyway), by calling
110+
// unsigned_multiply_to_hi_product(), mn_lo can be considered to be an
111+
// implied variable for explanation purposes, rather than a programming
112+
// variable.
113+
//T mn_hi = ::hurchalla::unsigned_multiply_to_hilo_product(mn_lo, m, n);
114+
T mn_hi = ::hurchalla::unsigned_multiply_to_hi_product(m, n);
110115

111116
// mn = m*n. Since m = (u_lo*inv_n)%R, we know m < R, and thus mn < R*n.
112117
// Therefore mn == mn_hi*R + mn_lo < R*n, and mn_hi*R < R*n - mn_lo <= R*n,
@@ -139,7 +144,9 @@ struct RedcIncomplete {
139144
// We simply disregard the low words of the minuend and subtrahend, since
140145
// they are equal to each other.
141146
// *** Assertion #2 ***
142-
HPBC_CLOCKWORK_ASSERT2(u_lo == mn_lo);
147+
// since we skip calculting the unused variable mn_lo, we can't actually
148+
// call this assert anymore, even though it would be true.
149+
//HPBC_CLOCKWORK_ASSERT2(u_lo == mn_lo);
143150

144151
// Since u_hi and u_lo are type T (which is unsigned) variables, both
145152
// u_hi >= 0 and u_lo >= 0, and thus u = u_hi*R + u_lo >= 0. Along with
@@ -511,8 +518,7 @@ struct RedcStandard<__uint128_t>
511518
HPBC_CLOCKWORK_PRECONDITION2(n > 1);
512519

513520
T m = static_cast<T>(static_cast<P>(u_lo) * static_cast<P>(inv_n));
514-
T mn_lo;
515-
T mn_hi = ::hurchalla::unsigned_multiply_to_hilo_product(mn_lo, m, n);
521+
T mn_hi = ::hurchalla::unsigned_multiply_to_hi_product(m, n);
516522
HPBC_CLOCKWORK_ASSERT2(mn_hi < n);
517523
T reg = u_hi + n;
518524

@@ -574,8 +580,7 @@ struct RedcStandard<std::uint64_t>
574580
HPBC_CLOCKWORK_PRECONDITION2(n > 1);
575581

576582
T m = static_cast<T>(static_cast<P>(u_lo) * static_cast<P>(inv_n));
577-
T mn_lo;
578-
T mn_hi = ::hurchalla::unsigned_multiply_to_hilo_product(mn_lo, m, n);
583+
T mn_hi = ::hurchalla::unsigned_multiply_to_hi_product(m, n);
579584
HPBC_CLOCKWORK_ASSERT2(mn_hi < n);
580585
T reg = u_hi + n;
581586
T uhi = u_hi;
@@ -624,8 +629,7 @@ struct RedcStandard<std::uint32_t>
624629
HPBC_CLOCKWORK_PRECONDITION2(n > 1);
625630

626631
T m = static_cast<T>(static_cast<P>(u_lo) * static_cast<P>(inv_n));
627-
T mn_lo;
628-
T mn_hi = ::hurchalla::unsigned_multiply_to_hilo_product(mn_lo, m, n);
632+
T mn_hi = ::hurchalla::unsigned_multiply_to_hi_product(m, n);
629633
HPBC_CLOCKWORK_ASSERT2(mn_hi < n);
630634
T reg = u_hi + n;
631635
T uhi = u_hi;
@@ -683,8 +687,7 @@ struct RedcStandard<__uint128_t>
683687
HPBC_CLOCKWORK_PRECONDITION2(n > 1);
684688

685689
T m = static_cast<T>(static_cast<P>(u_lo) * static_cast<P>(inv_n));
686-
T mn_lo;
687-
T mn_hi = ::hurchalla::unsigned_multiply_to_hilo_product(mn_lo, m, n);
690+
T mn_hi = ::hurchalla::unsigned_multiply_to_hi_product(m, n);
688691
HPBC_CLOCKWORK_ASSERT2(mn_hi < n);
689692
T reg = u_hi + n;
690693

@@ -746,8 +749,7 @@ struct RedcStandard<std::uint64_t>
746749
HPBC_CLOCKWORK_PRECONDITION2(n > 1);
747750

748751
T m = static_cast<T>(static_cast<P>(u_lo) * static_cast<P>(inv_n));
749-
T mn_lo;
750-
T mn_hi = ::hurchalla::unsigned_multiply_to_hilo_product(mn_lo, m, n);
752+
T mn_hi = ::hurchalla::unsigned_multiply_to_hi_product(m, n);
751753
HPBC_CLOCKWORK_ASSERT2(mn_hi < n);
752754
T reg = u_hi + n;
753755

0 commit comments

Comments
 (0)