forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce code relocation to avoid the need for far jumps. (FuelLabs#…
…3371) The existing solution for far jumps which can't fit in an immediate is to convert them to dynamic jumps, storing the destination address in the data section. This change helps avoid far jumps altogether by moving large blocks to beyond the limit to keep immediate mode control flow.
- Loading branch information
Showing
11 changed files
with
328 additions
and
71 deletions.
There are no files selected for viewing
277 changes: 245 additions & 32 deletions
277
sway-core/src/asm_generation/allocated_abstract_instruction_set.rs
Large diffs are not rendered by default.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
.../should_pass/language/far_jumps/Forc.lock → ...s/language/far_jumps/many_blobs/Forc.lock
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[[package]] | ||
name = 'far_jumps' | ||
name = 'many_blobs' | ||
source = 'member' |
8 changes: 8 additions & 0 deletions
8
test/src/e2e_vm_tests/test_programs/should_pass/language/far_jumps/many_blobs/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,8 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "many_blobs" | ||
implicit-std = false | ||
|
||
[dependencies] |
49 changes: 49 additions & 0 deletions
49
test/src/e2e_vm_tests/test_programs/should_pass/language/far_jumps/many_blobs/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,49 @@ | ||
script; | ||
|
||
// Having > 256K NOPs from the BLOBs will force some relocation to keep control flow under the 1MB | ||
// boundary. But only one of these need to be moved to get it back under, and it should be the | ||
// largest one. | ||
|
||
fn main() -> u64 { | ||
asm() { | ||
blob i50000; | ||
} | ||
if t() { | ||
if f() { | ||
asm() { | ||
blob i51000; | ||
} | ||
111 | ||
} else { | ||
// This one. | ||
asm() { | ||
blob i60000; | ||
} | ||
222 | ||
} | ||
} else { | ||
if f() { | ||
asm() { | ||
blob i52000; | ||
} | ||
333 | ||
} else { | ||
asm() { | ||
blob i53000; | ||
} | ||
444 | ||
} | ||
} | ||
} | ||
|
||
fn f() -> bool { | ||
asm() { | ||
zero: bool | ||
} | ||
} | ||
|
||
fn t() -> bool { | ||
asm() { | ||
one: bool | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
test/src/e2e_vm_tests/test_programs/should_pass/language/far_jumps/many_blobs/test.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,3 @@ | ||
category = "run" | ||
expected_result = { action = "return", value = 222 } | ||
validate_abi = false |
3 changes: 3 additions & 0 deletions
3
test/src/e2e_vm_tests/test_programs/should_pass/language/far_jumps/single_blob/Forc.lock
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,3 @@ | ||
[[package]] | ||
name = 'single_blob' | ||
source = 'member' |
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 |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "far_jumps" | ||
name = "single_blob" | ||
implicit-std = false |
File renamed without changes.
File renamed without changes.
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