-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[RISCV][MC] Support Base P non-GPR pair instructions #137927
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 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a39ef92
[RISCV][MC] Support Base P non-GPR pair instructions
realqhc 43d5b23
remove unused patterns, revert unnecessary change in rv64p-valid.s
realqhc 82921ce
rename RVPUnaryImm9 to RVPUnaryImm10 and fix simm10 encoding, fix REV…
realqhc 0d5b680
Change simm10 to simm10_unsigned to handle extended range for PLUI
realqhc fa5dd24
simplify RVPUnary#
realqhc 7cd6711
Add back SImm10 for non-u load instructions. Add a test showing plui.…
realqhc 94e492d
fix test to correctly handle difference between asm and obj output
realqhc 1762fa3
Merge branch 'main' into p-no-gpr-pair
realqhc 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,163 @@ | ||
| //===-- RISCVInstrInfoP.td - RISC-V 'P' instructions -------*- 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 RISC-V instructions from the standard 'Base P' | ||
| // Packed SIMD instruction set extension. | ||
| // | ||
| // This version is still experimental as the 'P' extension hasn't been | ||
| // ratified yet. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Operand and SDNode transformation definitions. | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def simm10 : RISCVSImmLeafOp<10>; | ||
|
|
||
| // A 10-bit signed immediate allowing range [-512, 1023] | ||
| // but will decode to [-512, 511]. | ||
| def simm10_unsigned : RISCVOp { | ||
| let ParserMatchClass = SImmAsmOperand<10, "Unsigned">; | ||
| let EncoderMethod = "getImmOpValue"; | ||
| let DecoderMethod = "decodeSImmOperand<10>"; | ||
| let OperandType = "OPERAND_SIMM10_UNSIGNED"; | ||
| let MCOperandPredicate = [{ | ||
| int64_t Imm; | ||
| if (!MCOp.evaluateAsConstantImm(Imm)) | ||
| return false; | ||
| return isInt<10>(Imm) || isUInt<10>(Imm); | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Instruction class templates | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in | ||
| class RVPUnaryImm10<bits<7> funct7, string opcodestr, | ||
| DAGOperand TyImm10 = simm10> | ||
| : RVInstIBase<0b010, OPC_OP_IMM_32, (outs GPR:$rd), (ins TyImm10:$imm10), | ||
| opcodestr, "$rd, $imm10"> { | ||
| bits<10> imm10; | ||
|
|
||
| let Inst{31-25} = funct7; | ||
| let Inst{24-16} = imm10{8-0}; | ||
| let Inst{15} = imm10{9}; | ||
| } | ||
|
|
||
| let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in | ||
| class RVPUnaryImm8<bits<8> funct8, string opcodestr> | ||
| : RVInstIBase<0b010, OPC_OP_IMM_32, (outs GPR:$rd), (ins uimm8:$uimm8), | ||
| opcodestr, "$rd, $uimm8"> { | ||
| bits<8> uimm8; | ||
|
|
||
| let Inst{31-24} = funct8; | ||
| let Inst{23-16} = uimm8; | ||
| let Inst{15} = 0b0; | ||
| } | ||
|
|
||
| let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in | ||
| class RVPUnary<bits<3> f, string opcodestr, dag operands, string argstr> | ||
| : RVInstIBase<0b010, OPC_OP_IMM_32, (outs GPR:$rd), operands, opcodestr, argstr> { | ||
| bits<5> imm; | ||
| bits<5> rs1; | ||
|
|
||
| let Inst{31} = 0b1; | ||
| let Inst{30-28} = f; | ||
| let Inst{27} = 0b0; | ||
| let Inst{19-15} = rs1; | ||
| } | ||
|
|
||
| class RVPUnaryImm5<bits<3> f, string opcodestr> | ||
| : RVPUnary<f, opcodestr, (ins GPR:$rs1, uimm5:$uimm5), "$rd, $rs1, $uimm5"> { | ||
| bits<5> uimm5; | ||
|
|
||
| let imm = uimm5; | ||
| let Inst{26-25} = 0b01; | ||
| let Inst{24-20} = uimm5; | ||
| } | ||
|
|
||
| class RVPUnaryImm4<bits<3> f, string opcodestr> | ||
| : RVPUnary<f, opcodestr, (ins GPR:$rs1, uimm4:$uimm4), "$rd, $rs1, $uimm4"> { | ||
| bits<4> uimm4; | ||
|
|
||
| let Inst{26-24} = 0b001; | ||
| let Inst{23-20} = uimm4; | ||
| } | ||
|
|
||
| class RVPUnaryImm3<bits<3> f, string opcodestr> | ||
| : RVPUnary<f, opcodestr, (ins GPR:$rs1, uimm3:$uimm3), "$rd, $rs1, $uimm3"> { | ||
| bits<3> uimm3; | ||
|
|
||
| let Inst{26-23} = 0b0001; | ||
| let Inst{22-20} = uimm3; | ||
| } | ||
|
|
||
| let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in | ||
| class RVPUnaryWUF<bits<2> w, bits<5> uf, string opcodestr> | ||
| : RVInstIBase<0b010, OPC_OP_IMM_32, (outs GPR:$rd), (ins GPR:$rs1), | ||
| opcodestr, "$rd, $rs1"> { | ||
| let Inst{31-27} = 0b11100; | ||
| let Inst{26-25} = w; | ||
| let Inst{24-20} = uf; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Instructions | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| let Predicates = [HasStdExtP] in { | ||
| def CLS : Unary_r<0b011000000011, 0b001, "cls">; | ||
| def ABS : Unary_r<0b011000000111, 0b001, "abs">; | ||
| } // Predicates = [HasStdExtP] | ||
| let Predicates = [HasStdExtP, IsRV32] in | ||
| def REV_RV32 : Unary_r<0b011010011111, 0b101, "rev">; | ||
|
|
||
| let Predicates = [HasStdExtP, IsRV64] in { | ||
| def REV16 : Unary_r<0b011010110000, 0b101, "rev16">; | ||
| def REV_RV64 : Unary_r<0b011010111111, 0b101, "rev">; | ||
|
|
||
| def CLSW : UnaryW_r<0b011000000011, 0b001, "clsw">; | ||
| def ABSW : UnaryW_r<0b011000000111, 0b001, "absw">; | ||
| } // Predicates = [HasStdExtP, IsRV64] | ||
|
|
||
| let Predicates = [HasStdExtP] in { | ||
| def PSLLI_B : RVPUnaryImm3<0b000, "pslli.b">; | ||
| def PSLLI_H : RVPUnaryImm4<0b000, "pslli.h">; | ||
| def PSSLAI_H : RVPUnaryImm4<0b101, "psslai.h">; | ||
| } // Predicates = [HasStdExtP] | ||
| let DecoderNamespace = "RV32Only", | ||
| Predicates = [HasStdExtP, IsRV32] in | ||
| def SSLAI : RVPUnaryImm5<0b101, "sslai">; | ||
| let Predicates = [HasStdExtP, IsRV64] in { | ||
| def PSLLI_W : RVPUnaryImm5<0b000, "pslli.w">; | ||
| def PSSLAI_W : RVPUnaryImm5<0b101, "psslai.w">; | ||
| } // Predicates = [HasStdExtP, IsRV64] | ||
|
|
||
| let Predicates = [HasStdExtP] in | ||
| def PLI_H : RVPUnaryImm10<0b1011000, "pli.h">; | ||
| let Predicates = [HasStdExtP, IsRV64] in | ||
| def PLI_W : RVPUnaryImm10<0b1011001, "pli.w">; | ||
| let Predicates = [HasStdExtP] in | ||
| def PLI_B : RVPUnaryImm8<0b10110100, "pli.b">; | ||
|
|
||
| let Predicates = [HasStdExtP] in { | ||
| def PSEXT_H_B : RVPUnaryWUF<0b00, 0b00100, "psext.h.b">; | ||
| def PSABS_H : RVPUnaryWUF<0b00, 0b00111, "psabs.h">; | ||
| def PSABS_B : RVPUnaryWUF<0b10, 0b00111, "psabs.b">; | ||
| } // Predicates = [HasStdExtP] | ||
| let Predicates = [HasStdExtP, IsRV64] in { | ||
| def PSEXT_W_B : RVPUnaryWUF<0b01, 0b00100, "psext.w.b">; | ||
| def PSEXT_W_H : RVPUnaryWUF<0b01, 0b00101, "psext.w.h">; | ||
| } // Predicates = [HasStdExtP, IsRV64] | ||
|
|
||
| let Predicates = [HasStdExtP] in | ||
| def PLUI_H : RVPUnaryImm10<0b1111000, "plui.h", simm10_unsigned>; | ||
| let Predicates = [HasStdExtP, IsRV64] in | ||
| def PLUI_W : RVPUnaryImm10<0b1111001, "plui.w", simm10_unsigned>; | ||
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,19 @@ | ||
| # RUN: not llvm-mc -triple=riscv32 --mattr=+experimental-p %s 2>&1 \ | ||
| # RUN: | FileCheck %s --check-prefixes=CHECK-ERROR | ||
|
|
||
| # Imm overflow | ||
| pli.h a0, 0x400 | ||
| # CHECK-ERROR: immediate must be an integer in the range [-512, 511] | ||
| plui.h a1, 0x400 | ||
| # CHECK-ERROR: immediate must be an integer in the range [-512, 1023] | ||
| pli.b a0, 0x200 | ||
| # CHECK-ERROR: immediate must be an integer in the range [0, 255] | ||
|
|
||
| pslli.b a6, a7, 100 | ||
| # CHECK-ERROR: immediate must be an integer in the range [0, 7] | ||
| pslli.h ra, sp, 100 | ||
| # CHECK-ERROR: immediate must be an integer in the range [0, 15] | ||
| psslai.h t0, t1, 100 | ||
| # CHECK-ERROR: immediate must be an integer in the range [0, 15] | ||
| sslai a4, a5, -1 | ||
| # CHECK-ERROR: immediate must be an integer in the range [0, 31] |
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 |
|---|---|---|
| @@ -1,36 +1,79 @@ | ||
| # RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-p -M no-aliases -show-encoding \ | ||
| # RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s | ||
| # RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-p < %s \ | ||
| # RUN: | llvm-objdump --mattr=+experimental-p -M no-aliases -d -r - \ | ||
| # RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s | ||
| # RUN: | llvm-objdump --mattr=+experimental-p -M no-aliases -d -r --no-print-imm-hex - \ | ||
| # RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ,CHECK-OBJ %s | ||
|
|
||
| # CHECK-ASM-AND-OBJ: sh1add a0, a1, a2 | ||
| # CHECK-ASM: encoding: [0x33,0xa5,0xc5,0x20] | ||
| sh1add a0, a1, a2 | ||
| # CHECK-ASM-AND-OBJ: clz a0, a1 | ||
| # CHECK-ASM: encoding: [0x13,0x95,0x05,0x60] | ||
| clz a0, a1 | ||
| # CHECK-ASM-AND-OBJ: cls a1, a2 | ||
| # CHECK-ASM: encoding: [0x93,0x15,0x36,0x60] | ||
| cls a1, a2 | ||
| # CHECK-ASM-AND-OBJ: sext.b a2, a3 | ||
| # CHECK-ASM: encoding: [0x13,0x96,0x46,0x60] | ||
| sext.b a2, a3 | ||
| # CHECK-ASM-AND-OBJ: sext.h t0, t1 | ||
| # CHECK-ASM: encoding: [0x93,0x12,0x53,0x60] | ||
| sext.h t0, t1 | ||
| # CHECK-ASM-AND-OBJ: abs a4, a5 | ||
| # CHECK-ASM: encoding: [0x13,0x97,0x77,0x60] | ||
| abs a4, a5 | ||
| # CHECK-ASM-AND-OBJ: rev8 s0, s1 | ||
| # CHECK-ASM: encoding: [0x13,0xd4,0x84,0x69] | ||
| rev8 s0, s1 | ||
| # CHECK-ASM-AND-OBJ: rev s2, s3 | ||
| # CHECK-ASM: encoding: [0x13,0xd9,0xf9,0x69] | ||
| rev s2, s3 | ||
| # CHECK-ASM-AND-OBJ: sh1add a0, a1, a2 | ||
| # CHECK-ASM: encoding: [0x33,0xa5,0xc5,0x20] | ||
| sh1add a0, a1, a2 | ||
| # CHECK-ASM-AND-OBJ: pack s0, s1, s2 | ||
| # CHECK-ASM: encoding: [0x33,0xc4,0x24,0x09] | ||
| pack s0, s1, s2 | ||
| # CHECK-ASM-AND-OBJ: min t0, t1, t2 | ||
| # CHECK-ASM: encoding: [0xb3,0x42,0x73,0x0a] | ||
| min t0, t1, t2 | ||
| # CHECK-ASM-AND-OBJ: minu t0, t1, t2 | ||
| # CHECK-ASM: encoding: [0xb3,0x52,0x73,0x0a] | ||
| minu t0, t1, t2 | ||
| # CHECK-ASM-AND-OBJ: minu ra, sp, gp | ||
| # CHECK-ASM: encoding: [0xb3,0x50,0x31,0x0a] | ||
| minu ra, sp, gp | ||
| # CHECK-ASM-AND-OBJ: max t3, t4, t5 | ||
| # CHECK-ASM: encoding: [0x33,0xee,0xee,0x0b] | ||
| max t3, t4, t5 | ||
| # CHECK-ASM-AND-OBJ: maxu a4, a5, a6 | ||
| # CHECK-ASM: encoding: [0x33,0xf7,0x07,0x0b] | ||
| maxu a4, a5, a6 | ||
| # CHECK-ASM-AND-OBJ: pack s0, s1, s2 | ||
| # CHECK-ASM: encoding: [0x33,0xc4,0x24,0x09] | ||
| pack s0, s1, s2 | ||
| # CHECK-ASM-AND-OBJ: rev8 s0, s1 | ||
| # CHECK-ASM: encoding: [0x13,0xd4,0x84,0x69] | ||
| rev8 s0, s1 | ||
| # CHECK-ASM-AND-OBJ: pslli.b a6, a7, 0 | ||
| # CHECK-ASM: encoding: [0x1b,0xa8,0x88,0x80] | ||
| pslli.b a6, a7, 0 | ||
| # CHECK-ASM-AND-OBJ: pslli.h ra, sp, 1 | ||
| # CHECK-ASM: encoding: [0x9b,0x20,0x11,0x81] | ||
| pslli.h ra, sp, 1 | ||
| # CHECK-ASM-AND-OBJ: psslai.h t0, t1, 2 | ||
| # CHECK-ASM: encoding: [0x9b,0x22,0x23,0xd1] | ||
| psslai.h t0, t1, 2 | ||
| # CHECK-ASM-AND-OBJ: sslai a4, a5, 3 | ||
| # CHECK-ASM: encoding: [0x1b,0xa7,0x37,0xd2] | ||
| sslai a4, a5, 3 | ||
| # CHECK-ASM-AND-OBJ: pli.h a5, 16 | ||
| # CHECK-ASM: encoding: [0x9b,0x27,0x10,0xb0] | ||
| pli.h a5, 16 | ||
| # CHECK-ASM-AND-OBJ: pli.b a6, 16 | ||
| # CHECK-ASM: encoding: [0x1b,0x28,0x10,0xb4] | ||
| pli.b a6, 16 | ||
| # CHECK-ASM-AND-OBJ: psext.h.b a7, a0 | ||
| # CHECK-ASM: encoding: [0x9b,0x28,0x45,0xe0] | ||
| psext.h.b a7, a0 | ||
| # CHECK-ASM-AND-OBJ: psabs.h a1, a2 | ||
| # CHECK-ASM: encoding: [0x9b,0x25,0x76,0xe0] | ||
| psabs.h a1, a2 | ||
| # CHECK-ASM-AND-OBJ: psabs.b t0, t1 | ||
| # CHECK-ASM: encoding: [0x9b,0x22,0x73,0xe4] | ||
| psabs.b t0, t1 | ||
| # CHECK-ASM-AND-OBJ: plui.h gp, 32 | ||
| # CHECK-ASM: encoding: [0x9b,0x21,0x20,0xf0] | ||
| plui.h gp, 32 | ||
| # CHECK-OBJ: plui.h gp, -412 | ||
| # CHECK-ASM: plui.h gp, 612 | ||
| # CHECK-ASM: encoding: [0x9b,0xa1,0x64,0xf0] | ||
| plui.h gp, 612 |
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,21 @@ | ||
| # RUN: not llvm-mc -triple=riscv64 --mattr=+experimental-p %s 2>&1 \ | ||
| # RUN: | FileCheck %s --check-prefixes=CHECK-ERROR | ||
|
|
||
| # Imm overflow | ||
| pli.h a0, 0x400 | ||
| # CHECK-ERROR: immediate must be an integer in the range [-512, 511] | ||
| plui.h a1, 0x400 | ||
| # CHECK-ERROR: immediate must be an integer in the range [-512, 1023] | ||
| pli.w a1, -0x201 | ||
| # CHECK-ERROR: immediate must be an integer in the range [-512, 511] | ||
|
|
||
| pslli.b a6, a7, 100 | ||
| # CHECK-ERROR: immediate must be an integer in the range [0, 7] | ||
| pslli.h ra, sp, 100 | ||
| # CHECK-ERROR: immediate must be an integer in the range [0, 15] | ||
| pslli.w ra, sp, 100 | ||
| # CHECK-ERROR: immediate must be an integer in the range [0, 31] | ||
| psslai.h t0, t1, 100 | ||
| # CHECK-ERROR: immediate must be an integer in the range [0, 15] | ||
| psslai.w a4, a5, -1 | ||
| # CHECK-ERROR: error: immediate must be an integer in the range [0, 31] |
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.
Uh oh!
There was an error while loading. Please reload this page.