Skip to content

Commit

Permalink
Merge pull request #222 from 0xPolygonMiden/greenhat/i211-update-vm-a…
Browse files Browse the repository at this point in the history
…bs-proc-path

[1/x] Update VM with the absolute paths support
  • Loading branch information
bitwalker authored Jul 10, 2024
2 parents 2fd472a + 77aa3ac commit 448b982
Show file tree
Hide file tree
Showing 15 changed files with 253 additions and 205 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ thiserror = { version = "1.0", git = "https://github.com/bitwalker/thiserror", b
toml = { version = "0.5", features = ["preserve_order"] }
derive_more = "0.99"
indexmap = "2.1"
# ddf536cd7157053f0940d7be41998b2a6546b4c1 is the latest commit in 'next' that includes the `if.true` empty blocks support
miden-assembly = { git = "https://github.com/0xPolygonMiden/miden-vm", rev = "ddf536cd7157053f0940d7be41998b2a6546b4c1" }
miden-core = { git = "https://github.com/0xPolygonMiden/miden-vm", rev = "ddf536cd7157053f0940d7be41998b2a6546b4c1" }
miden-processor = { git = "https://github.com/0xPolygonMiden/miden-vm", rev = "ddf536cd7157053f0940d7be41998b2a6546b4c1" }
miden-stdlib = { git = "https://github.com/0xPolygonMiden/miden-vm", rev = "ddf536cd7157053f0940d7be41998b2a6546b4c1" }
# 2da11ad0a975d2e5d6a2582871f0c89b820b3ffa is the latest commit in 'next' that includes
# the absolute paths support
miden-assembly = { git = "https://github.com/0xPolygonMiden/miden-vm", rev = "2da11ad0a975d2e5d6a2582871f0c89b820b3ffa" }
miden-core = { git = "https://github.com/0xPolygonMiden/miden-vm", rev = "2da11ad0a975d2e5d6a2582871f0c89b820b3ffa" }
miden-processor = { git = "https://github.com/0xPolygonMiden/miden-vm", rev = "2da11ad0a975d2e5d6a2582871f0c89b820b3ffa" }
miden-stdlib = { git = "https://github.com/0xPolygonMiden/miden-vm", rev = "2da11ad0a975d2e5d6a2582871f0c89b820b3ffa" }
midenc-codegen-masm = { path = "codegen/masm" }
miden-diagnostics = "0.1"
midenc-hir = { path = "hir" }
Expand Down
12 changes: 12 additions & 0 deletions codegen/masm/intrinsics/mem.masm
Original file line number Diff line number Diff line change
Expand Up @@ -562,3 +562,15 @@ export.store_sw # [waddr, index, offset, value]
end
end
end

# Store a double 32-bit machine word from the given native pointer triplet.
#
# A native pointer triplet consists of a word address which contains the
# start of the data; an element index, which indicates which element of
# the word the data starts in; and a byte offset, which indicates which
# byte is the start of the data.
export.store_dw # [waddr, index, offset, value]
# TODO: implement
# cleanup the operand stack
dropw
end
20 changes: 10 additions & 10 deletions codegen/masm/src/codegen/emit/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl<'a> OpEmitter<'a> {
Type::U32 | Type::U16 | Type::U8 | Type::I1 => {
self.emit(Op::U32Gt);
}
Type::I32 => self.emit(Op::Exec("intrinsics::i32::is_gt".parse().unwrap())),
Type::I32 => self.emit(Op::Exec("::intrinsics::i32::is_gt".parse().unwrap())),
ty => unimplemented!("gt is not yet implemented for {ty}"),
}
self.push(Type::I1);
Expand All @@ -186,7 +186,7 @@ impl<'a> OpEmitter<'a> {
Type::I32 => {
self.emit_all(&[
Op::PushU32(imm.as_i32().unwrap() as u32),
Op::Exec("intrinsics::i32::is_gt".parse().unwrap()),
Op::Exec("::intrinsics::i32::is_gt".parse().unwrap()),
]);
}
ty => unimplemented!("gt is not yet implemented for {ty}"),
Expand All @@ -206,7 +206,7 @@ impl<'a> OpEmitter<'a> {
Type::U32 | Type::U16 | Type::U8 | Type::I1 => {
self.emit(Op::U32Gte);
}
Type::I32 => self.emit(Op::Exec("intrinsics::i32::is_gte".parse().unwrap())),
Type::I32 => self.emit(Op::Exec("::intrinsics::i32::is_gte".parse().unwrap())),
ty => unimplemented!("gte is not yet implemented for {ty}"),
}
self.push(Type::I1);
Expand All @@ -226,7 +226,7 @@ impl<'a> OpEmitter<'a> {
Type::I32 => {
self.emit_all(&[
Op::PushU32(imm.as_i32().unwrap() as u32),
Op::Exec("intrinsics::i32::is_gte".parse().unwrap()),
Op::Exec("::intrinsics::i32::is_gte".parse().unwrap()),
]);
}
ty => unimplemented!("gte is not yet implemented for {ty}"),
Expand All @@ -246,7 +246,7 @@ impl<'a> OpEmitter<'a> {
Type::U32 | Type::U16 | Type::U8 | Type::I1 => {
self.emit(Op::U32Lt);
}
Type::I32 => self.emit(Op::Exec("intrinsics::i32::is_lt".parse().unwrap())),
Type::I32 => self.emit(Op::Exec("::intrinsics::i32::is_lt".parse().unwrap())),
ty => unimplemented!("lt is not yet implemented for {ty}"),
}
self.push(Type::I1);
Expand All @@ -266,7 +266,7 @@ impl<'a> OpEmitter<'a> {
Type::I32 => {
self.emit_all(&[
Op::PushU32(imm.as_i32().unwrap() as u32),
Op::Exec("intrinsics::i32::is_lt".parse().unwrap()),
Op::Exec("::intrinsics::i32::is_lt".parse().unwrap()),
]);
}
ty => unimplemented!("lt is not yet implemented for {ty}"),
Expand All @@ -286,7 +286,7 @@ impl<'a> OpEmitter<'a> {
Type::U32 | Type::U16 | Type::U8 | Type::I1 => {
self.emit(Op::U32Lte);
}
Type::I32 => self.emit(Op::Exec("intrinsics::i32::is_lte".parse().unwrap())),
Type::I32 => self.emit(Op::Exec("::intrinsics::i32::is_lte".parse().unwrap())),
ty => unimplemented!("lte is not yet implemented for {ty}"),
}
self.push(Type::I1);
Expand All @@ -306,7 +306,7 @@ impl<'a> OpEmitter<'a> {
Type::I32 => {
self.emit_all(&[
Op::PushU32(imm.as_i32().unwrap() as u32),
Op::Exec("intrinsics::i32::is_lte".parse().unwrap()),
Op::Exec("::intrinsics::i32::is_lte".parse().unwrap()),
]);
}
ty => unimplemented!("lte is not yet implemented for {ty}"),
Expand Down Expand Up @@ -788,7 +788,7 @@ impl<'a> OpEmitter<'a> {
self.emit_all(&[Op::Exp, Op::U32Assert]);
}
Type::I32 => {
self.emit(Op::Exec("intrinsics::i32::ipow".parse().unwrap()));
self.emit(Op::Exec("::intrinsics::i32::ipow".parse().unwrap()));
}
ty @ (Type::U16 | Type::U8) => {
self.emit_all(&[Op::Exp, Op::U32Assert]);
Expand Down Expand Up @@ -819,7 +819,7 @@ impl<'a> OpEmitter<'a> {
Type::I32 => {
self.emit_all(&[
Op::PushU8(exp),
Op::Exec("intrinsics::i32::ipow".parse().unwrap()),
Op::Exec("::intrinsics::i32::ipow".parse().unwrap()),
]);
}
ty @ (Type::U16 | Type::U8) => {
Expand Down
46 changes: 24 additions & 22 deletions codegen/masm/src/codegen/emit/int32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,10 @@ impl<'a> OpEmitter<'a> {
pub fn add_i32(&mut self, overflow: Overflow) {
self.emit(match overflow {
Overflow::Unchecked | Overflow::Wrapping => Op::U32WrappingAdd,
Overflow::Checked => Op::Exec("intrinsics::i32::checked_add".parse().unwrap()),
Overflow::Overflowing => Op::Exec("intrinsics::i32::overflowing_add".parse().unwrap()),
Overflow::Checked => Op::Exec("::intrinsics::i32::checked_add".parse().unwrap()),
Overflow::Overflowing => {
Op::Exec("::intrinsics::i32::overflowing_add".parse().unwrap())
}
})
}

Expand Down Expand Up @@ -427,12 +429,12 @@ impl<'a> OpEmitter<'a> {
Overflow::Checked => {
self.emit_all(&[
Op::PushU32(imm as u32),
Op::Exec("intrinsics::i32::checked_add".parse().unwrap()),
Op::Exec("::intrinsics::i32::checked_add".parse().unwrap()),
]);
}
Overflow::Overflowing => self.emit_all(&[
Op::PushU32(imm as u32),
Op::Exec("intrinsics::i32::overflowing_add".parse().unwrap()),
Op::Exec("::intrinsics::i32::overflowing_add".parse().unwrap()),
]),
}
}
Expand All @@ -458,10 +460,10 @@ impl<'a> OpEmitter<'a> {
match overflow {
Overflow::Unchecked | Overflow::Wrapping => self.sub_u32(overflow),
Overflow::Checked => {
self.emit(Op::Exec("intrinsics::i32::checked_sub".parse().unwrap()))
self.emit(Op::Exec("::intrinsics::i32::checked_sub".parse().unwrap()))
}
Overflow::Overflowing => {
self.emit(Op::Exec("intrinsics::i32::overflowing_sub".parse().unwrap()))
self.emit(Op::Exec("::intrinsics::i32::overflowing_sub".parse().unwrap()))
}
}
}
Expand Down Expand Up @@ -500,11 +502,11 @@ impl<'a> OpEmitter<'a> {
Overflow::Unchecked | Overflow::Wrapping => self.sub_imm_u32(imm as u32, overflow),
Overflow::Checked => self.emit_all(&[
Op::PushU32(imm as u32),
Op::Exec("intrinsics::i32::checked_sub".parse().unwrap()),
Op::Exec("::intrinsics::i32::checked_sub".parse().unwrap()),
]),
Overflow::Overflowing => self.emit_all(&[
Op::PushU32(imm as u32),
Op::Exec("intrinsics::i32::overflowing_sub".parse().unwrap()),
Op::Exec("::intrinsics::i32::overflowing_sub".parse().unwrap()),
]),
}
}
Expand All @@ -527,13 +529,13 @@ impl<'a> OpEmitter<'a> {
pub fn mul_i32(&mut self, overflow: Overflow) {
match overflow {
Overflow::Unchecked | Overflow::Wrapping => {
self.emit(Op::Exec("intrinsics::i32::wrapping_mul".parse().unwrap()))
self.emit(Op::Exec("::intrinsics::i32::wrapping_mul".parse().unwrap()))
}
Overflow::Checked => {
self.emit(Op::Exec("intrinsics::i32::checked_mul".parse().unwrap()))
self.emit(Op::Exec("::intrinsics::i32::checked_mul".parse().unwrap()))
}
Overflow::Overflowing => {
self.emit(Op::Exec("intrinsics::i32::overflowing_mul".parse().unwrap()))
self.emit(Op::Exec("::intrinsics::i32::overflowing_mul".parse().unwrap()))
}
}
}
Expand Down Expand Up @@ -584,15 +586,15 @@ impl<'a> OpEmitter<'a> {
imm => match overflow {
Overflow::Unchecked | Overflow::Wrapping => self.emit_all(&[
Op::PushU32(imm as u32),
Op::Exec("intrinsics::i32::wrapping_mul".parse().unwrap()),
Op::Exec("::intrinsics::i32::wrapping_mul".parse().unwrap()),
]),
Overflow::Checked => self.emit_all(&[
Op::PushU32(imm as u32),
Op::Exec("intrinsics::i32::checked_mul".parse().unwrap()),
Op::Exec("::intrinsics::i32::checked_mul".parse().unwrap()),
]),
Overflow::Overflowing => self.emit_all(&[
Op::PushU32(imm as u32),
Op::Exec("intrinsics::i32::overflowing_mul".parse().unwrap()),
Op::Exec("::intrinsics::i32::overflowing_mul".parse().unwrap()),
]),
},
}
Expand All @@ -609,7 +611,7 @@ impl<'a> OpEmitter<'a> {
///
/// This operation is checked, so if the operands or result are not valid i32, execution traps.
pub fn checked_div_i32(&mut self) {
self.emit(Op::Exec("intrinsics::i32::checked_div".parse().unwrap()));
self.emit(Op::Exec("::intrinsics::i32::checked_div".parse().unwrap()));
}

/// Pops a u32 value off the stack, `a`, and performs `a / <imm>`.
Expand All @@ -631,7 +633,7 @@ impl<'a> OpEmitter<'a> {
assert_ne!(imm, 0, "division by zero is not allowed");
self.emit_all(&[
Op::PushU32(imm as u32),
Op::Exec("intrinsics::i32::checked_div".parse().unwrap()),
Op::Exec("::intrinsics::i32::checked_div".parse().unwrap()),
]);
}

Expand Down Expand Up @@ -795,7 +797,7 @@ impl<'a> OpEmitter<'a> {
///
/// This operation is checked, if the operands or result are not valid i32, execution traps.
pub fn shr_i32(&mut self) {
self.emit(Op::Exec("intrinsics::i32::checked_shr".parse().unwrap()));
self.emit(Op::Exec("::intrinsics::i32::checked_shr".parse().unwrap()));
}

/// Pops a u32 value off the stack, `a`, and performs `a >> <imm>`
Expand All @@ -813,7 +815,7 @@ impl<'a> OpEmitter<'a> {
assert!(imm < 32, "invalid shift value: must be < 32, got {imm}");
self.emit_all(&[
Op::PushU32(imm as u32),
Op::Exec("intrinsics::i32::checked_shr".parse().unwrap()),
Op::Exec("::intrinsics::i32::checked_shr".parse().unwrap()),
]);
}

Expand Down Expand Up @@ -865,7 +867,7 @@ impl<'a> OpEmitter<'a> {
///
/// This operation is checked, if the operands or result are not valid i32, execution traps.
pub fn min_i32(&mut self) {
self.emit(Op::Exec("intrinsics::i32::min".parse().unwrap()));
self.emit(Op::Exec("::intrinsics::i32::min".parse().unwrap()));
}

/// Pops a u32 value off the stack, `a`, and puts the result of `min(a, imm)` on the stack
Expand All @@ -881,7 +883,7 @@ impl<'a> OpEmitter<'a> {
pub fn min_imm_i32(&mut self, imm: i32) {
self.emit_all(&[
Op::PushU32(imm as u32),
Op::Exec("intrinsics::i32::min".parse().unwrap()),
Op::Exec("::intrinsics::i32::min".parse().unwrap()),
]);
}

Expand All @@ -898,7 +900,7 @@ impl<'a> OpEmitter<'a> {
///
/// This operation is checked, if the operands or result are not valid i32, execution traps.
pub fn max_i32(&mut self) {
self.emit(Op::Exec("intrinsics::i32::max".parse().unwrap()));
self.emit(Op::Exec("::intrinsics::i32::max".parse().unwrap()));
}

/// Pops a u32 value off the stack, `a`, and puts the result of `max(a, imm)` on the stack
Expand All @@ -914,7 +916,7 @@ impl<'a> OpEmitter<'a> {
pub fn max_imm_i32(&mut self, imm: i32) {
self.emit_all(&[
Op::PushU32(imm as u32),
Op::Exec("intrinsics::i32::max".parse().unwrap()),
Op::Exec("::intrinsics::i32::max".parse().unwrap()),
]);
}
}
Loading

0 comments on commit 448b982

Please sign in to comment.