Skip to content

Conversation

pacheco
Copy link
Contributor

@pacheco pacheco commented Aug 6, 2025

Use OpenVM specific settings instead of the generic one, so we're able to do "one to many" translation of directives

@pacheco pacheco requested review from Copilot and lvella and removed request for Copilot August 6, 2025 18:51
Copilot

This comment was marked as resolved.

@powdr-labs powdr-labs deleted a comment from Copilot AI Aug 6, 2025
@powdr-labs powdr-labs deleted a comment from Copilot AI Aug 6, 2025
Comment on lines 245 to 275
fn allocate_loop_frame_slots(
&self,
need_ret_info: bool,
saved_fps: BTreeSet<u32>,
) -> (RegisterGenerator<'a, Self>, LoopFrameLayout) {
let mut rgen = RegisterGenerator::new();

let ret_info = need_ret_info.then(|| {
// Allocate the return PC and frame pointer for the loop.
let ret_pc = rgen.allocate_words(Self::words_per_ptr());
let ret_fp = rgen.allocate_words(Self::words_per_ptr());
ReturnInfo { ret_pc, ret_fp }
});

// Allocate the slots for the saved frame pointers.
let saved_fps = saved_fps
.into_iter()
.map(|depth| {
let outer_fp = rgen.allocate_words(Self::words_per_ptr());
(depth, outer_fp)
})
.collect();

(
rgen,
LoopFrameLayout {
saved_fps,
ret_info,
},
)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a matter for another PR, in womir, but I think this function should have a default implementation. It was created for PetraVM, that I think would require a different layout...

Comment on lines 356 to 397
fn emit_jump_into_loop(
&self,
_g: &mut womir::loader::flattening::Generators<'a, '_, Self>,
loop_label: String,
loop_frame_ptr: std::ops::Range<u32>,
ret_info_to_copy: Option<womir::loader::flattening::settings::ReturnInfosToCopy>,
saved_curr_fp_ptr: Option<std::ops::Range<u32>>,
) -> Vec<Self::Directive> {
let mut directives = if let Some(to_copy) = ret_info_to_copy {
assert_eq!(Self::words_per_ptr(), 1);
vec![
Directive::Instruction(ib::copy_into_frame(
to_copy.dest.ret_pc.start as usize,
to_copy.src.ret_pc.start as usize,
loop_frame_ptr.start as usize,
)),
Directive::Instruction(ib::copy_into_frame(
to_copy.dest.ret_fp.start as usize,
to_copy.src.ret_fp.start as usize,
loop_frame_ptr.start as usize,
)),
]
} else {
Vec::new()
};

let jump = if let Some(saved_caller_fp) = saved_curr_fp_ptr {
Directive::JaafSave {
target: loop_label,
new_frame_ptr: loop_frame_ptr.start,
saved_caller_fp: saved_caller_fp.start,
}
} else {
Directive::Jaaf {
target: loop_label,
new_frame_ptr: loop_frame_ptr.start,
}
};

directives.push(jump);
directives
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar situation to allocate_loop_frame_slots: implementing this at this level should not be needed, and can be improved in womir.

@lvella lvella merged commit 00504ad into main Aug 7, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants