|
13 | 13 | #include "hurchalla/modular_arithmetic/modular_subtraction.h" |
14 | 14 | #include "hurchalla/util/traits/ut_numeric_limits.h" |
15 | 15 | #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" |
17 | 17 | #include "hurchalla/util/conditional_select.h" |
18 | 18 | #include "hurchalla/util/compiler_macros.h" |
19 | 19 | #include "hurchalla/modular_arithmetic/detail/clockwork_programming_by_contract.h" |
@@ -105,8 +105,13 @@ struct RedcIncomplete { |
105 | 105 | // compute m = (u * inv_n) % R |
106 | 106 | T m = static_cast<T>(static_cast<P>(u_lo) * static_cast<P>(inv_n)); |
107 | 107 |
|
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); |
110 | 115 |
|
111 | 116 | // mn = m*n. Since m = (u_lo*inv_n)%R, we know m < R, and thus mn < R*n. |
112 | 117 | // 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 { |
139 | 144 | // We simply disregard the low words of the minuend and subtrahend, since |
140 | 145 | // they are equal to each other. |
141 | 146 | // *** 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); |
143 | 150 |
|
144 | 151 | // Since u_hi and u_lo are type T (which is unsigned) variables, both |
145 | 152 | // 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> |
511 | 518 | HPBC_CLOCKWORK_PRECONDITION2(n > 1); |
512 | 519 |
|
513 | 520 | 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); |
516 | 522 | HPBC_CLOCKWORK_ASSERT2(mn_hi < n); |
517 | 523 | T reg = u_hi + n; |
518 | 524 |
|
@@ -574,8 +580,7 @@ struct RedcStandard<std::uint64_t> |
574 | 580 | HPBC_CLOCKWORK_PRECONDITION2(n > 1); |
575 | 581 |
|
576 | 582 | 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); |
579 | 584 | HPBC_CLOCKWORK_ASSERT2(mn_hi < n); |
580 | 585 | T reg = u_hi + n; |
581 | 586 | T uhi = u_hi; |
@@ -624,8 +629,7 @@ struct RedcStandard<std::uint32_t> |
624 | 629 | HPBC_CLOCKWORK_PRECONDITION2(n > 1); |
625 | 630 |
|
626 | 631 | 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); |
629 | 633 | HPBC_CLOCKWORK_ASSERT2(mn_hi < n); |
630 | 634 | T reg = u_hi + n; |
631 | 635 | T uhi = u_hi; |
@@ -683,8 +687,7 @@ struct RedcStandard<__uint128_t> |
683 | 687 | HPBC_CLOCKWORK_PRECONDITION2(n > 1); |
684 | 688 |
|
685 | 689 | 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); |
688 | 691 | HPBC_CLOCKWORK_ASSERT2(mn_hi < n); |
689 | 692 | T reg = u_hi + n; |
690 | 693 |
|
@@ -746,8 +749,7 @@ struct RedcStandard<std::uint64_t> |
746 | 749 | HPBC_CLOCKWORK_PRECONDITION2(n > 1); |
747 | 750 |
|
748 | 751 | 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); |
751 | 753 | HPBC_CLOCKWORK_ASSERT2(mn_hi < n); |
752 | 754 | T reg = u_hi + n; |
753 | 755 |
|
|
0 commit comments