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

Function xor_2_nibbles

bitvm/src/hash/blake3_utils.rs:87–136  ·  view source on GitHub ↗

Calculates bitwise XOR of two nibbles (x_{nibble_x} and y_{nibble_y}), each given by their u32 variable and the index of their nibble, consumes the nibble of x (which shifts the remaining nibbles of x)

(
    stack: &mut StackTracker,
    x: &mut StackVariable,
    y: StackVariable,
    nibble_x: u8,
    nibble_y: u8,
    use_full_tables: bool,
)

Source from the content-addressed store, hash-verified

85
86/// Calculates bitwise XOR of two nibbles (x_{nibble_x} and y_{nibble_y}), each given by their u32 variable and the index of their nibble, consumes the nibble of x (which shifts the remaining nibbles of x)
87fn xor_2_nibbles(
88 stack: &mut StackTracker,
89 x: &mut StackVariable,
90 y: StackVariable,
91 nibble_x: u8,
92 nibble_y: u8,
93 use_full_tables: bool,
94) -> StackVariable {
95 if !use_full_tables {
96 stack.op_depth();
97
98 stack.op_dup();
99
100 stack.copy_var_sub_n(y, nibble_y as u32);
101 stack.move_var_sub_n(x, nibble_x as u32);
102 stack.op_2dup();
103 stack.op_min();
104 stack.to_altstack();
105
106 stack.op_max();
107
108 stack.op_sub();
109 stack.op_1sub();
110
111 stack.op_pick();
112
113 stack.op_add();
114
115 stack.from_altstack();
116
117 stack.op_sub();
118
119 stack.op_pick()
120 } else {
121 stack.op_depth();
122 stack.op_dup();
123
124 stack.copy_var_sub_n(y, nibble_y as u32);
125
126 stack.op_sub();
127 stack.op_pick();
128
129 stack.op_add();
130
131 stack.move_var_sub_n(x, nibble_x as u32);
132
133 stack.op_add();
134 stack.op_pick()
135 }
136}
137
138/// Calculates the bitwise XOR of two u32 numbers (x, y) and cyclically shifts them to right by 7. Consumes x and leaves y on the stack.
139fn xor_and_rotate_right_by_7(

Callers 3

compressFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected