fuel-specs icon indicating copy to clipboard operation
fuel-specs copied to clipboard

`$hp` is initialised to incorrect value.

Open otrho opened this issue 2 years ago • 2 comments

At VM initialization it says:

$hp = VM_MAX_RAM - 1: the heap area begins at the top and is empty to start.

It makes more sense for $hp to be initialised to just VM_MAX_RAM. It always essentially points to either non-addressable memory or previously allocated buffers (via ALOC), both of which are essentially 'reserved'.

otrho avatar May 25 '22 07:05 otrho

This change would avoid having to offset the value by 1 to use allocated memory, right?

adlerjohn avatar May 25 '22 14:05 adlerjohn

Yep. Doing an aloc would be just:

let buf_addr = asm(size: size) {
    aloc size;
    hp: u64
}

...as per the discussion in https://github.com/FuelLabs/sway/pull/1627

otrho avatar May 25 '22 15:05 otrho

@Voxelot is there general consensus to go forward with this change?

adlerjohn avatar Feb 26 '23 02:02 adlerjohn

There is from the client-team side. @otrho also mentioned that the sway team could make a future-compatible workaround so that this change won't immediately break previously compiled code as well. But this workaround may not be needed if we do the change sooner.

Voxelot avatar Feb 27 '23 20:02 Voxelot