Skip to content

Commit 9e27db0

Browse files
authored
[RISCV] Add Andes XAndesVPackFPH (Andes Vector Packed FP16) extension. (llvm#138827)
The spec can be found at: https://github.com/andestech/andes-v5-isa/releases/tag/ast-v5_4_0-release. This patch only supports assembler. Intrinsics support will be added in a later patch.
1 parent 9600a12 commit 9e27db0

File tree

10 files changed

+93
-1
lines changed

10 files changed

+93
-1
lines changed

clang/test/Driver/print-supported-extensions-riscv.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
// CHECK-NEXT: svpbmt 1.0 'Svpbmt' (Page-Based Memory Types)
158158
// CHECK-NEXT: svvptc 1.0 'Svvptc' (Obviating Memory-Management Instructions after Marking PTEs Valid)
159159
// CHECK-NEXT: xandesperf 5.0 'XAndesPerf' (Andes Performance Extension)
160+
// CHECK-NEXT: xandesvpackfph 5.0 'XAndesVPackFPH' (Andes Vector Packed FP16 Extension)
160161
// CHECK-NEXT: xcvalu 1.0 'XCValu' (CORE-V ALU Operations)
161162
// CHECK-NEXT: xcvbi 1.0 'XCVbi' (CORE-V Immediate Branching)
162163
// CHECK-NEXT: xcvbitmanip 1.0 'XCVbitmanip' (CORE-V Bit Manipulation)

llvm/docs/RISCVUsage.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,9 @@ The current vendor extensions supported are:
508508
``XAndesPerf``
509509
LLVM implements `version 5.0.0 of the Andes Performance Extension specification <https://github.com/andestech/andes-v5-isa/releases/download/ast-v5_4_0-release/AndeStar_V5_ISA_Spec_UM165-v1.5.08-20250317.pdf>`__ by Andes Technology. All instructions are prefixed with `nds.` as described in the specification.
510510

511+
``XAndesVPackFPH``
512+
LLVM implements `version 5.0.0 of the Andes Vector Packed FP16 Extension specification <https://github.com/andestech/andes-v5-isa/releases/download/ast-v5_4_0-release/AndeStar_V5_ISA_Spec_UM165-v1.5.08-20250317.pdf>`__ by Andes Technology. All instructions are prefixed with `nds.` as described in the specification.
513+
511514
Experimental C Intrinsics
512515
=========================
513516

llvm/docs/ReleaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ Changes to the RISC-V Backend
185185
interrupt handlers without using inline assembly.
186186
* Adds assembler support for the Andes `XAndesperf` (Andes Performance extension).
187187
* `-mcpu=sifive-p870` was added.
188+
* Adds assembler support for the Andes `XAndesvpackfph` (Andes Vector Packed FP16 extension).
188189

189190
Changes to the WebAssembly Backend
190191
----------------------------------

llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,8 @@ static constexpr FeatureBitset XTHeadGroup = {
727727
RISCV::FeatureVendorXTHeadMemPair, RISCV::FeatureVendorXTHeadSync,
728728
RISCV::FeatureVendorXTHeadVdot};
729729

730-
static constexpr FeatureBitset XAndesGroup = {RISCV::FeatureVendorXAndesPerf};
730+
static constexpr FeatureBitset XAndesGroup = {
731+
RISCV::FeatureVendorXAndesPerf, RISCV::FeatureVendorXAndesVPackFPH};
731732

732733
static constexpr DecoderListEntry DecoderList32[]{
733734
// Vendor Extensions

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,14 @@ def HasVendorXAndesPerf
15171517
AssemblerPredicate<(all_of FeatureVendorXAndesPerf),
15181518
"'XAndesPerf' (Andes Performance Extension)">;
15191519

1520+
def FeatureVendorXAndesVPackFPH
1521+
: RISCVExtension<5, 0, "Andes Vector Packed FP16 Extension",
1522+
[FeatureStdExtZvfhmin]>;
1523+
def HasVendorXAndesVPackFPH
1524+
: Predicate<"Subtarget->hasVendorXAndesVPackFPH()">,
1525+
AssemblerPredicate<(all_of FeatureVendorXAndesVPackFPH),
1526+
"'XAndesVPackFPH' (Andes Vector Packed FP16 Extension)">;
1527+
15201528
//===----------------------------------------------------------------------===//
15211529
// LLVM specific features and extensions
15221530
//===----------------------------------------------------------------------===//

llvm/lib/Target/RISCV/RISCVInstrInfoXAndes.td

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,29 @@ class NDSRVInstSDGP<bits<3> funct3, string opcodestr>
315315
let mayStore = 1;
316316
}
317317

318+
class NDSRVInstVFPMAD<bits<6> funct6, string opcodestr>
319+
: RVInst<(outs VR:$vd), (ins VR:$vs2, FPR32:$rs1, VMaskOp:$vm),
320+
opcodestr # "." # "vf", "$vd, $rs1, $vs2$vm", [], InstFormatR>,
321+
SchedBinaryMC<"WriteVFMulAddF", "ReadVFMulAddV", "ReadVFMulAddF"> {
322+
bits<5> vs2;
323+
bits<5> rs1;
324+
bits<5> vd;
325+
bit vm;
326+
327+
let Inst{31-26} = funct6;
328+
let Inst{25} = vm;
329+
let Inst{24-20} = vs2;
330+
let Inst{19-15} = rs1;
331+
let Inst{14-12} = 0b100;
332+
let Inst{11-7} = vd;
333+
let Inst{6-0} = OPC_CUSTOM_2.Value;
334+
let hasSideEffects = 0;
335+
let mayLoad = 0;
336+
let mayStore = 0;
337+
338+
let RVVConstraint = VMConstraint;
339+
}
340+
318341
//===----------------------------------------------------------------------===//
319342
// XAndesPerf
320343
//===----------------------------------------------------------------------===//
@@ -365,6 +388,16 @@ def NDS_LDGP : NDSRVInstLDGP<0b011, "nds.ldgp">;
365388

366389
def NDS_SDGP : NDSRVInstSDGP<0b111, "nds.sdgp">;
367390
} // Predicates = [HasVendorXAndesPerf, IsRV64]
391+
392+
//===----------------------------------------------------------------------===//
393+
// XAndesVPackFPH
394+
//===----------------------------------------------------------------------===//
395+
396+
let Predicates = [HasVendorXAndesVPackFPH],
397+
Uses = [FRM, VL, VTYPE], mayRaiseFPException = true in {
398+
def NDS_VFPMADT_VF : NDSRVInstVFPMAD<0b000010, "nds.vfpmadt">;
399+
def NDS_VFPMADB_VF : NDSRVInstVFPMAD<0b000011, "nds.vfpmadb">;
400+
}
368401
} // DecoderNamespace = "XAndes"
369402

