-
Notifications
You must be signed in to change notification settings - Fork 1.7k
pulley: Add some macro-instructions related to bounds-checks #9943
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
Merged
alexcrichton
merged 2 commits into
bytecodealliance:main
from
alexcrichton:pulley-bounds-check-macro-op
Jan 8, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,110 @@ | ||
| ;;! target = "pulley32" | ||
| ;;! test = "compile" | ||
|
|
||
| (module | ||
| (memory 1) | ||
|
|
||
| (func $load8 (param i32) (result i32) | ||
| (i32.load8_u (local.get 0))) | ||
|
|
||
| (func $load16 (param i32) (result i32) | ||
| (i32.load16_u (local.get 0))) | ||
|
|
||
| (func $load32 (param i32) (result i32) | ||
| (i32.load (local.get 0))) | ||
|
|
||
| (func $load64 (param i32) (result i64) | ||
| (i64.load (local.get 0))) | ||
|
|
||
| (func $load8_offset (param i32) (result i32) | ||
| (i32.load8_u offset=32 (local.get 0))) | ||
|
|
||
| (func $load16_offset (param i32) (result i32) | ||
| (i32.load16_u offset=32 (local.get 0))) | ||
|
|
||
| (func $load32_offset (param i32) (result i32) | ||
| (i32.load offset=32 (local.get 0))) | ||
|
|
||
| (func $load64_offset (param i32) (result i64) | ||
| (i64.load offset=32 (local.get 0))) | ||
| ) | ||
| ;; wasm[0]::function[0]::load8: | ||
| ;; push_frame | ||
| ;; xload32le_offset8 x6, x0, 52 | ||
| ;; br_if_xulteq32 x6, x2, 0x14 // target = 0x19 | ||
| ;; c: xload32le_offset8 x7, x0, 48 | ||
| ;; xadd32 x7, x7, x2 | ||
| ;; xload8_u32_offset8 x0, x7, 0 | ||
| ;; pop_frame | ||
| ;; ret | ||
| ;; 19: trap | ||
| ;; | ||
| ;; wasm[0]::function[1]::load16: | ||
| ;; push_frame | ||
| ;; xload32le_offset8 x6, x0, 52 | ||
| ;; xbc32_bound32_trap x2, x6, 2 | ||
| ;; xload32le_offset8 x7, x0, 48 | ||
| ;; xadd32 x7, x7, x2 | ||
| ;; xload16le_u32_offset8 x0, x7, 0 | ||
| ;; pop_frame | ||
| ;; ret | ||
| ;; | ||
| ;; wasm[0]::function[2]::load32: | ||
| ;; push_frame | ||
| ;; xload32le_offset8 x6, x0, 52 | ||
| ;; xbc32_bound32_trap x2, x6, 4 | ||
| ;; xload32le_offset8 x7, x0, 48 | ||
| ;; xadd32 x7, x7, x2 | ||
| ;; xload32le_offset8 x0, x7, 0 | ||
| ;; pop_frame | ||
| ;; ret | ||
| ;; | ||
| ;; wasm[0]::function[3]::load64: | ||
| ;; push_frame | ||
| ;; xload32le_offset8 x6, x0, 52 | ||
| ;; xbc32_bound32_trap x2, x6, 8 | ||
| ;; xload32le_offset8 x7, x0, 48 | ||
| ;; xadd32 x7, x7, x2 | ||
| ;; xload64le_offset8 x0, x7, 0 | ||
| ;; pop_frame | ||
| ;; ret | ||
| ;; | ||
| ;; wasm[0]::function[4]::load8_offset: | ||
| ;; push_frame | ||
| ;; xload32le_offset8 x6, x0, 52 | ||
| ;; xbc32_bound32_trap x2, x6, 33 | ||
| ;; xload32le_offset8 x7, x0, 48 | ||
| ;; xadd32 x7, x7, x2 | ||
| ;; xload8_u32_offset8 x0, x7, 32 | ||
| ;; pop_frame | ||
| ;; ret | ||
| ;; | ||
| ;; wasm[0]::function[5]::load16_offset: | ||
| ;; push_frame | ||
| ;; xload32le_offset8 x6, x0, 52 | ||
| ;; xbc32_bound32_trap x2, x6, 34 | ||
| ;; xload32le_offset8 x7, x0, 48 | ||
| ;; xadd32 x7, x7, x2 | ||
| ;; xload16le_u32_offset8 x0, x7, 32 | ||
| ;; pop_frame | ||
| ;; ret | ||
| ;; | ||
| ;; wasm[0]::function[6]::load32_offset: | ||
| ;; push_frame | ||
| ;; xload32le_offset8 x6, x0, 52 | ||
| ;; xbc32_bound32_trap x2, x6, 36 | ||
| ;; xload32le_offset8 x7, x0, 48 | ||
| ;; xadd32 x7, x7, x2 | ||
| ;; xload32le_offset8 x0, x7, 32 | ||
| ;; pop_frame | ||
| ;; ret | ||
| ;; | ||
| ;; wasm[0]::function[7]::load64_offset: | ||
| ;; push_frame | ||
| ;; xload32le_offset8 x6, x0, 52 | ||
| ;; xbc32_bound32_trap x2, x6, 40 | ||
| ;; xload32le_offset8 x7, x0, 48 | ||
| ;; xadd32 x7, x7, x2 | ||
| ;; xload64le_offset8 x0, x7, 32 | ||
| ;; pop_frame | ||
| ;; ret | ||
This file contains hidden or 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,118 @@ | ||
| ;;! target = "pulley64" | ||
| ;;! test = "compile" | ||
|
|
||
| (module | ||
| (memory 1) | ||
|
|
||
| (func $load8 (param i32) (result i32) | ||
| (i32.load8_u (local.get 0))) | ||
|
|
||
| (func $load16 (param i32) (result i32) | ||
| (i32.load16_u (local.get 0))) | ||
|
|
||
| (func $load32 (param i32) (result i32) | ||
| (i32.load (local.get 0))) | ||
|
|
||
| (func $load64 (param i32) (result i64) | ||
| (i64.load (local.get 0))) | ||
|
|
||
| (func $load8_offset (param i32) (result i32) | ||
| (i32.load8_u offset=32 (local.get 0))) | ||
|
|
||
| (func $load16_offset (param i32) (result i32) | ||
| (i32.load16_u offset=32 (local.get 0))) | ||
|
|
||
| (func $load32_offset (param i32) (result i32) | ||
| (i32.load offset=32 (local.get 0))) | ||
|
|
||
| (func $load64_offset (param i32) (result i64) | ||
| (i64.load offset=32 (local.get 0))) | ||
| ) | ||
| ;; wasm[0]::function[0]::load8: | ||
| ;; push_frame | ||
| ;; xload64le_offset8 x8, x0, 104 | ||
| ;; zext32 x7, x2 | ||
| ;; br_if_xulteq64 x8, x7, 0x14 // target = 0x1c | ||
| ;; f: xload64le_offset8 x8, x0, 96 | ||
| ;; xadd64 x8, x8, x7 | ||
| ;; xload8_u32_offset8 x0, x8, 0 | ||
| ;; pop_frame | ||
| ;; ret | ||
| ;; 1c: trap | ||
| ;; | ||
| ;; wasm[0]::function[1]::load16: | ||
| ;; push_frame | ||
| ;; xload64le_offset8 x8, x0, 104 | ||
| ;; zext32 x7, x2 | ||
| ;; xbc32_bound64_trap x2, x8, 2 | ||
| ;; xload64le_offset8 x8, x0, 96 | ||
| ;; xadd64 x8, x8, x7 | ||
| ;; xload16le_u32_offset8 x0, x8, 0 | ||
| ;; pop_frame | ||
| ;; ret | ||
| ;; | ||
| ;; wasm[0]::function[2]::load32: | ||
| ;; push_frame | ||
| ;; xload64le_offset8 x8, x0, 104 | ||
| ;; zext32 x7, x2 | ||
| ;; xbc32_bound64_trap x2, x8, 4 | ||
| ;; xload64le_offset8 x8, x0, 96 | ||
| ;; xadd64 x8, x8, x7 | ||
| ;; xload32le_offset8 x0, x8, 0 | ||
| ;; pop_frame | ||
| ;; ret | ||
| ;; | ||
| ;; wasm[0]::function[3]::load64: | ||
| ;; push_frame | ||
| ;; xload64le_offset8 x8, x0, 104 | ||
| ;; zext32 x7, x2 | ||
| ;; xbc32_bound64_trap x2, x8, 8 | ||
| ;; xload64le_offset8 x8, x0, 96 | ||
| ;; xadd64 x8, x8, x7 | ||
| ;; xload64le_offset8 x0, x8, 0 | ||
| ;; pop_frame | ||
| ;; ret | ||
| ;; | ||
| ;; wasm[0]::function[4]::load8_offset: | ||
| ;; push_frame | ||
| ;; xload64le_offset8 x8, x0, 104 | ||
| ;; zext32 x7, x2 | ||
| ;; xbc32_bound64_trap x2, x8, 33 | ||
| ;; xload64le_offset8 x8, x0, 96 | ||
| ;; xadd64 x8, x8, x7 | ||
| ;; xload8_u32_offset8 x0, x8, 32 | ||
| ;; pop_frame | ||
| ;; ret | ||
| ;; | ||
| ;; wasm[0]::function[5]::load16_offset: | ||
| ;; push_frame | ||
| ;; xload64le_offset8 x8, x0, 104 | ||
| ;; zext32 x7, x2 | ||
| ;; xbc32_bound64_trap x2, x8, 34 | ||
| ;; xload64le_offset8 x8, x0, 96 | ||
| ;; xadd64 x8, x8, x7 | ||
| ;; xload16le_u32_offset8 x0, x8, 32 | ||
| ;; pop_frame | ||
| ;; ret | ||
| ;; | ||
| ;; wasm[0]::function[6]::load32_offset: | ||
| ;; push_frame | ||
| ;; xload64le_offset8 x8, x0, 104 | ||
| ;; zext32 x7, x2 | ||
| ;; xbc32_bound64_trap x2, x8, 36 | ||
| ;; xload64le_offset8 x8, x0, 96 | ||
| ;; xadd64 x8, x8, x7 | ||
| ;; xload32le_offset8 x0, x8, 32 | ||
| ;; pop_frame | ||
| ;; ret | ||
| ;; | ||
| ;; wasm[0]::function[7]::load64_offset: | ||
| ;; push_frame | ||
| ;; xload64le_offset8 x8, x0, 104 | ||
| ;; zext32 x7, x2 | ||
| ;; xbc32_bound64_trap x2, x8, 40 | ||
| ;; xload64le_offset8 x8, x0, 96 | ||
| ;; xadd64 x8, x8, x7 | ||
| ;; xload64le_offset8 x0, x8, 32 | ||
| ;; pop_frame | ||
| ;; ret |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want this one to use the new
xbcmacro-op?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No we probably do but I wanted to add this here for complete-ness to show that it's not currently using the new op. One-byte loads/stores are generated a bit differently with bounds checks and use a
>=condition instead of>+ arithmetic to test whether something is out of bounds. That made it so it doesn't fall into the patterns I added and would need a specific opcode just for the one-byte access. I figured it's probably fine to leave that off for now and add in the future if necessary