Skip to content

Commit

Permalink
removed EQW instruction from VM
Browse files Browse the repository at this point in the history
  • Loading branch information
4rgon4ut committed Jul 21, 2022
1 parent 0c5d33e commit 1defdc4
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 109 deletions.
6 changes: 0 additions & 6 deletions core/src/operations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ pub enum Operation {
/// the stack, otherwise pushes 0 onto the stack.
Eqz,

/// Compares the first word (four elements) with the second word on the stack, if the words are
/// equal, pushes 1 onto the stack, otherwise pushes 0 onto the stack.
Eqw,

// ----- u32 operations -----------------------------------------------------------------------
/// Pops an element off the stack, splits it into upper and lower 32-bit values, and pushes
/// these values back onto the stack.
Expand Down Expand Up @@ -377,7 +373,6 @@ impl Operation {

Self::Eq => 0b0100_1001,
Self::Eqz => 5,
Self::Eqw => 6,

Self::Add => 0b0100_1000,
Self::Neg => 7,
Expand Down Expand Up @@ -524,7 +519,6 @@ impl fmt::Display for Operation {

Self::Eq => write!(f, "eq"),
Self::Eqz => write!(f, "eqz"),
Self::Eqw => write!(f, "eqw"),

// ----- u32 operations ---------------------------------------------------------------
Self::U32assert2 => write!(f, "u32assert2"),
Expand Down
55 changes: 0 additions & 55 deletions miden/tests/integration/operations/field_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,31 +484,6 @@ fn eq() {
test.expect_stack(&[1]);
}

#[test]
fn eqw() {
let asm_op = "eqw";

// --- test when top two words are equal ------------------------------------------------------
let values = vec![5, 4, 3, 2, 5, 4, 3, 2];
let mut expected = values.clone();
// push the result
expected.push(1);
// put it in stack order
expected.reverse();
let test = build_op_test!(asm_op, &values);
test.expect_stack(&expected);

// --- test when top two words are not equal --------------------------------------------------
let values = vec![8, 7, 6, 5, 4, 3, 2, 1];
let mut expected = values.clone();
// push the result
expected.push(0);
// put it in stack order
expected.reverse();
let test = build_op_test!(asm_op, &values);
test.expect_stack(&expected);
}

#[test]
fn lt() {
// Results in 1 if a < b for a starting stack of [b, a, ...] and 0 otherwise
Expand Down Expand Up @@ -667,36 +642,6 @@ proptest! {
test.prop_expect_stack(&[expected_result])?;
}

#[test]
fn eqw_proptest(w1 in prop_randw(), w2 in prop_randw()) {
// test the eqw assembly operation with randomized inputs
let asm_op = "eqw";

// 2 words (8 values) for comparison and 1 for the result
let mut values = vec![0; 2 * WORD_LEN + 1];

// check the inputs for equality in the field
let mut inputs_equal = true;
for (i, (a, b)) in w1.iter().zip(w2.iter()).enumerate() {
// if any of the values are unequal in the field, then the words will be unequal
if *a % Felt::MODULUS != *b % Felt::MODULUS {
inputs_equal = false;
}
// add the values to the vector
values[i] = *a;
values[i + WORD_LEN] = *b;
}

let test = build_op_test!(asm_op, &values);

// add the expected result to get the expected state
let expected_result = if inputs_equal { 1 } else { 0 };
values.push(expected_result);
values.reverse();

test.prop_expect_stack(&values)?;
}

#[test]
fn lt_proptest(a in any::<u64>(), b in any::<u64>()) {
// test the less-than assembly operation with randomized inputs
Expand Down
47 changes: 0 additions & 47 deletions processor/src/operations/field_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,28 +139,6 @@ impl Process {
self.stack.copy_state(1);
Ok(())
}

/// Compares the first word (four elements) with the second word on the stack, if the words are
/// equal, pushes ONE onto the stack, otherwise pushes ZERO onto the stack.
pub(super) fn op_eqw(&mut self) -> Result<(), ExecutionError> {
let b3 = self.stack.get(0);
let b2 = self.stack.get(1);
let b1 = self.stack.get(2);
let b0 = self.stack.get(3);

let a3 = self.stack.get(4);
let a2 = self.stack.get(5);
let a1 = self.stack.get(6);
let a0 = self.stack.get(7);

if a0 == b0 && a1 == b1 && a2 == b2 && a3 == b3 {
self.stack.set(0, Felt::ONE);
} else {
self.stack.set(0, Felt::ZERO);
}
self.stack.shift_right(0);
Ok(())
}
}

// TESTS
Expand Down Expand Up @@ -437,31 +415,6 @@ mod tests {
assert_eq!(expected, process.stack.trace_state());
}

#[test]
fn op_eqw() {
// --- test when top two words are equal ------------------------------
let mut process = Process::new_dummy();
let mut values = vec![1, 2, 3, 4, 5, 2, 3, 4, 5];
init_stack_with(&mut process, &values);

process.execute_op(Operation::Eqw).unwrap();
values.reverse();
values.insert(0, 1);
let expected = build_expected_from_ints(&values);
assert_eq!(expected, process.stack.trace_state());

// --- test when top two words are not equal --------------------------
let mut process = Process::new_dummy();
let mut values = vec![1, 2, 3, 4, 5, 6, 7, 8, 9];
init_stack_with(&mut process, &values);

process.execute_op(Operation::Eqw).unwrap();
values.reverse();
values.insert(0, 0);
let expected = build_expected_from_ints(&values);
assert_eq!(expected, process.stack.trace_state());
}

// HELPER FUNCTIONS
// --------------------------------------------------------------------------------------------

Expand Down
1 change: 0 additions & 1 deletion processor/src/operations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ impl Process {

Operation::Eq => self.op_eq()?,
Operation::Eqz => self.op_eqz()?,
Operation::Eqw => self.op_eqw()?,

// ----- u32 operations ---------------------------------------------------------------
Operation::U32split => self.op_u32split()?,
Expand Down

0 comments on commit 1defdc4

Please sign in to comment.