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

Function u4_and_with_xor_stack

bitvm/src/u4/u4_logic_stack.rs:99–110  ·  view source on GitHub ↗

Calculates the bitwise AND of top 2 u4 values using XOR tables Uses the formula (a and b) = ((a + b) - a XOR b) >> 1

(
    stack: &mut StackTracker,
    lookup_table: StackVariable,
    logic_table: StackVariable,
    shift_table: StackVariable,
)

Source from the content-addressed store, hash-verified

97/// Calculates the bitwise AND of top 2 u4 values using XOR tables
98/// Uses the formula (a and b) = ((a + b) - a XOR b) >> 1
99pub fn u4_and_with_xor_stack(
100 stack: &mut StackTracker,
101 lookup_table: StackVariable,
102 logic_table: StackVariable,
103 shift_table: StackVariable,
104) -> StackVariable {
105 stack.op_2dup();
106 u4_logic_with_table_stack(stack, lookup_table, logic_table);
107 stack.op_sub();
108 stack.op_add();
109 u4_rshift_stack(stack, shift_table, 1)
110}
111
112#[cfg(test)]
113mod tests {

Callers 3

Calls 2

u4_rshift_stackFunction · 0.85

Tested by 2