370403
// Patterns

llvm/test/CodeGen/RISCV/attributes.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcisync %s -o - | FileCheck --check-prefix=RV32XQCISYNC %s
105105
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcisls %s -o - | FileCheck --check-prefix=RV32XQCISLS %s
106106
; RUN: llc -mtriple=riscv32 -mattr=+xandesperf %s -o - | FileCheck --check-prefix=RV32XANDESPERF %s
107+
; RUN: llc -mtriple=riscv32 -mattr=+xandesvpackfph %s -o - | FileCheck --check-prefix=RV32XANDESVPACKFPH %s
107108
; RUN: llc -mtriple=riscv32 -mattr=+zaamo %s -o - | FileCheck --check-prefix=RV32ZAAMO %s
108109
; RUN: llc -mtriple=riscv32 -mattr=+zalrsc %s -o - | FileCheck --check-prefix=RV32ZALRSC %s
109110
; RUN: llc -mtriple=riscv32 -mattr=+zca %s -o - | FileCheck --check-prefixes=CHECK,RV32ZCA %s
@@ -254,6 +255,7 @@
254255
; RUN: llc -mtriple=riscv64 -mattr=+xtheadsync %s -o - | FileCheck --check-prefix=RV64XTHEADSYNC %s
255256
; RUN: llc -mtriple=riscv64 -mattr=+xtheadvdot %s -o - | FileCheck --check-prefixes=CHECK,RV64XTHEADVDOT %s
256257
; RUN: llc -mtriple=riscv64 -mattr=+xandesperf %s -o - | FileCheck --check-prefix=RV64XANDESPERF %s
258+
; RUN: llc -mtriple=riscv64 -mattr=+xandesvpackfph %s -o - | FileCheck --check-prefix=RV64XANDESVPACKFPH %s
257259
; RUN: llc -mtriple=riscv64 -mattr=+za64rs %s -o - | FileCheck --check-prefixes=CHECK,RV64ZA64RS %s
258260
; RUN: llc -mtriple=riscv64 -mattr=+za128rs %s -o - | FileCheck --check-prefixes=CHECK,RV64ZA128RS %s
259261
; RUN: llc -mtriple=riscv64 -mattr=+zama16b %s -o - | FileCheck --check-prefixes=CHECK,RV64ZAMA16B %s
@@ -447,6 +449,7 @@
447449
; RV32XQCISYNC: attribute 5, "rv32i2p1_zca1p0_xqcisync0p2"
448450
; RV32XQCISLS: .attribute 5, "rv32i2p1_xqcisls0p2"
449451
; RV32XANDESPERF: .attribute 5, "rv32i2p1_xandesperf5p0"
452+
; RV32XANDESVPACKFPH: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zve32f1p0_zve32x1p0_zvfhmin1p0_zvl32b1p0_xandesvpackfph5p0"
450453
; RV32ZAAMO: .attribute 5, "rv32i2p1_zaamo1p0"
451454
; RV32ZALRSC: .attribute 5, "rv32i2p1_zalrsc1p0"
452455
; RV32ZCA: .attribute 5, "rv32i2p1_zca1p0"
@@ -598,6 +601,7 @@
598601
; RV64XTHEADSYNC: .attribute 5, "rv64i2p1_xtheadsync1p0"
599602
; RV64XTHEADVDOT: .attribute 5, "rv64i2p1_f2p2_d2p2_v1p0_zicsr2p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0_xtheadvdot1p0"
600603
; RV64XANDESPERF: .attribute 5, "rv64i2p1_xandesperf5p0"
604+
; RV64XANDESVPACKFPH: .attribute 5, "rv64i2p1_f2p2_zicsr2p0_zve32f1p0_zve32x1p0_zvfhmin1p0_zvl32b1p0_xandesvpackfph5p0"
601605
; RV64ZTSO: .attribute 5, "rv64i2p1_ztso1p0"
602606
; RV64ZAAMO: .attribute 5, "rv64i2p1_zaamo1p0"
603607
; RV64ZALRSC: .attribute 5, "rv64i2p1_zalrsc1p0"

