Skip to content

Commit

Permalink
Merge pull request #1407 from o1-labs/feature/lookup-numerator-as-var…
Browse files Browse the repository at this point in the history
…iable

Add a sign to lookup numerators
  • Loading branch information
mrmr1993 authored Dec 5, 2023
2 parents a03e597 + d04d82a commit d9e730a
Showing 1 changed file with 45 additions and 9 deletions.
54 changes: 45 additions & 9 deletions optimism/src/mips/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@ pub enum ITypeInstruction {
StoreWordRight, // swr
}

#[derive(Copy, Clone, Debug)]
pub enum Sign {
Pos,
Neg,
}

#[derive(Copy, Clone, Debug)]
pub struct Signed<T> {
pub sign: Sign,
pub magnitude: T,
}

#[derive(Copy, Clone, Debug)]
pub enum LookupTable {
MemoryLookup,
Expand All @@ -164,7 +176,7 @@ pub enum LookupTable {

#[derive(Clone, Debug)]
pub struct Lookup<Fp> {
pub numerator: i32, // FIXME: Bad, sad hack.
pub numerator: Signed<Fp>,
pub table_id: LookupTable,
pub value: Vec<Fp>,
}
Expand Down Expand Up @@ -255,12 +267,18 @@ pub trait InterpreterEnv {
instruction_counter + Self::constant(1)
};
self.add_lookup(Lookup {
numerator: 1,
numerator: Signed {
sign: Sign::Pos,
magnitude: Self::constant(1),
},
table_id: LookupTable::RegisterLookup,
value: vec![idx.clone(), last_accessed, old_value.clone()],
});
self.add_lookup(Lookup {
numerator: -1,
numerator: Signed {
sign: Sign::Neg,
magnitude: Self::constant(1),
},
table_id: LookupTable::RegisterLookup,
value: vec![idx.clone(), new_accessed, new_value.clone()],
});
Expand Down Expand Up @@ -358,12 +376,18 @@ pub trait InterpreterEnv {
instruction_counter + Self::constant(1)
};
self.add_lookup(Lookup {
numerator: 1,
numerator: Signed {
sign: Sign::Pos,
magnitude: Self::constant(1),
},
table_id: LookupTable::MemoryLookup,
value: vec![addr.clone(), last_accessed, old_value.clone()],
});
self.add_lookup(Lookup {
numerator: -1,
numerator: Signed {
sign: Sign::Neg,
magnitude: Self::constant(1),
},
table_id: LookupTable::MemoryLookup,
value: vec![addr.clone(), new_accessed, new_value.clone()],
});
Expand Down Expand Up @@ -408,7 +432,10 @@ pub trait InterpreterEnv {
self.push_register(&idx, ip.clone());
}
self.add_lookup(Lookup {
numerator: -1,
numerator: Signed {
sign: Sign::Neg,
magnitude: Self::constant(1),
},
table_id: LookupTable::RegisterLookup,
value: vec![idx, new_accessed, ip],
});
Expand All @@ -421,7 +448,10 @@ pub trait InterpreterEnv {
unsafe { self.fetch_register(&idx, value_location) }
};
self.add_lookup(Lookup {
numerator: 1,
numerator: Signed {
sign: Sign::Pos,
magnitude: Self::constant(1),
},
table_id: LookupTable::RegisterLookup,
value: vec![idx, self.instruction_counter(), ip.clone()],
});
Expand All @@ -438,7 +468,10 @@ pub trait InterpreterEnv {
self.push_register(&idx, ip.clone());
}
self.add_lookup(Lookup {
numerator: -1,
numerator: Signed {
sign: Sign::Neg,
magnitude: Self::constant(1),
},
table_id: LookupTable::RegisterLookup,
value: vec![idx, new_accessed, ip],
});
Expand All @@ -451,7 +484,10 @@ pub trait InterpreterEnv {
unsafe { self.fetch_register(&idx, value_location) }
};
self.add_lookup(Lookup {
numerator: 1,
numerator: Signed {
sign: Sign::Pos,
magnitude: Self::constant(1),
},
table_id: LookupTable::RegisterLookup,
value: vec![idx, self.instruction_counter(), ip.clone()],
});
Expand Down

0 comments on commit d9e730a

Please sign in to comment.