Adds the given constant numbers and u32 variables. Variables in `to_copy` are copied and the original remains on the stack. Variables in `to_move` are consumed from the stack.
(
stack: &mut StackTracker,
to_copy: Vec<StackVariable>,
mut to_move: Vec<&mut StackVariable>,
tables: &TablesVars,
)
| 199 | /// Variables in `to_copy` are copied and the original remains on the stack. |
| 200 | /// Variables in `to_move` are consumed from the stack. |
| 201 | fn u4_add_direct( |
| 202 | stack: &mut StackTracker, |
| 203 | to_copy: Vec<StackVariable>, |
| 204 | mut to_move: Vec<&mut StackVariable>, |
| 205 | tables: &TablesVars, |
| 206 | ) { |
| 207 | let nibble_count = 8; |
| 208 | let number_count = to_copy.len() + to_move.len(); |
| 209 | |
| 210 | for i in (0..nibble_count).rev() { |
| 211 | for x in to_copy.iter() { |
| 212 | stack.copy_var_sub_n(*x, i); |
| 213 | } |
| 214 | |
| 215 | for x in to_move.iter_mut() { |
| 216 | stack.move_var_sub_n(x, i); |
| 217 | } |
| 218 | |
| 219 | //add the numbers |
| 220 | for _ in 0..number_count - 1 { |
| 221 | stack.op_add(); |
| 222 | } |
| 223 | |
| 224 | //add the carry of the previous addition |
| 225 | if i < nibble_count - 1 { |
| 226 | stack.op_add(); |
| 227 | } |
| 228 | |
| 229 | if i > 0 { |
| 230 | //dup the result to be used to get the carry except for the last nibble |
| 231 | stack.op_dup(); |
| 232 | } |
| 233 | |
| 234 | //save value |
| 235 | let modulo = stack.get_value_from_table(tables.modulo, None); |
| 236 | stack.rename(modulo, &format!("modulo[{}]", i).to_string()); |
| 237 | stack.to_altstack(); |
| 238 | |
| 239 | if i > 0 { |
| 240 | let carry = stack.get_value_from_table(tables.quotient, None); |
| 241 | stack.rename(carry, "carry"); |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | /// Applies the G function (same notation as the paper) with the given parameters to the variables |
| 247 | #[allow(clippy::too_many_arguments)] |