llvm/test/CodeGen/RISCV/features-info.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
; CHECK-NEXT: ventana-veyron - Ventana Veyron-Series processors.
172172
; CHECK-NEXT: vxrm-pipeline-flush - VXRM writes causes pipeline flush.
173173
; CHECK-NEXT: xandesperf - 'XAndesPerf' (Andes Performance Extension).
174+
; CHECK-NEXT: xandesvpackfph - 'XAndesVPackFPH' (Andes Vector Packed FP16 Extension).
174175
; CHECK-NEXT: xcvalu - 'XCValu' (CORE-V ALU Operations).
175176
; CHECK-NEXT: xcvbi - 'XCVbi' (CORE-V Immediate Branching).
176177
; CHECK-NEXT: xcvbitmanip - 'XCVbitmanip' (CORE-V Bit Manipulation).
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# XAndesVPackFPH - Andes Vector Packed FP16 Extension
2+
# RUN: llvm-mc %s -triple=riscv32 -mattr=+xandesvpackfph -show-encoding \
3+
# RUN: | FileCheck -check-prefixes=CHECK-ASM %s
4+
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+xandesvpackfph < %s \
5+
# RUN: | llvm-objdump --mattr=+xandesvpackfph -M no-aliases -d -r - \
6+
# RUN: | FileCheck -check-prefixes=CHECK-OBJ %s
7+
# RUN: not llvm-mc -triple=riscv32 -show-encoding %s 2>&1 \
8+
# RUN: | FileCheck %s --check-prefix=CHECK-ERROR
9+
# RUN: llvm-mc %s -triple=riscv64 -mattr=+xandesvpackfph -show-encoding \
10+
# RUN: | FileCheck -check-prefixes=CHECK-ASM %s
11+
# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+xandesvpackfph < %s \
12+
# RUN: | llvm-objdump --mattr=+xandesvpackfph -M no-aliases -d -r - \
13+
# RUN: | FileCheck -check-prefixes=CHECK-OBJ %s
14+
# RUN: not llvm-mc -triple=riscv64 -show-encoding %s 2>&1 \
15+
# RUN: | FileCheck %s --check-prefix=CHECK-ERROR
16+
17+
# CHECK-OBJ: nds.vfpmadt.vf v8, fa0, v10
18+
# CHECK-ASM: nds.vfpmadt.vf v8, fa0, v10
19+
# CHECK-ASM: encoding: [0x5b,0x44,0xa5,0x0a]
20+
# CHECK-ERROR: instruction requires the following: 'XAndesVPackFPH' (Andes Vector Packed FP16 Extension){{$}}
21+
nds.vfpmadt.vf v8, fa0, v10
22+
23+
# CHECK-OBJ: nds.vfpmadt.vf v8, fa0, v10, v0.t
24+
# CHECK-ASM: nds.vfpmadt.vf v8, fa0, v10, v0.t
25+
# CHECK-ASM: encoding: [0x5b,0x44,0xa5,0x08]
26+
# CHECK-ERROR: instruction requires the following: 'XAndesVPackFPH' (Andes Vector Packed FP16 Extension){{$}}
27+
nds.vfpmadt.vf v8, fa0, v10, v0.t
28+
29+
# CHECK-OBJ: nds.vfpmadb.vf v8, fa0, v10
30+
# CHECK-ASM: nds.vfpmadb.vf v8, fa0, v10
31+
# CHECK-ASM: encoding: [0x5b,0x44,0xa5,0x0e]
32+
# CHECK-ERROR: instruction requires the following: 'XAndesVPackFPH' (Andes Vector Packed FP16 Extension){{$}}
33+
nds.vfpmadb.vf v8, fa0, v10
34+
35+
# CHECK-OBJ: nds.vfpmadb.vf v8, fa0, v10, v0.t
36+
# CHECK-ASM: nds.vfpmadb.vf v8, fa0, v10, v0.t
37+
# CHECK-ASM: encoding: [0x5b,0x44,0xa5,0x0c]
38+
# CHECK-ERROR: instruction requires the following: 'XAndesVPackFPH' (Andes Vector Packed FP16 Extension){{$}}
39+
nds.vfpmadb.vf v8, fa0, v10, v0.t

llvm/unittests/TargetParser/RISCVISAInfoTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,7 @@ R"(All available -march extensions for RISC-V
11281128
svpbmt 1.0
11291129
svvptc 1.0
11301130
xandesperf 5.0
1131+
xandesvpackfph 5.0
11311132
xcvalu 1.0
11321133
xcvbi 1.0
11331134
xcvbitmanip 1.0

0 commit comments

Comments
 (0)