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#include <stdexcept>
5
8
9namespace bb::avm2::simulation {
10
12{
13 try {
14 MemoryValue c = a & b;
15 events.emit({ .operation = BitwiseOperation::AND, .a = a, .b = b, .res = static_cast<uint128_t>(c.as_ff()) });
16 return c;
17 } catch (const std::exception& e) {
18 // We emit an event if we fail, but default the result to 0.
19 events.emit({ .operation = BitwiseOperation::AND, .a = a, .b = b, .res = 0 });
20 throw BitwiseException("AND, " + std::string(e.what()));
21 }
22}
23
25{
26 try {
27 MemoryValue c = a | b;
28 events.emit({ .operation = BitwiseOperation::OR, .a = a, .b = b, .res = static_cast<uint128_t>(c.as_ff()) });
29 return c;
30 } catch (const std::exception& e) {
31 // We emit an event if we fail, but default the result to 0.
32 events.emit({ .operation = BitwiseOperation::OR, .a = a, .b = b, .res = 0 });
33 throw BitwiseException("OR, " + std::string(e.what()));
34 }
35}
36
38{
39 try {
40 MemoryValue c = a ^ b;
41 events.emit({
42 .operation = BitwiseOperation::XOR,
43 .a = a,
44 .b = b,
45 .res = static_cast<uint128_t>(c.as_ff()),
46 });
47 return c;
48 } catch (const std::exception& e) {
49 // We emit an event if we fail, but default the result to 0.
50 events.emit({ .operation = BitwiseOperation::XOR, .a = a, .b = b, .res = 0 });
51 throw BitwiseException("XOR, " + std::string(e.what()));
52 }
53}
54
55} // namespace bb::avm2::simulation
MemoryValue and_op(const MemoryValue &a, const MemoryValue &b) override
Definition bitwise.cpp:11
EventEmitterInterface< BitwiseEvent > & events
Definition bitwise.hpp:32
MemoryValue or_op(const MemoryValue &a, const MemoryValue &b) override
Definition bitwise.cpp:24
MemoryValue xor_op(const MemoryValue &a, const MemoryValue &b) override
Definition bitwise.cpp:37
FF a
FF b
unsigned __int128 uint128_t
Definition serialize.hpp:44