Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::avm2::simulation::Alu Class Reference

#include <alu.hpp>

Inheritance diagram for bb::avm2::simulation::Alu:
bb::avm2::simulation::AluInterface

Public Member Functions

 Alu (GreaterThanInterface &greater_than, FieldGreaterThanInterface &field_gt, RangeCheckInterface &range_check, EventEmitterInterface< AluEvent > &event_emitter)
 
MemoryValue add (const MemoryValue &a, const MemoryValue &b) override
 Add two memory values and emit an event of type AluEvent.
 
MemoryValue sub (const MemoryValue &a, const MemoryValue &b) override
 Subtract two memory values and emit an event of type AluEvent.
 
MemoryValue mul (const MemoryValue &a, const MemoryValue &b) override
 Multiply two memory values and emit an event of type AluEvent.
 
MemoryValue div (const MemoryValue &a, const MemoryValue &b) override
 Divide two memory values and emit an event of type AluEvent.
 
MemoryValue fdiv (const MemoryValue &a, const MemoryValue &b) override
 Perform field division on two memory values and emit an event of type AluEvent.
 
MemoryValue eq (const MemoryValue &a, const MemoryValue &b) override
 Check if two memory values are equal and emit an event of type AluEvent.
 
MemoryValue lt (const MemoryValue &a, const MemoryValue &b) override
 Check if the first memory value is less than the second and emit an event of type AluEvent.
 
MemoryValue lte (const MemoryValue &a, const MemoryValue &b) override
 Check if the first memory value is less than or equal to the second and emit an event of type AluEvent.
 
MemoryValue op_not (const MemoryValue &a) override
 Perform bitwise NOT operation on a memory value and emit an event of type AluEvent.
 
MemoryValue shr (const MemoryValue &a, const MemoryValue &b) override
 Perform right shift operation on a memory value and emit an event of type AluEvent.
 
MemoryValue shl (const MemoryValue &a, const MemoryValue &b) override
 Perform left shift operation on a memory value and emit an event of type AluEvent.
 
MemoryValue truncate (const FF &a, MemoryTag dst_tag) override
 Truncate a field element to a specific memory tag and emit an event of type AluEvent.
 
- Public Member Functions inherited from bb::avm2::simulation::AluInterface
virtual ~AluInterface ()=default
 

Private Attributes

GreaterThanInterfacegreater_than
 
FieldGreaterThanInterfacefield_gt
 
RangeCheckInterfacerange_check
 
EventEmitterInterface< AluEvent > & events
 

Detailed Description

Definition at line 13 of file alu.hpp.

Constructor & Destructor Documentation

◆ Alu()

bb::avm2::simulation::Alu::Alu ( GreaterThanInterface greater_than,
FieldGreaterThanInterface field_gt,
RangeCheckInterface range_check,
EventEmitterInterface< AluEvent > &  event_emitter 
)
inline

Definition at line 15 of file alu.hpp.

Member Function Documentation

◆ add()

MemoryValue bb::avm2::simulation::Alu::add ( const MemoryValue a,
const MemoryValue b 
)
overridevirtual

Add two memory values and emit an event of type AluEvent.

Exceptions
AluExceptionif the tags of a and b do not match.
Parameters
aThe first memory value.
bThe second memory value.
Returns
The sum of the two memory values. (same tag as a and b)

Implements bb::avm2::simulation::AluInterface.

Definition at line 24 of file alu.cpp.

◆ div()

MemoryValue bb::avm2::simulation::Alu::div ( const MemoryValue a,
const MemoryValue b 
)
overridevirtual

Divide two memory values and emit an event of type AluEvent.

Exceptions
AluExceptionif (in order):
  • the tags of a and b do not match
  • the divisor (b) zero
  • both a and b are field elements
Parameters
aThe dividend memory value.
bThe divisor memory value.
Returns
The quotient of the division. (same tag as a and b)

Implements bb::avm2::simulation::AluInterface.

Definition at line 108 of file alu.cpp.

◆ eq()

MemoryValue bb::avm2::simulation::Alu::eq ( const MemoryValue a,
const MemoryValue b 
)
overridevirtual

Check if two memory values are equal and emit an event of type AluEvent.

Exceptions
AluExceptionif the tags of a and b do not match.
Parameters
aThe first memory value.
bThe second memory value.
Returns
A boolean memory value (1 if equal, 0 if not equal).

Implements bb::avm2::simulation::AluInterface.

Definition at line 189 of file alu.cpp.

◆ fdiv()

MemoryValue bb::avm2::simulation::Alu::fdiv ( const MemoryValue a,
const MemoryValue b 
)
overridevirtual

Perform field division on two memory values and emit an event of type AluEvent.

Exceptions
AluExceptionif (in order):
  • the tags of a and b do not match
  • the divisor (b) zero
  • both a and b are non-field elements
