-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
101 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
test/src/e2e_vm_tests/test_programs/b512_struct_alignment/Forc.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[project] | ||
author = "Alexander Hansen" | ||
license = "MIT" | ||
name = "b512_panic_test" | ||
entry = "main.sw" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../stdlib" } | ||
|
41 changes: 41 additions & 0 deletions
41
test/src/e2e_vm_tests/test_programs/b512_struct_alignment/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
script; | ||
|
||
// Stores two b256s in contiguous memory. | ||
// Guaranteed to be contiguous for things like ECR. | ||
struct B512 { | ||
hi: b256, | ||
lo: b256, | ||
} | ||
|
||
// temp | ||
pub fn build_from_b256s(hi: b256, lo: b256) -> B512 { | ||
let hi = asm(r1: hi, rhi) { | ||
move rhi sp; // move stack pointer to rhi | ||
cfei i32; // extend call frame by 32 bytes to allocate more memory. now $rhi is pointing to blank, uninitialized (but allocated) memory | ||
// addi r5 zero i32; | ||
mcpi rhi r1 i32; | ||
rhi: b256 | ||
}; | ||
|
||
let lo = asm(r1: lo, rlo) { | ||
move rlo sp; | ||
cfei i32; | ||
// now $rlo is pointing to blank memory that we can use | ||
mcpi rlo r1 i32; | ||
rlo: b256 | ||
}; | ||
|
||
B512 { | ||
hi: hi, | ||
lo: lo | ||
} | ||
} | ||
|
||
fn main() -> bool { | ||
let hi_bits: b256 = 0x7777777777777777777777777777777777777777777777777777777777777777; | ||
let lo_bits: b256 = 0x5555555555555555555555555555555555555555555555555555555555555555; | ||
|
||
let b: B512 = build_from_b256s(hi_bits, lo_bits); | ||
|
||
b.lo == lo_bits && b.hi == hi_bits | ||
} |