-
Notifications
You must be signed in to change notification settings - Fork 1.7k
cranelift(aarch64): lower the i8 relaxed dot product to NEON SDOT #13640
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 1 commit into
bytecodealliance:main
from
darmie:aarch64-sdot-relaxed-dot
Jun 15, 2026
Merged
Changes from all commits
Commits
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
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,35 @@ | ||
| test compile precise-output | ||
| set unwind_info=false | ||
| target aarch64 has_dotprod | ||
|
|
||
| ;; Tests the aarch64 `sdot` lowering: the i8 dot-product tree contracts to one `sdot`. | ||
| function %sdot_i8x16(i8x16, i8x16, i32x4) -> i32x4 { | ||
| block0(v0: i8x16, v1: i8x16, v2: i32x4): | ||
| v3 = swiden_low v0 | ||
| v4 = swiden_low v1 | ||
| v5 = imul v3, v4 | ||
| v6 = swiden_high v0 | ||
| v7 = swiden_high v1 | ||
| v8 = imul v6, v7 | ||
| v9 = iadd_pairwise v5, v8 | ||
| v10 = swiden_low v9 | ||
| v11 = swiden_high v9 | ||
| v12 = iadd_pairwise v10, v11 | ||
| v13 = iadd v12, v2 | ||
| return v13 | ||
| } | ||
|
|
||
| ; VCode: | ||
| ; block0: | ||
| ; mov v5.16b, v0.16b | ||
| ; mov v0.16b, v2.16b | ||
| ; sdot v0.4s, v0.4s, v5.4s, v1.4s | ||
| ; ret | ||
| ; | ||
| ; Disassembled: | ||
| ; block0: ; offset 0x0 | ||
| ; mov v5.16b, v0.16b | ||
| ; mov v0.16b, v2.16b | ||
| ; sdot v0.4s, v5.16b, v1.16b | ||
| ; 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,27 @@ | ||
| test interpret | ||
| test run | ||
| target aarch64 | ||
| target aarch64 has_dotprod | ||
| target x86_64 has_sse3 has_ssse3 has_sse41 | ||
| target s390x | ||
|
|
||
| ;; Tests the aarch64 `sdot` lowering of the i8 4-way dot product. | ||
| function %sdot_i8x16(i8x16, i8x16, i32x4) -> i32x4 { | ||
| block0(v0: i8x16, v1: i8x16, v2: i32x4): | ||
| v3 = swiden_low v0 | ||
| v4 = swiden_low v1 | ||
| v5 = imul v3, v4 | ||
| v6 = swiden_high v0 | ||
| v7 = swiden_high v1 | ||
| v8 = imul v6, v7 | ||
| v9 = iadd_pairwise v5, v8 | ||
| v10 = swiden_low v9 | ||
| v11 = swiden_high v9 | ||
| v12 = iadd_pairwise v10, v11 | ||
| v13 = iadd v12, v2 | ||
| return v13 | ||
| } | ||
| ; each i32x4 lane i = c[i] + sum_{j=4i..4i+3} a[j]*b[j] | ||
| ; run: %sdot_i8x16([1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16], [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1], [0 0 0 0]) == [10 26 42 58] | ||
| ; run: %sdot_i8x16([-1 -2 -3 -4 1 2 3 4 5 5 5 5 -5 -5 -5 -5], [2 2 2 2 3 3 3 3 1 1 1 1 4 4 4 4], [100 200 300 400]) == [80 230 320 320] | ||
| ; run: %sdot_i8x16([127 127 127 127 -128 -128 -128 -128 100 -100 100 -100 0 0 0 0], [127 127 127 127 127 127 127 127 63 63 63 63 1 2 3 4], [0 0 0 0]) == [64516 -65024 0 0] |
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,22 @@ | ||
| ;;! target = "aarch64" | ||
| ;;! test = "compile" | ||
| ;;! flags = "-C cranelift-has_dotprod=true" | ||
|
|
||
| ;; `i32x4.relaxed_dot_i8x16_i7x16_add_s` with FEAT_DotProd: the dot-product tree | ||
| ;; lowers to a single `sdot`. | ||
| (module | ||
| (func (param v128 v128 v128) (result v128) | ||
| local.get 0 | ||
| local.get 1 | ||
| local.get 2 | ||
| i32x4.relaxed_dot_i8x16_i7x16_add_s | ||
| ) | ||
| ) | ||
| ;; wasm[0]::function[0]: | ||
| ;; stp x29, x30, [sp, #-0x10]! | ||
| ;; mov x29, sp | ||
| ;; mov v6.16b, v0.16b | ||
| ;; mov v0.16b, v2.16b | ||
| ;; sdot v0.4s, v6.16b, v1.16b | ||
| ;; ldp x29, x30, [sp], #0x10 | ||
| ;; ret |
Oops, something went wrong.
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.
Could this include a
test interpretas well to verify it runs against the interpreter?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.
Done! It passes.