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

Intrinsics for the VM's storage opcodes. #2508

Merged
merged 24 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ecee49b
Add storage load/store word intrinsics
vaivaswatha Aug 9, 2022
4ab8013
Storage load/store quad intrinsics
vaivaswatha Aug 10, 2022
9863a44
Merge branch 'master' into vaivaswatha/storage_intrinsics
vaivaswatha Aug 10, 2022
2c0a816
Update hash of a test
vaivaswatha Aug 10, 2022
3aee84a
fix clippy
vaivaswatha Aug 10, 2022
26807c7
Process key_reg after val_reg to avoid diffs in asm gen tests
vaivaswatha Aug 10, 2022
799b981
Merge branch 'master' into vaivaswatha/storage_intrinsics
vaivaswatha Aug 10, 2022
e7f8168
Fix a deployment based test with right hash
vaivaswatha Aug 10, 2022
75e7a9c
Add asm gen test
vaivaswatha Aug 10, 2022
ca164d3
Merge branch 'master' into vaivaswatha/storage_intrinsics
vaivaswatha Aug 10, 2022
82a2e6e
Check arguments after monomorphization, during IR gen
vaivaswatha Aug 11, 2022
88e954d
Replace asm with intrinsics in storage.sw
vaivaswatha Aug 11, 2022
2c2015f
Restore storage.sw
vaivaswatha Aug 11, 2022
d1f11e2
minor fixes
vaivaswatha Aug 11, 2022
ba5e609
Update storage.sw and add exhaustive tests
vaivaswatha Aug 12, 2022
4d433e3
Merge branch 'master' into vaivaswatha/storage_intrinsics
vaivaswatha Aug 12, 2022
66fe14c
Update JSON ABI
vaivaswatha Aug 12, 2022
cad780b
Move cfei into an alloca lib function
vaivaswatha Aug 12, 2022
6db548d
Update contract hash in calling script
vaivaswatha Aug 12, 2022
a6a59d1
Revert "Move cfei into an alloca lib function"
vaivaswatha Aug 12, 2022
594a5b9
Revert "Update contract hash in calling script"
vaivaswatha Aug 12, 2022
fa82947
Merge remote-tracking branch 'origin/master' into vaivaswatha/storage…
vaivaswatha Aug 16, 2022
a27f9b3
Merge branch 'master' into vaivaswatha/storage_intrinsics
vaivaswatha Aug 16, 2022
80858ab
Merge branch 'master' into vaivaswatha/storage_intrinsics
sezna Aug 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions sway-lib-std/src/alloc.sw
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
library alloc;

use ::mem::copy;
use ::context::registers::stack_ptr;

/// Allocates zeroed memory on the heap
///
Expand Down Expand Up @@ -45,3 +46,12 @@ pub fn realloc(ptr: u64, size: u64, new_size: u64) -> u64 {
ptr
}
}

// Allocate a type on the stack.
pub fn alloca<T>() -> u64 {
let current_pointer = stack_ptr();
asm() {
cfei i32;
Copy link
Contributor

@otrho otrho Aug 12, 2022

Choose a reason for hiding this comment

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

This is allocating 32 bytes, where it needs to allocate __size_of<T>().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is allocating 32 bytes, where it needs to allocate '__size_of()`.

Oops, yes. Let me fix this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dropping (and reverting related commits) this as it needs to be an intrinsic. The argument to cfei must be an immediate :-(

};
current_pointer
}
2 changes: 1 addition & 1 deletion sway-lib-std/src/lib.sw
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ dep assert;
dep option;
dep result;
dep mem;
dep alloc;
dep contract_id;
dep constants;
dep context;
dep alloc;
dep hash;
dep r#storage;
dep b512;
Expand Down
11 changes: 3 additions & 8 deletions sway-lib-std/src/storage.sw
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use ::context::registers::stack_ptr;
use ::hash::sha256;
use ::option::Option;
use ::result::Result;
use ::alloc::alloca;

/// Store a stack variable in storage.
#[storage(write)]pub fn store<T>(key: b256, value: T) {
Expand Down Expand Up @@ -63,10 +64,7 @@ use ::result::Result;

while size_left > 32 {
// Read 4 words (32 bytes) at a time
let current_pointer = stack_ptr();
asm() {
cfei i32;
};
let current_pointer = alloca::<i32>();
__state_load_quad(local_key, current_pointer);

// Move by 32 bytes
Expand All @@ -78,10 +76,7 @@ use ::result::Result;
}

// Read the leftover bytes using a single `srwq`
let current_pointer = stack_ptr();
asm() {
cfei i32;
}
let current_pointer = alloca::<i32>();
__state_load_quad(local_key, current_pointer);

// Return the final result as type T
Expand Down