Skip to content

Commit de2c1b1

Browse files
committed
🩹 make limbs number accessible through the trait
1 parent a37cc07 commit de2c1b1

File tree

7 files changed

+11
-6
lines changed

7 files changed

+11
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# :heavy_multiplication_x: Fast Windowed Multiplication implementation in Bitcoin
22

3-
This repository contains the implementation of the Fast Multiplication algorithm in _Bitcoin_ for two 254-bit numbers using $w$-window multiplication.
3+
This repository contains the implementation of the Fast Multiplication algorithm in _Bitcoin_ for two 254-bit numbers using $w$-window multiplication.
44

55
## :interrobang: How to test?
66

src/bigint/arithmetics/add.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::bigint::NonNativeBigIntImpl;
2+
use crate::traits::integer::NonNativeLimbInteger;
23
use crate::treepp::*;
34

45
#[allow(non_snake_case)]

src/bigint/bits/implementation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{bigint::NonNativeBigIntImpl, treepp::*};
1+
use crate::{bigint::NonNativeBigIntImpl, traits::integer::NonNativeLimbInteger, treepp::*};
22
use std::cmp::min;
33

44
#[allow(non_snake_case)]

src/bigint/comparison/implementation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{bigint::NonNativeBigIntImpl, treepp::*};
1+
use crate::{bigint::NonNativeBigIntImpl, traits::integer::NonNativeLimbInteger, treepp::*};
22

33
#[allow(non_snake_case)]
44
impl<const N_BITS: usize, const LIMB_SIZE: usize> NonNativeBigIntImpl<N_BITS, LIMB_SIZE> {

src/bigint/implementation.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ impl<const N_BITS: usize, const LIMB_SIZE: usize> NonNativeLimbInteger
2727
}
2828

2929
impl<const N_BITS: usize, const LIMB_SIZE: usize> NonNativeBigIntImpl<N_BITS, LIMB_SIZE> {
30-
/// Number of limbs
31-
pub(super) const N_LIMBS: usize = (N_BITS + LIMB_SIZE - 1) / LIMB_SIZE;
3230
/// Base of the big integer is u32
3331
pub(super) const BASE: u32 = 1u32 << LIMB_SIZE;
3432
/// Numbers of bits in the head limb

src/bigint/stack/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::bigint::{NonNativeBigIntImpl, U254, U508};
22
use crate::debug::print_script_size;
33
use crate::traits::comparable::Comparable;
4-
use crate::traits::integer::NonNativeInteger;
4+
use crate::traits::integer::{NonNativeInteger, NonNativeLimbInteger};
55
use crate::treepp::{execute_script, pushable};
66
use bitcoin_script::script;
77
use num_bigint::{BigUint, RandomBits};

src/traits/integer.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,14 @@ pub trait NonNativeInteger: Comparable + Arithmeticable + Bitable {
8686
/// Note that the only requirement is to specify the total number of limbs and the size of each limb.
8787
#[allow(non_snake_case)]
8888
pub trait NonNativeLimbInteger: NonNativeInteger {
89+
/// The total number of bits in the integer.
8990
const N_BITS: usize;
91+
/// The size of each limb in bits.
9092
const LIMB_SIZE: usize;
93+
/// The total number of limbs in the integer.
94+
///
95+
/// **NOTE**: This is always calculated as `(N_BITS + LIMB_SIZE - 1) / LIMB_SIZE`.
96+
const N_LIMBS: usize = (Self::N_BITS + Self::LIMB_SIZE - 1) / Self::LIMB_SIZE;
9197

9298
/// Multiplies the top two big integers on the stack to get a big integer that is of type Q
9399
/// larger than the original type (for example, multiplying two 32-bit integers to get a 64-bit integer).

0 commit comments

Comments
 (0)