Skip to content

Commit

Permalink
feat: added assert_eqw instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
hackaugusto committed Mar 2, 2023
1 parent 3a45724 commit b7941f3
Show file tree
Hide file tree
Showing 8 changed files with 256 additions and 238 deletions.
10 changes: 10 additions & 0 deletions assembly/src/assembler/instruction/field_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ use crate::MAX_EXP_BITS;
/// Field element representing TWO in the base field of the VM.
const TWO: Felt = Felt::new(2);

// ASSERTIONS
// ================================================================================================

/// Asserts that the top two words in the stack are equal.
///
/// VM cycles: 11 cycles
pub fn assertw(span: &mut SpanBuilder) -> Result<Option<CodeBlock>, AssemblyError> {
span.add_ops([MovUp4, Eq, Assert, MovUp3, Eq, Assert, MovUp2, Eq, Assert, Eq, Assert])
}

// BASIC ARITHMETIC OPERATIONS
// ================================================================================================

Expand Down
1 change: 1 addition & 0 deletions assembly/src/assembler/instruction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl Assembler {
let result = match instruction {
Instruction::Assert => span.add_op(Assert),
Instruction::AssertEq => span.add_ops([Eq, Assert]),
Instruction::AssertEqw => field_ops::assertw(span),
Instruction::Assertz => span.add_ops([Eqz, Assert]),

Instruction::Add => span.add_op(Add),
Expand Down
1 change: 1 addition & 0 deletions assembly/src/parsers/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ impl ParserContext {
"assert" => simple_instruction(op, Assert),
"assertz" => simple_instruction(op, Assertz),
"assert_eq" => simple_instruction(op, AssertEq),
"assert_eqw" => simple_instruction(op, AssertEqw),

"add" => field_ops::parse_add(op),
"sub" => field_ops::parse_sub(op),
Expand Down
2 changes: 2 additions & 0 deletions assembly/src/parsers/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub enum Node {
pub enum Instruction {
Assert,
AssertEq,
AssertEqw,
Assertz,
Add,
AddImm(Felt),
Expand Down Expand Up @@ -282,6 +283,7 @@ impl fmt::Display for Instruction {
match self {
Self::Assert => write!(f, "assert"),
Self::AssertEq => write!(f, "assert_eq"),
Self::AssertEqw => write!(f, "assert_eqw"),
Self::Assertz => write!(f, "assertz"),
Self::Add => write!(f, "add"),
Self::AddImm(value) => write!(f, "add.{value}"),
Expand Down
1 change: 1 addition & 0 deletions assembly/src/parsers/serde/deserialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl Deserializable for Instruction {
match opcode {
OpCode::Assert => Ok(Instruction::Assert),
OpCode::AssertEq => Ok(Instruction::AssertEq),
OpCode::AssertEqw => Ok(Instruction::AssertEqw),
OpCode::Assertz => Ok(Instruction::Assertz),
OpCode::Add => Ok(Instruction::Add),
OpCode::AddImm => Ok(Instruction::AddImm(bytes.read_felt()?)),
Expand Down
Loading

0 comments on commit b7941f3

Please sign in to comment.