MCPcopy Create free account
hub / github.com/BitVM/BitVM / u4_add_internal_stack

Function u4_add_internal_stack

bitvm/src/u4/u4_add_stack.rs:90–123  ·  view source on GitHub ↗

Addition of numbers consisting of nibble_count u4's in the parameter bases locations The overflowing bit (if exists) is omitted

(
    stack: &mut StackTracker,
    nibble_count: u32,
    number_count: u32,
    quotient_table: StackVariable,
    modulo_table: StackVariable,
)

Source from the content-addressed store, hash-verified

88/// Addition of numbers consisting of nibble_count u4's in the parameter bases locations
89/// The overflowing bit (if exists) is omitted
90pub fn u4_add_internal_stack(
91 stack: &mut StackTracker,
92 nibble_count: u32,
93 number_count: u32,
94 quotient_table: StackVariable,
95 modulo_table: StackVariable,
96) {
97 for i in 0..nibble_count {
98 //extra add to add the carry from previous addition
99 if i > 0 {
100 stack.op_add();
101 }
102
103 //add the column of nibbles (needs one less add than nibble count)
104 for _ in 0..number_count - 1 {
105 stack.op_add();
106 }
107
108 // duplicate the result to be used to get the carry except for the last nibble
109 if i < nibble_count - 1 {
110 stack.op_dup();
111 }
112
113 //get the modulo of the addition
114 stack.get_value_from_table(modulo_table, None);
115 stack.to_altstack();
116
117 //we don't care about the last carry
118 if i < nibble_count - 1 {
119 //obtain the quotinent to be used as carry for the next addition
120 stack.get_value_from_table(quotient_table, None);
121 }
122 }
123}
124
125#[cfg(test)]
126mod tests {

Callers 2

test_add_internal_stackFunction · 0.85
test_add_for_blakeFunction · 0.85

Calls

no outgoing calls

Tested by 2

test_add_internal_stackFunction · 0.68
test_add_for_blakeFunction · 0.68