Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add push/pop instructions #498

Merged
merged 12 commits into from
Aug 8, 2023
Merged

Add push/pop instructions #498

merged 12 commits into from
Aug 8, 2023

Conversation

Dentosal
Copy link
Member

@Dentosal Dentosal commented Jun 28, 2023

Experimenting with push/pop opcodes. See spec PR FuelLabs/fuel-specs#499 and spec issue FuelLabs/fuel-specs#407

@Dentosal Dentosal self-assigned this Jun 28, 2023
@Dentosal Dentosal marked this pull request as ready for review July 4, 2023 03:30
@Dentosal Dentosal requested a review from a team July 12, 2023 17:05
@Dentosal Dentosal requested review from Voxelot and a team July 14, 2023 12:00
try_update_stack_pointer(sp, ssp, hp, stack_range.words().end)?;

// Write the registers to the stack
let mut it = memory[stack_range.usizes()].chunks_exact_mut(8);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to cross the heap here? Or is it not because we checked that inside of the try_update_stack_pointer?

Copy link
Member Author

Choose a reason for hiding this comment

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

try_update_stack_pointer performs the check

let mut it = memory[stack_range.usizes()].chunks_exact_mut(8);
for (i, reg) in program_regs.segment(segment).iter().enumerate() {
if (bitmask & (1 << i)) != 0 {
it.next().unwrap().copy_from_slice(&reg.to_be_bytes());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you use expect, please, with a description of why it is impossible?=)


// First update the new stack pointer, as that's the only error condition
let count = bitmask.count_ones();
let stack_range = MemoryRange::new(*sp, (count as u64) * 8)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
let stack_range = MemoryRange::new(*sp, (count as u64) * 8)?;
let stack_range = MemoryRange::new(*sp, count * 8)?;

Copy link
Member Author

Choose a reason for hiding this comment

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

That will not work; u32 doesn't implement ToAddr (unless we expand the implementation to cover it). The as-cast here is extending u32 returned by count_ones(), and is complely harmless. I'm replacing it with a .into() cast anyway, so it looks less suspicious.

fuel-vm/src/interpreter/memory.rs Outdated Show resolved Hide resolved
@xgreenx xgreenx added this pull request to the merge queue Aug 8, 2023
Merged via the queue into master with commit 11dc5c9 Aug 8, 2023
33 checks passed
@xgreenx xgreenx deleted the dento/scattered-push-pop branch August 8, 2023 11:11
@xgreenx xgreenx mentioned this pull request Aug 8, 2023
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