Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bitwise.cpp
Go to the documentation of this file.
2
3#include <cstdint>
4
6
7namespace bb::avm2::simulation {
8
21{
22 try {
23 MemoryValue c = a & b;
24 events.emit({ .operation = BitwiseOperation::AND, .a = a, .b = b, .res = static_cast<uint128_t>(c.as_ff()) });
25 return c;
26 } catch (const TaggedValueException& e) {
27 events.emit({ .operation = BitwiseOperation::AND, .a = a, .b = b, .res = 0 });
28 throw BitwiseException("AND, " + std::string(e.what()));
29 }
30}
31
44{
45 try {
46 MemoryValue c = a | b;
47 events.emit({ .operation = BitwiseOperation::OR, .a = a, .b = b, .res = static_cast<uint128_t>(c.as_ff()) });
48 return c;
49 } catch (const TaggedValueException& e) {
50 events.emit({ .operation = BitwiseOperation::OR, .a = a, .b = b, .res = 0 });
51 throw BitwiseException("OR, " + std::string(e.what()));
52 }
53}
54
67{
68 try {
69 MemoryValue c = a ^ b;
70 events.emit({
71 .operation = BitwiseOperation::XOR,
72 .a = a,
73 .b = b,
74 .res = static_cast<uint128_t>(c.as_ff()),
75 });
76 return c;
77 } catch (const TaggedValueException& e) {
78 events.emit({ .operation = BitwiseOperation::XOR, .a = a, .b = b, .res = 0 });
79 throw BitwiseException("XOR, " + std::string(e.what()));
80 }
81}
82
83} // namespace bb::avm2::simulation
MemoryValue and_op(const MemoryValue &a, const MemoryValue &b) override
Perform bitwise AND on two tagged memory values.
Definition bitwise.cpp:20
EventEmitterInterface< BitwiseEvent > & events
Definition bitwise.hpp:27
MemoryValue or_op(const MemoryValue &a, const MemoryValue &b) override
Perform bitwise OR on two tagged memory values.
Definition bitwise.cpp:43
MemoryValue xor_op(const MemoryValue &a, const MemoryValue &b) override
Perform bitwise XOR on two tagged memory values.
Definition bitwise.cpp:66
FF a
FF b
AVM range check gadget for witness generation.
unsigned __int128 uint128_t
Definition serialize.hpp:45