Parameters
aThe dividend memory value.
bThe divisor memory value.
Returns
The quotient of the field division (field element).

Implements bb::avm2::simulation::AluInterface.

Definition at line 156 of file alu.cpp.

◆ lt()

MemoryValue bb::avm2::simulation::Alu::lt ( const MemoryValue a,
const MemoryValue b 
)
overridevirtual

Check if the first memory value is less than the second and emit an event of type AluEvent.

Exceptions
AluExceptionif the tags of a and b do not match.
Parameters
aThe first memory value.
bThe second memory value.
Returns
A boolean memory value (1 if a < b, 0 otherwise).

Implements bb::avm2::simulation::AluInterface.

Definition at line 210 of file alu.cpp.

◆ lte()

MemoryValue bb::avm2::simulation::Alu::lte ( const MemoryValue a,
const MemoryValue b 
)
overridevirtual

Check if the first memory value is less than or equal to the second and emit an event of type AluEvent.

Exceptions
AluExceptionif the tags of a and b do not match.
Parameters
aThe first memory value.
bThe second memory value.
Returns
A boolean memory value (1 if a <= b, 0 otherwise).

Implements bb::avm2::simulation::AluInterface.

Definition at line 233 of file alu.cpp.

◆ mul()

MemoryValue bb::avm2::simulation::Alu::mul ( const MemoryValue a,
const MemoryValue b 
)
overridevirtual

Multiply two memory values and emit an event of type AluEvent.

Exceptions
AluExceptionif the tags of a and b do not match.
Parameters
aThe first memory value.
bThe second memory value.
Returns
The product of the two memory values. (same tag as a and b)

Implements bb::avm2::simulation::AluInterface.

Definition at line 64 of file alu.cpp.

◆ op_not()

MemoryValue bb::avm2::simulation::Alu::op_not ( const MemoryValue a)
overridevirtual

Perform bitwise NOT operation on a memory value and emit an event of type AluEvent.

Exceptions
AluExceptionfor field elements.
Parameters
aThe memory value to negate.
Returns
The bitwise NOT of the memory value (same tag as a).

Implements bb::avm2::simulation::AluInterface.

Definition at line 256 of file alu.cpp.

◆ shl()

MemoryValue bb::avm2::simulation::Alu::shl ( const MemoryValue a,
const MemoryValue b 
)
overridevirtual

Perform left shift operation on a memory value and emit an event of type AluEvent.

Exceptions
AluExceptionif the tags (in order):
  • do not match
  • both a and b are field elements
Parameters
aThe memory value to shift.
bThe number of positions to shift left.
Returns
The result of the left shift operation (same tag as a and b).

Implements bb::avm2::simulation::AluInterface.

Definition at line 278 of file alu.cpp.

◆ shr()

MemoryValue bb::avm2::simulation::Alu::shr ( const MemoryValue a,
const MemoryValue b 
)
overridevirtual

Perform right shift operation on a memory value and emit an event of type AluEvent.

Exceptions
AluExceptionif the tags (in order):
  • do not match
  • both a and b are field elements
Parameters
aThe memory value to shift.
bThe number of positions to shift right.
Returns
The result of the right shift operation (same tag as a and b).

Implements bb::avm2::simulation::AluInterface.

Definition at line 320 of file alu.cpp.

◆ sub()

MemoryValue bb::avm2::simulation::Alu::sub ( const MemoryValue a,
const MemoryValue b 
)
overridevirtual

Subtract two memory values and emit an event of type AluEvent.

Exceptions
AluExceptionif the tags of a and b do not match.
Parameters
aThe first memory value (minuend).
bThe second memory value (subtrahend).
Returns
The difference of the two memory values. (same tag as a and b)

Implements bb::avm2::simulation::AluInterface.

Definition at line 44 of file alu.cpp.

◆ truncate()

MemoryValue bb::avm2::simulation::Alu::truncate ( const FF a,
MemoryTag  dst_tag 
)
overridevirtual

Truncate a field element to a specific memory tag and emit an event of type AluEvent.

Parameters
aThe field element to truncate.
dst_tagThe target memory tag to truncate to.
Returns
The truncated memory value (with tag dst_tag).

Implements bb::avm2::simulation::AluInterface.

Definition at line 359 of file alu.cpp.

Member Data Documentation

◆ events

EventEmitterInterface<AluEvent>& bb::avm2::simulation::Alu::events
private

Definition at line 42 of file alu.hpp.

◆ field_gt

FieldGreaterThanInterface& bb::avm2::simulation::Alu::field_gt
private

Definition at line 40 of file alu.hpp.

◆ greater_than

GreaterThanInterface& bb::avm2::simulation::Alu::greater_than
private

Definition at line 39 of file alu.hpp.

◆ range_check

RangeCheckInterface& bb::avm2::simulation::Alu::range_check
private

Definition at line 41 of file alu.hpp.


The documentation for this class was generated from the following files: