Skip to content

Commit ace08d5

Browse files
toppercrealqhc
andauthored
[RISCV] Add MC support for more P extension instructions. (#153458)
These instructions are the shift by immediate and saturate by immediate instructions from the top half of page 9 of https://jhauser.us/RISCV/ext-P/RVP-instrEncodings-015.pdf I've also improved the CHECK lines in the invalid tests to check line and column number from the diagnostic. Co-authored-by: realqhc <[email protected]>
1 parent d8850ee commit ace08d5

File tree

5 files changed

+181
-34
lines changed

5 files changed

+181
-34
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoP.td

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ class RVPShift_ri<bits<3> f, bits<3> funct3, string opcodestr, Operand ImmType>
9898
let Inst{27} = 0b0;
9999
}
100100

101+
class RVPShiftD_ri<bits<3> f, bits<3> funct3, string opcodestr>
102+
: RVPShift_ri<f, funct3, opcodestr, uimm6> {
103+
bits<6> shamt;
104+
105+
let Inst{26} = 0b1;
106+
let Inst{25-20} = shamt;
107+
}
108+
101109
class RVPShiftW_ri<bits<3> f, bits<3> funct3, string opcodestr>
102110
: RVPShift_ri<f, funct3, opcodestr, uimm5> {
103111
bits<5> shamt;
@@ -189,3 +197,37 @@ let Predicates = [HasStdExtP] in
189197
def PLUI_H : PLUI_i<0b1111000, "plui.h">;
190198
let Predicates = [HasStdExtP, IsRV64] in
191199
def PLUI_W : PLUI_i<0b1111001, "plui.w">;
200+
201+
let Predicates = [HasStdExtP] in {
202+
def PSRLI_B : RVPShiftB_ri<0b000, 0b100, "psrli.b">;
203+
def PSRLI_H : RVPShiftH_ri<0b000, 0b100, "psrli.h">;
204+
205+
def PUSATI_H : RVPShiftH_ri<0b010, 0b100, "pusati.h">;
206+
207+
def PSRAI_B : RVPShiftB_ri<0b100, 0b100, "psrai.b">;
208+
def PSRAI_H : RVPShiftH_ri<0b100, 0b100, "psrai.h">;
209+
210+
def PSRARI_H : RVPShiftH_ri<0b101, 0b100, "psrari.h">;
211+
212+
def PSATI_H : RVPShiftH_ri<0b110, 0b100, "psati.h">;
213+
} // Predicates = [HasStdExtP]
214+
let Predicates = [HasStdExtP, IsRV32], DecoderNamespace = "RV32Only" in {
215+
def USATI_RV32 : RVPShiftW_ri<0b010, 0b100, "usati">;
216+
217+
def SRARI_RV32 : RVPShiftW_ri<0b101, 0b100, "srari">;
218+
219+
def SATI_RV32 : RVPShiftW_ri<0b110, 0b100, "sati">;
220+
} // Predicates = [HasStdExtP, IsRV32]
221+
let Predicates = [HasStdExtP, IsRV64] in {
222+
def PSRLI_W : RVPShiftW_ri<0b000, 0b100, "psrli.w">;
223+
def PSRAI_W : RVPShiftW_ri<0b100, 0b100, "psrai.w">;
224+
225+
def PUSATI_W : RVPShiftW_ri<0b010, 0b100, "pusati.w">;
226+
def USATI_RV64 : RVPShiftD_ri<0b010, 0b100, "usati">;
227+
228+
def PSRARI_W : RVPShiftW_ri<0b101, 0b100, "psrari.w">;
229+
def SRARI_RV64 : RVPShiftD_ri<0b101, 0b100, "srari">;
230+
231+
def PSATI_W : RVPShiftW_ri<0b110, 0b100, "psati.w">;
232+
def SATI_RV64 : RVPShiftD_ri<0b110, 0b100, "sati">;
233+
} // Predicates = [HasStdExtP, IsRV64]

llvm/test/MC/RISCV/rv32p-invalid.s

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
11
# RUN: not llvm-mc -triple=riscv32 --mattr=+experimental-p %s 2>&1 \
2-
# RUN: | FileCheck %s --check-prefixes=CHECK-ERROR
2+
# RUN: | FileCheck %s
33

44
# Imm overflow
5-
pli.h a0, 0x400
6-
# CHECK-ERROR: immediate must be an integer in the range [-512, 511]
7-
plui.h a1, 0x400
8-
# CHECK-ERROR: immediate must be an integer in the range [-512, 1023]
9-
pli.b a0, 0x200
10-
# CHECK-ERROR: immediate must be an integer in the range [0, 255]
11-
12-
pslli.b a6, a7, 100
13-
# CHECK-ERROR: immediate must be an integer in the range [0, 7]
14-
pslli.h ra, sp, 100
15-
# CHECK-ERROR: immediate must be an integer in the range [0, 15]
16-
psslai.h t0, t1, 100
17-
# CHECK-ERROR: immediate must be an integer in the range [0, 15]
18-
sslai a4, a5, -1
19-
# CHECK-ERROR: immediate must be an integer in the range [0, 31]
5+
pli.h a0, 0x400 # CHECK: :[[@LINE]]:11: error: immediate must be an integer in the range [-512, 511]
6+
plui.h a1, 0x400 # CHECK: :[[@LINE]]:12: error: immediate must be an integer in the range [-512, 1023]
7+
pli.b a0, 0x200 # CHECK: :[[@LINE]]:11: error: immediate must be an integer in the range [0, 255]
8+
9+
pslli.b a6, a7, 100 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 7]
10+
pslli.h ra, sp, 100 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 15]
11+
pslli.w ra, sp, 12 # CHECK: :[[@LINE]]:1: error: instruction requires the following: RV64I Base Instruction Set
12+
13+
psslai.h t0, t1, 100 # CHECK: :[[@LINE]]:18: error: immediate must be an integer in the range [0, 15]
14+
psslai.w t0, t1, 27 # CHECK: :[[@LINE]]:1: error: instruction requires the following: RV64I Base Instruction Set
15+
sslai a4, a5, -1 # CHECK: :[[@LINE]]:15: error: immediate must be an integer in the range [0, 31]
16+
17+
psrli.b a6, a7, 100 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 7]
18+
psrli.h ra, sp, 100 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 15]
19+
psrli.w ra, sp, 31 # CHECK: :[[@LINE]]:1: error: instruction requires the following: RV64I Base Instruction Set
20+
21+
pusati.h ra, sp, 100 # CHECK: :[[@LINE]]:18: error: immediate must be an integer in the range [0, 15]
22+
pusati.w ra, sp, 0 # CHECK: :[[@LINE]]:1: error: instruction requires the following: RV64I Base Instruction Set
23+
usati ra, sp, 100 # CHECK: :[[@LINE]]:15: error: immediate must be an integer in the range [0, 31]
24+
25+
psrai.b a6, a7, 100 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 7]
26+
psrai.h ra, sp, 100 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 15]
27+
psrai.w ra, sp, 10 # CHECK: :[[@LINE]]:1: error: instruction requires the following: RV64I Base Instruction Set
28+
29+
psrari.h ra, sp, 100 # CHECK: :[[@LINE]]:18: error: immediate must be an integer in the range [0, 15]
30+
psrari.w ra, sp, 15 # CHECK: :[[@LINE]]:1: error: instruction requires the following: RV64I Base Instruction Set
31+
srari ra, sp, 100 # CHECK: :[[@LINE]]:15: error: immediate must be an integer in the range [0, 31]
32+
33+
psati.h ra, sp, 100 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 15]
34+
psati.w ra, sp, 24 # CHECK: :[[@LINE]]:1: error: instruction requires the following: RV64I Base Instruction Set
35+
sati ra, sp, 100 # CHECK: :[[@LINE]]:14: error: immediate must be an integer in the range [0, 31]

llvm/test/MC/RISCV/rv32p-valid.s

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,33 @@ plui.h gp, 32
7676
# CHECK-ASM-AND-OBJ: plui.h gp, -412
7777
# CHECK-ASM: encoding: [0x9b,0x21,0x99,0xf0]
7878
plui.h gp, 612
79+
# CHECK-ASM-AND-OBJ: psrli.b a6, a7, 0
80+
# CHECK-ASM: encoding: [0x1b,0xc8,0x88,0x80]
81+
psrli.b a6, a7, 0
82+
# CHECK-ASM-AND-OBJ: psrli.h ra, sp, 1
83+
# CHECK-ASM: encoding: [0x9b,0x40,0x11,0x81]
84+
psrli.h ra, sp, 1
85+
# CHECK-ASM-AND-OBJ: pusati.h t2, t3, 4
86+
# CHECK-ASM: encoding: [0x9b,0x43,0x4e,0xa1]
87+
pusati.h t2, t3, 4
88+
# CHECK-ASM-AND-OBJ: usati t3, t4, 5
89+
# CHECK-ASM: encoding: [0x1b,0xce,0x5e,0xa2]
90+
usati t3, t4, 5
91+
# CHECK-ASM-AND-OBJ: psrai.b a6, a7, 0
92+
# CHECK-ASM: encoding: [0x1b,0xc8,0x88,0xc0]
93+
psrai.b a6, a7, 0
94+
# CHECK-ASM-AND-OBJ: psrai.h ra, sp, 1
95+
# CHECK-ASM: encoding: [0x9b,0x40,0x11,0xc1]
96+
psrai.h ra, sp, 1
97+
# CHECK-ASM-AND-OBJ: psrari.h t4, t5, 6
98+
# CHECK-ASM: encoding: [0x9b,0x4e,0x6f,0xd1]
99+
psrari.h t4, t5, 6
100+
# CHECK-ASM-AND-OBJ: srari t5, t6, 7
101+
# CHECK-ASM: encoding: [0x1b,0xcf,0x7f,0xd2]
102+
srari t5, t6, 7
103+
# CHECK-ASM-AND-OBJ: psati.h t6, s11, 8
104+
# CHECK-ASM: encoding: [0x9b,0xcf,0x8d,0xe1]
105+
psati.h t6, s11, 8
106+
# CHECK-ASM-AND-OBJ: sati s11, s10, 9
107+
# CHECK-ASM: encoding: [0x9b,0x4d,0x9d,0xe2]
108+
sati s11, s10, 9

llvm/test/MC/RISCV/rv64p-invalid.s

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
11
# RUN: not llvm-mc -triple=riscv64 --mattr=+experimental-p %s 2>&1 \
2-
# RUN: | FileCheck %s --check-prefixes=CHECK-ERROR
2+
# RUN: | FileCheck %s
33

44
# Imm overflow
5-
pli.h a0, 0x400
6-
# CHECK-ERROR: immediate must be an integer in the range [-512, 511]
7-
plui.h a1, 0x400
8-
# CHECK-ERROR: immediate must be an integer in the range [-512, 1023]
9-
pli.w a1, -0x201
10-
# CHECK-ERROR: immediate must be an integer in the range [-512, 511]
11-
12-
pslli.b a6, a7, 100
13-
# CHECK-ERROR: immediate must be an integer in the range [0, 7]
14-
pslli.h ra, sp, 100
15-
# CHECK-ERROR: immediate must be an integer in the range [0, 15]
16-
pslli.w ra, sp, 100
17-
# CHECK-ERROR: immediate must be an integer in the range [0, 31]
18-
psslai.h t0, t1, 100
19-
# CHECK-ERROR: immediate must be an integer in the range [0, 15]
20-
psslai.w a4, a5, -1
21-
# CHECK-ERROR: error: immediate must be an integer in the range [0, 31]
5+
pli.h a0, 0x400 # CHECK: :[[@LINE]]:11: error: immediate must be an integer in the range [-512, 511]
6+
plui.h a1, 0x400 # CHECK: :[[@LINE]]:12: error: immediate must be an integer in the range [-512, 1023]
7+
pli.w a1, -0x201 # CHECK: :[[@LINE]]:11: error: immediate must be an integer in the range [-512, 511]
8+
9+
pslli.b a6, a7, 100 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 7]
10+
pslli.h ra, sp, 100 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 15]
11+
pslli.w ra, sp, 100 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 31]
12+
13+
psslai.h t0, t1, 100 # CHECK: :[[@LINE]]:18: error: immediate must be an integer in the range [0, 15]
14+
psslai.w a4, a5, -1 # CHECK: :[[@LINE]]:18: error: immediate must be an integer in the range [0, 31]
15+
sslai ra, sp, 10 # CHECK: :[[@LINE]]:1: error: instruction requires the following: RV32I Base Instruction Set
16+
17+
psrli.b a6, a7, 100 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 7]
18+
psrli.h ra, sp, 100 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 15]
19+
psrli.w ra, sp, 100 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 31]
20+
21+
pusati.h ra, sp, 100 # CHECK: :[[@LINE]]:18: error: immediate must be an integer in the range [0, 15]
22+
pusati.w ra, sp, 100 # CHECK: :[[@LINE]]:18: error: immediate must be an integer in the range [0, 31]
23+
usati ra, sp, 100 # CHECK: :[[@LINE]]:15: error: immediate must be an integer in the range [0, 63]
24+
25+
psrai.b a6, a7, 100 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 7]
26+
psrai.h ra, sp, 100 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 15]
27+
psrai.w ra, sp, 100 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 31]
28+
29+
psrari.h ra, sp, 100 # CHECK: :[[@LINE]]:18: error: immediate must be an integer in the range [0, 15]
30+
psrari.w ra, sp, 100 # CHECK: :[[@LINE]]:18: error: immediate must be an integer in the range [0, 31]
31+
srari ra, sp, 100 # CHECK: :[[@LINE]]:15: error: immediate must be an integer in the range [0, 63]
32+
33+
psati.h ra, sp, 100 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 15]
34+
psati.w ra, sp, 100 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 31]
35+
sati ra, sp, 100 # CHECK: :[[@LINE]]:14: error: immediate must be an integer in the range [0, 63]

llvm/test/MC/RISCV/rv64p-valid.s

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,48 @@ plui.w a2, 1
106106
# CHECK-ASM-AND-OBJ: plui.w a2, -1
107107
# CHECK-ASM: encoding: [0x1b,0xa6,0xff,0xf3]
108108
plui.w a2, 1023
109+
# CHECK-ASM-AND-OBJ: psrli.b a6, a7
110+
# CHECK-ASM: encoding: [0x1b,0xc8,0x88,0x80]
111+
psrli.b a6, a7, 0
112+
# CHECK-ASM-AND-OBJ: psrli.h ra, sp, 1
113+
# CHECK-ASM: encoding: [0x9b,0x40,0x11,0x81]
114+
psrli.h ra, sp, 1
115+
# CHECK-ASM-AND-OBJ: psrli.w ra, sp, 2
116+
# CHECK-ASM: encoding: [0x9b,0x40,0x21,0x82]
117+
psrli.w ra, sp, 2
118+
# CHECK-ASM-AND-OBJ: pusati.h t2, t3, 4
119+
# CHECK-ASM: encoding: [0x9b,0x43,0x4e,0xa1]
120+
pusati.h t2, t3, 4
121+
# CHECK-ASM-AND-OBJ: pusati.w t2, t3, 5
122+
# CHECK-ASM: encoding: [0x9b,0x43,0x5e,0xa2]
123+
pusati.w t2, t3, 5
124+
# CHECK-ASM-AND-OBJ: usati t3, t4, 5
125+
# CHECK-ASM: encoding: [0x1b,0xce,0x5e,0xa4]
126+
usati t3, t4, 5
127+
# CHECK-ASM-AND-OBJ: psrai.b a6, a7, 0
128+
# CHECK-ASM: encoding: [0x1b,0xc8,0x88,0xc0]
129+
psrai.b a6, a7, 0
130+
# CHECK-ASM-AND-OBJ: psrai.h ra, sp, 1
131+
# CHECK-ASM: encoding: [0x9b,0x40,0x11,0xc1]
132+
psrai.h ra, sp, 1
133+
# CHECK-ASM-AND-OBJ: psrai.w ra, sp, 2
134+
# CHECK-ASM: encoding: [0x9b,0x40,0x21,0xc2]
135+
psrai.w ra, sp, 2
136+
# CHECK-ASM-AND-OBJ: psrari.h t4, t5, 6
137+
# CHECK-ASM: encoding: [0x9b,0x4e,0x6f,0xd1]
138+
psrari.h t4, t5, 6
139+
# CHECK-ASM-AND-OBJ: psrari.w t5, t6, 7
140+
# CHECK-ASM: encoding: [0x1b,0xcf,0x7f,0xd2]
141+
psrari.w t5, t6, 7
142+
# CHECK-ASM-AND-OBJ: srari t6, s11, 63
143+
# CHECK-ASM: encoding: [0x9b,0xcf,0xfd,0xd7]
144+
srari t6, s11, 63
145+
# CHECK-ASM-AND-OBJ: psati.h s11, s10, 9
146+
# CHECK-ASM: encoding: [0x9b,0x4d,0x9d,0xe1]
147+
psati.h s11, s10, 9
148+
# CHECK-ASM-AND-OBJ: psati.w s10, s9, 10
149+
# CHECK-ASM: encoding: [0x1b,0xcd,0xac,0xe2]
150+
psati.w s10, s9, 10
151+
# CHECK-ASM-AND-OBJ: sati s9, s8, 32
152+
# CHECK-ASM: encoding: [0x9b,0x4c,0x0c,0xe6]
153+
sati s9, s8, 32

0 commit comments

Comments
 (0)