-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[RISCV] Add SpacemiT XSMTVDot (SpacemiT Vector Dot Product) extension. #151706
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
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
74170fa
[RISCV] Add SpacemiT XSMTVDot (SpacemiT Vector Dot Product) extension.
link-xyq 93f28dd
[RISCV] Add xsmtvdot extension support for SPACEMIT_X60 target.
link-xyq f483229
[Fix] code review.
link-xyq efeadf7
[Fix] code review.
link-xyq 0c7a92a
[Fix] code review.
link-xyq b9e6ec8
[Refactor] Replace explicit .Value with type-safe SMTVEncoding2 param.
link-xyq 3d857ca
[RISCV] Enforce even-numbered vd for xsmtvdot.
link-xyq ff62a78
[Fix] code review.
link-xyq 11a2cd6
[Fix] code review.
link-xyq a911e84
[Fix] code review.
link-xyq 0700683
[Fix] Avoid change the register pressure.
link-xyq 89f0e88
[Fix] Avoid changing the VL operand on these instructions.
link-xyq 3e91875
Update llvm/lib/Target/RISCV/RISCVRegisterInfo.td
link-xyq 0578b4d
[Fix] code review.
link-xyq a6ef5c1
[Fix] code review.
link-xyq a436834
[Fix] code review.
link-xyq 2f82a7e
[Fix] code review.
link-xyq 89152e5
[Fix] code review.
link-xyq 4d6a898
[Fix] code review.
link-xyq 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,139 @@ | ||
| //===-- RISCVInstrInfoXSpacemiT.td -------------------------*- tablegen -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This file describes the vendor extensions defined by SpacemiT. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Operand definitions. | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| class SMTVDotOpcode<bits<7> val> { | ||
| bits<7> Value = val; | ||
| } | ||
|
|
||
| class SMTVEncoding2<bits<2> val> { | ||
| bits<2> Value = val; | ||
| } | ||
|
|
||
| def OPMMA : SMTVDotOpcode<0b1110001>; | ||
| def OPMMA_SLIDE : SMTVDotOpcode<0b1110011>; | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Vector Dot-Product Sign Encoding | ||
| // Defines the signed/unsigned mixing modes for vector dot-product operations. | ||
| // Encoding format: [1:0] bits | ||
| // 00: UU (Unsigned x Unsigned) | ||
| // 01: US (Unsigned x Signed) | ||
| // 10: SU (Signed x Unsigned) | ||
| // 11: SS (Signed x Signed) | ||
| //===----------------------------------------------------------------------===// | ||
| def SMT_VDot_UU : SMTVEncoding2<0b00>; | ||
| def SMT_VDot_US : SMTVEncoding2<0b01>; | ||
| def SMT_VDot_SU : SMTVEncoding2<0b10>; | ||
| def SMT_VDot_SS : SMTVEncoding2<0b11>; | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Vector Dot-Product Sliding Window Modes | ||
| // Encoding format: [1:0] bits | ||
| // 00: Slide1 (1-element sliding stride) | ||
| // 01: Slide2 (2-element sliding stride) | ||
| // 10: Slide3 (3-element sliding stride) | ||
| // 11: Reserved | ||
| // | ||
| // Used in sliding-window dot-product operations: | ||
| // vd = vs1 • vs2.slide{1|2|3} // • = dot product | ||
| //===----------------------------------------------------------------------===// | ||
| def SMT_VDot_Slide1 : SMTVEncoding2<0b00>; | ||
| def SMT_VDot_Slide2 : SMTVEncoding2<0b01>; | ||
| def SMT_VDot_Slide3 : SMTVEncoding2<0b10>; | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Instruction formats | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in { | ||
| // Base vector dot product (no slide) format. | ||
| class RVInstSMTVDot<SMTVEncoding2 sign, string opcodestr, string argstr> | ||
| : RVInst<(outs VRM2:$vd), (ins VR:$vs1, VR:$vs2), opcodestr, argstr, [], InstFormatR> { | ||
| bits<5> vd; | ||
| bits<5> vs1; | ||
| bits<5> vs2; | ||
|
|
||
| let Inst{31-25} = OPMMA.Value; | ||
| let Inst{24-20} = vs2; | ||
| let Inst{19-15} = vs1; | ||
| let Inst{14} = 0b0; | ||
| let Inst{13-12} = sign.Value; | ||
| let Inst{11-8} = vd{4-1}; | ||
| let Inst{7} = 0b0; | ||
| let Inst{6-0} = OPC_CUSTOM_1.Value; | ||
| } | ||
|
|
||
| // Sliding-window vector dot product format. | ||
| class RVInstSMTVDotSlide<SMTVEncoding2 funct2, SMTVEncoding2 sign, string opcodestr, string argstr> | ||
| : RVInst<(outs VRM2:$vd), (ins VRM2:$vs1, VR:$vs2), opcodestr, argstr, [], InstFormatR> { | ||
| bits<5> vd; | ||
| bits<5> vs1; | ||
| bits<5> vs2; | ||
|
|
||
| let Inst{31-25} = OPMMA_SLIDE.Value; | ||
| let Inst{24-20} = vs2; | ||
| let Inst{19-16} = vs1{4-1}; | ||
| let Inst{15-14} = funct2.Value; | ||
| let Inst{13-12} = sign.Value; | ||
| let Inst{11-8} = vd{4-1}; | ||
| let Inst{7} = 0b0; | ||
| let Inst{6-0} = OPC_CUSTOM_1.Value; | ||
| } | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Instructions | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| let DecoderNamespace = "XSMT" in { | ||
|
|
||
| let Predicates = [HasVendorXSMTVDot], ElementsDependOn = EltDepsVL in { | ||
| // Base vector dot product (no slide) instructions | ||
| // NOTE: Destination registers (vd) MUST be even-numbered (v0, v2, ..., v30) | ||
| // due to hardware alignment constraints. Using odd registers may cause undefined behavior. | ||
| def VMADOT : RVInstSMTVDot<SMT_VDot_SS, "smt.vmadot", "$vd, $vs1, $vs2">; | ||
| def VMADOTU : RVInstSMTVDot<SMT_VDot_UU, "smt.vmadotu", "$vd, $vs1, $vs2">; | ||
| def VMADOTSU : RVInstSMTVDot<SMT_VDot_SU, "smt.vmadotsu", "$vd, $vs1, $vs2">; | ||
| def VMADOTUS : RVInstSMTVDot<SMT_VDot_US, "smt.vmadotus", "$vd, $vs1, $vs2">; | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Sliding-window Vector Dot Product Instructions | ||
| // | ||
| // The numeric suffix (1, 2, 3) specifies the stride of the sliding window: | ||
| // 1: Window slides by 1 element per operation | ||
| // 2: Window slides by 2 elements per operation | ||
| // 3: Window slides by 3 elements per operation | ||
| // | ||
| // These instructions compute dot products with overlapping operand windows | ||
| // where the window position increments by <N> elements between computations. | ||
| //===----------------------------------------------------------------------===// | ||
| // NOTE: Destination registers (vd) and first source register (vs1) MUST be | ||
| // even-numbered (v0, v2, ..., v30) due to hardware alignment constraints. | ||
| // Using odd registers may cause undefined behavior. | ||
| def VMADOT1 : RVInstSMTVDotSlide<SMT_VDot_Slide1, SMT_VDot_SS, "smt.vmadot1", "$vd, $vs1, $vs2">; | ||
| def VMADOT1U : RVInstSMTVDotSlide<SMT_VDot_Slide1, SMT_VDot_UU, "smt.vmadot1u", "$vd, $vs1, $vs2">; | ||
| def VMADOT1SU : RVInstSMTVDotSlide<SMT_VDot_Slide1, SMT_VDot_SU, "smt.vmadot1su", "$vd, $vs1, $vs2">; | ||
| def VMADOT1US : RVInstSMTVDotSlide<SMT_VDot_Slide1, SMT_VDot_US, "smt.vmadot1us", "$vd, $vs1, $vs2">; | ||
| def VMADOT2 : RVInstSMTVDotSlide<SMT_VDot_Slide2, SMT_VDot_SS, "smt.vmadot2", "$vd, $vs1, $vs2">; | ||
| def VMADOT2U : RVInstSMTVDotSlide<SMT_VDot_Slide2, SMT_VDot_UU, "smt.vmadot2u", "$vd, $vs1, $vs2">; | ||
| def VMADOT2SU : RVInstSMTVDotSlide<SMT_VDot_Slide2, SMT_VDot_SU, "smt.vmadot2su", "$vd, $vs1, $vs2">; | ||
| def VMADOT2US : RVInstSMTVDotSlide<SMT_VDot_Slide2, SMT_VDot_US, "smt.vmadot2us", "$vd, $vs1, $vs2">; | ||
| def VMADOT3 : RVInstSMTVDotSlide<SMT_VDot_Slide3, SMT_VDot_SS, "smt.vmadot3", "$vd, $vs1, $vs2">; | ||
| def VMADOT3U : RVInstSMTVDotSlide<SMT_VDot_Slide3, SMT_VDot_UU, "smt.vmadot3u", "$vd, $vs1, $vs2">; | ||
| def VMADOT3SU : RVInstSMTVDotSlide<SMT_VDot_Slide3, SMT_VDot_SU, "smt.vmadot3su", "$vd, $vs1, $vs2">; | ||
| def VMADOT3US : RVInstSMTVDotSlide<SMT_VDot_Slide3, SMT_VDot_US, "smt.vmadot3us", "$vd, $vs1, $vs2">; | ||
| } | ||
| } | ||
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,52 @@ | ||
| # RUN: not llvm-mc -triple riscv32 -mattr=+xsmtvdot < %s 2>&1 \ | ||
| # RUN: | FileCheck %s | ||
| # RUN: not llvm-mc -triple riscv64 -mattr=+xsmtvdot < %s 2>&1 \ | ||
| # RUN: | FileCheck %s | ||
|
|
||
| # NoSlide | ||
| smt.vmadot v1, v2, v2 # CHECK: :[[@LINE]]:14: error: invalid operand for instruction | ||
| smt.vmadotu v1, v2, v2 # CHECK: :[[@LINE]]:14: error: invalid operand for instruction | ||
| smt.vmadotsu v1, v2, v2 # CHECK: :[[@LINE]]:14: error: invalid operand for instruction | ||
| smt.vmadotus v1, v2, v2 # CHECK: :[[@LINE]]:14: error: invalid operand for instruction | ||
|
|
||
| # Slide = 1 | ||
| smt.vmadot1 v1, v2, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
| smt.vmadot1u v1, v2, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
| smt.vmadot1su v1, v2, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
| smt.vmadot1us v1, v2, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
| smt.vmadot1 v2, v1, v2 # CHECK: :[[@LINE]]:19: error: invalid operand for instruction | ||
| smt.vmadot1u v2, v1, v2 # CHECK: :[[@LINE]]:19: error: invalid operand for instruction | ||
| smt.vmadot1su v2, v1, v2 # CHECK: :[[@LINE]]:19: error: invalid operand for instruction | ||
| smt.vmadot1us v2, v1, v2 # CHECK: :[[@LINE]]:19: error: invalid operand for instruction | ||
| smt.vmadot1 v1, v3, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
| smt.vmadot1u v1, v3, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
| smt.vmadot1su v1, v3, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
| smt.vmadot1us v1, v3, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
|
|
||
| # Slide = 2 | ||
| smt.vmadot2 v1, v2, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
| smt.vmadot2u v1, v2, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
| smt.vmadot2su v1, v2, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
| smt.vmadot2us v1, v2, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
| smt.vmadot2 v2, v1, v2 # CHECK: :[[@LINE]]:19: error: invalid operand for instruction | ||
| smt.vmadot2u v2, v1, v2 # CHECK: :[[@LINE]]:19: error: invalid operand for instruction | ||
| smt.vmadot2su v2, v1, v2 # CHECK: :[[@LINE]]:19: error: invalid operand for instruction | ||
| smt.vmadot2us v2, v1, v2 # CHECK: :[[@LINE]]:19: error: invalid operand for instruction | ||
| smt.vmadot2 v1, v3, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
| smt.vmadot2u v1, v3, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
| smt.vmadot2su v1, v3, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
| smt.vmadot2us v1, v3, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
|
|
||
| # Slide = 3 | ||
| smt.vmadot3 v1, v2, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
| smt.vmadot3u v1, v2, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
| smt.vmadot3su v1, v2, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
| smt.vmadot3us v1, v2, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
| smt.vmadot3 v2, v1, v2 # CHECK: :[[@LINE]]:19: error: invalid operand for instruction | ||
| smt.vmadot3u v2, v1, v2 # CHECK: :[[@LINE]]:19: error: invalid operand for instruction | ||
| smt.vmadot3su v2, v1, v2 # CHECK: :[[@LINE]]:19: error: invalid operand for instruction | ||
| smt.vmadot3us v2, v1, v2 # CHECK: :[[@LINE]]:19: error: invalid operand for instruction | ||
| smt.vmadot3 v1, v3, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
| smt.vmadot3u v1, v3, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
| smt.vmadot3su v1, v3, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
| smt.vmadot3us v1, v3, v2 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has been addressed in #154457. |
||
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.
Please fix these files without newlines.
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.
This has been addressed in #154457. PTAL: #154457