Skip to content

Commit 8ddada4

Browse files
authored
[RISCV] Add Andes XAndesVBFHCvt (Andes Vector BFLOAT16 Conversion) extension (#144320)
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. The instructions are similar to `Zvfbfmin` and the only difference with `Zvfbfmin` is that `XAndesVBFHCvt` doesn't have mask variant.
1 parent 9265b1f commit 8ddada4

File tree

11 files changed

+88
-2
lines changed

11 files changed

+88
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
// CHECK-NEXT: svpbmt 1.0 'Svpbmt' (Page-Based Memory Types)
160160
// CHECK-NEXT: svvptc 1.0 'Svvptc' (Obviating Memory-Management Instructions after Marking PTEs Valid)
161161
// CHECK-NEXT: xandesperf 5.0 'XAndesPerf' (Andes Performance Extension)
162+
// CHECK-NEXT: xandesvbfhcvt 5.0 'XAndesVBFHCvt' (Andes Vector BFLOAT16 Conversion Extension)
162163
// CHECK-NEXT: xandesvdot 5.0 'XAndesVDot' (Andes Vector Dot Product Extension)
163164
// CHECK-NEXT: xandesvpackfph 5.0 'XAndesVPackFPH' (Andes Vector Packed FP16 Extension)
164165
// CHECK-NEXT: xcvalu 1.0 'XCValu' (CORE-V ALU Operations)

clang/test/Preprocessor/riscv-target-features-andes.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
// RUN: -o - | FileCheck --check-prefix=CHECK-XANDESPERF %s
1616
// CHECK-XANDESPERF: __riscv_xandesperf 5000000{{$}}
1717

18+
// RUN: %clang --target=riscv32 \
19+
// RUN: -march=rv32i_xandesvbfhcvt -E -dM %s \
20+
// RUN: -o - | FileCheck --check-prefix=CHECK-XANDESVBFHCVT %s
21+
// RUN: %clang --target=riscv64 \
22+
// RUN: -march=rv64i_xandesvbfhcvt -E -dM %s \
23+
// RUN: -o - | FileCheck --check-prefix=CHECK-XANDESVBFHCVT %s
24+
// CHECK-XANDESVBFHCVT: __riscv_xandesvbfhcvt 5000000{{$}}
25+
1826
// RUN: %clang --target=riscv32 \
1927
// RUN: -march=rv32i_xandesvpackfph -E -dM %s \
2028
// RUN: -o - | FileCheck --check-prefix=CHECK-XANDESVPACKFPH %s

llvm/docs/RISCVUsage.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,9 @@ The current vendor extensions supported are:
513513
``XAndesPerf``
514514
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.
515515

516+
``XAndesVBFHCvt``
517+
LLVM implements `version 5.0.0 of the Andes Vector BFLOAT16 Conversion 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.
518+
516519
``XAndesVPackFPH``
517520
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.
518521

llvm/docs/ReleaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ Changes to the RISC-V Backend
210210
* The `Shlcofideleg` extension was added.
211211
* `-mcpu=sifive-x390` was added.
212212
* `-mtune=andes-45-series` was added.
213+
* Adds assembler support for the Andes `XAndesvbfhcvt` (Andes Vector BFLOAT16 Conversion extension).
213214

214215
Changes to the WebAssembly Backend
215216
----------------------------------

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,8 +774,8 @@ static constexpr FeatureBitset XTHeadGroup = {
774774
RISCV::FeatureVendorXTHeadVdot};
775775

776776
static constexpr FeatureBitset XAndesGroup = {
777-
RISCV::FeatureVendorXAndesPerf, RISCV::FeatureVendorXAndesVPackFPH,
778-
RISCV::FeatureVendorXAndesVDot};
777+
RISCV::FeatureVendorXAndesPerf, RISCV::FeatureVendorXAndesVBFHCvt,
778+
RISCV::FeatureVendorXAndesVPackFPH, RISCV::FeatureVendorXAndesVDot};
779779

780780
static constexpr DecoderListEntry DecoderList32[]{
781781
// Vendor Extensions

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,15 @@ def HasVendorXAndesPerf
15991599
AssemblerPredicate<(all_of FeatureVendorXAndesPerf),
16001600
"'XAndesPerf' (Andes Performance Extension)">;
16011601

1602+
def FeatureVendorXAndesVBFHCvt
1603+
: RISCVExtension<5, 0, "Andes Vector BFLOAT16 Conversion Extension",
1604+
[FeatureStdExtZve32f]>;
1605+
def HasVendorXAndesVBFHCvt
1606+
: Predicate<"Subtarget->hasVendorXAndesVBFHCvt()">,
1607+
AssemblerPredicate<(all_of FeatureVendorXAndesVBFHCvt),
1608+
"'XAndesVBFHCvt' (Andes Vector BFLOAT16 Conversion Extension)">;
1609+
1610+
16021611
def FeatureVendorXAndesVPackFPH
16031612
: RISCVExtension<5, 0, "Andes Vector Packed FP16 Extension",
16041613
[FeatureStdExtZvfhmin]>;

llvm/lib/Target/RISCV/RISCVInstrInfoXAndes.td

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,25 @@ class NDSRVInstVD4DOT<bits<6> funct6, string opcodestr>
361361
let RVVConstraint = VMConstraint;
362362
}
363363

364+
class NDSRVInstVBFHCvt<bits<7> funct7, bits<5> vs1, string opcodestr>
365+
: RVInst<(outs VR:$vd), (ins VR:$vs2, VMaskOp:$vm),
366+
opcodestr, "$vd, $vs2", [], InstFormatR> {
367+
bits<5> vs2;
368+
bits<5> vd;
369+
370+
let Inst{31-25} = funct7;
371+
let Inst{24-20} = vs2;
372+
let Inst{19-15} = vs1;
373+
let Inst{14-12} = 0b100;
374+
let Inst{11-7} = vd;
375+
let Inst{6-0} = OPC_CUSTOM_2.Value;
376+
let hasSideEffects = 0;
377+
let mayLoad = 0;
378+
let mayStore = 0;
379+
380+
let Uses = [VL, VTYPE];
381+
}
382+
364383
//===----------------------------------------------------------------------===//
365384
// Multiclass
366385
//===----------------------------------------------------------------------===//
@@ -460,6 +479,18 @@ def NDS_LDGP : NDSRVInstLDGP<0b011, "nds.ldgp">;
460479
def NDS_SDGP : NDSRVInstSDGP<0b111, "nds.sdgp">;
461480
} // Predicates = [HasVendorXAndesPerf, IsRV64]
462481

482+
//===----------------------------------------------------------------------===//
483+
// XAndesVBFHCvt
484+
//===----------------------------------------------------------------------===//
485+
486+
let Predicates = [HasVendorXAndesVBFHCvt], Constraints = "@earlyclobber $vd",
487+
mayRaiseFPException = true in {
488+
let RVVConstraint = VS2Constraint, DestEEW = EEWSEWx2 in
489+
def NDS_VFWCVT_S_BF16 : NDSRVInstVBFHCvt<0b0000000, 0b00000, "nds.vfwcvt.s.bf16">;
490+
let Uses = [FRM, VL, VTYPE] in
491+
def NDS_VFNCVT_BF16_S : NDSRVInstVBFHCvt<0b0000000, 0b00001, "nds.vfncvt.bf16.s">;
492+
}
493+
463494
//===----------------------------------------------------------------------===//
464495
// XAndesVPackFPH
465496
//===----------------------------------------------------------------------===//

llvm/test/CodeGen/RISCV/attributes.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcisls %s -o - | FileCheck --check-prefix=RV32XQCISLS %s
107107
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcisync %s -o - | FileCheck --check-prefix=RV32XQCISYNC %s
108108
; RUN: llc -mtriple=riscv32 -mattr=+xandesperf %s -o - | FileCheck --check-prefix=RV32XANDESPERF %s
109+
; RUN: llc -mtriple=riscv32 -mattr=+xandesvbfhcvt %s -o - | FileCheck --check-prefix=RV32XANDESVBFHCVT %s
109110
; RUN: llc -mtriple=riscv32 -mattr=+xandesvdot %s -o - | FileCheck --check-prefix=RV32XANDESVDOT %s
110111
; RUN: llc -mtriple=riscv32 -mattr=+xandesvpackfph %s -o - | FileCheck --check-prefix=RV32XANDESVPACKFPH %s
111112
; RUN: llc -mtriple=riscv32 -mattr=+zaamo %s -o - | FileCheck --check-prefix=RV32ZAAMO %s
@@ -260,6 +261,7 @@
260261
; RUN: llc -mtriple=riscv64 -mattr=+xtheadsync %s -o - | FileCheck --check-prefix=RV64XTHEADSYNC %s
261262
; RUN: llc -mtriple=riscv64 -mattr=+xtheadvdot %s -o - | FileCheck --check-prefixes=CHECK,RV64XTHEADVDOT %s
262263
; RUN: llc -mtriple=riscv64 -mattr=+xandesperf %s -o - | FileCheck --check-prefix=RV64XANDESPERF %s
264+
; RUN: llc -mtriple=riscv64 -mattr=+xandesvbfhcvt %s -o - | FileCheck --check-prefix=RV64XANDESVBFHCVT %s
263265
; RUN: llc -mtriple=riscv64 -mattr=+xandesvdot %s -o - | FileCheck --check-prefix=RV64XANDESVDOT %s
264266
; RUN: llc -mtriple=riscv64 -mattr=+xandesvpackfph %s -o - | FileCheck --check-prefix=RV64XANDESVPACKFPH %s
265267
; RUN: llc -mtriple=riscv64 -mattr=+za64rs %s -o - | FileCheck --check-prefixes=CHECK,RV64ZA64RS %s
@@ -457,6 +459,7 @@
457459
; RV32XQCISLS: .attribute 5, "rv32i2p1_xqcisls0p2"
458460
; RV32XQCISYNC: attribute 5, "rv32i2p1_zca1p0_xqcisync0p3"
459461
; RV32XANDESPERF: .attribute 5, "rv32i2p1_xandesperf5p0"
462+
; RV32XANDESVBFHCVT: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zve32f1p0_zve32x1p0_zvl32b1p0_xandesvbfhcvt5p0"
460463
; RV32XANDESVDOT: .attribute 5, "rv32i2p1_zicsr2p0_zve32x1p0_zvl32b1p0_xandesvdot5p0"
461464
; RV32XANDESVPACKFPH: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zve32f1p0_zve32x1p0_zvfhmin1p0_zvl32b1p0_xandesvpackfph5p0"
462465
; RV32ZAAMO: .attribute 5, "rv32i2p1_zaamo1p0"
@@ -612,6 +615,7 @@
612615
; RV64XTHEADSYNC: .attribute 5, "rv64i2p1_xtheadsync1p0"
613616
; RV64XTHEADVDOT: .attribute 5, "rv64i2p1_f2p2_d2p2_v1p0_zicsr2p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0_xtheadvdot1p0"
614617
; RV64XANDESPERF: .attribute 5, "rv64i2p1_xandesperf5p0"
618+
; RV64XANDESVBFHCVT: .attribute 5, "rv64i2p1_f2p2_zicsr2p0_zve32f1p0_zve32x1p0_zvl32b1p0_xandesvbfhcvt5p0"
615619
; RV64XANDESVDOT: .attribute 5, "rv64i2p1_zicsr2p0_zve32x1p0_zvl32b1p0_xandesvdot5p0"
616620
; RV64XANDESVPACKFPH: .attribute 5, "rv64i2p1_f2p2_zicsr2p0_zve32f1p0_zve32x1p0_zvfhmin1p0_zvl32b1p0_xandesvpackfph5p0"
617621
; RV64ZTSO: .attribute 5, "rv64i2p1_ztso1p0"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174
; CHECK-NEXT: ventana-veyron - Ventana Veyron-Series processors.
175175
; CHECK-NEXT: vxrm-pipeline-flush - VXRM writes causes pipeline flush.
176176
; CHECK-NEXT: xandesperf - 'XAndesPerf' (Andes Performance Extension).
177+
; CHECK-NEXT: xandesvbfhcvt - 'XAndesVBFHCvt' (Andes Vector BFLOAT16 Conversion Extension).
177178
; CHECK-NEXT: xandesvdot - 'XAndesVDot' (Andes Vector Dot Product Extension).
178179
; CHECK-NEXT: xandesvpackfph - 'XAndesVPackFPH' (Andes Vector Packed FP16 Extension).
179180
; CHECK-NEXT: xcvalu - 'XCValu' (CORE-V ALU Operations).
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# XAndesVBFHCvt - Andes Vector BFLOAT16 Conversion Extension
2+
# RUN: llvm-mc %s -triple=riscv32 -mattr=+xandesvbfhcvt -show-encoding \
3+
# RUN: | FileCheck -check-prefixes=CHECK-ASM %s
4+
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+xandesvbfhcvt < %s \
5+
# RUN: | llvm-objdump --mattr=+xandesvbfhcvt -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=+xandesvbfhcvt -show-encoding \
10+
# RUN: | FileCheck -check-prefixes=CHECK-ASM %s
11+
# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+xandesvbfhcvt < %s \
12+
# RUN: | llvm-objdump --mattr=+xandesvbfhcvt -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.vfwcvt.s.bf16 v8, v10
18+
# CHECK-ASM: nds.vfwcvt.s.bf16 v8, v10
19+
# CHECK-ASM: encoding: [0x5b,0x44,0xa0,0x00]
20+
# CHECK-ERROR: instruction requires the following: 'XAndesVBFHCvt' (Andes Vector BFLOAT16 Conversion Extension){{$}}
21+
nds.vfwcvt.s.bf16 v8, v10
22+
23+
# CHECK-OBJ: nds.vfncvt.bf16.s v8, v10
24+
# CHECK-ASM: nds.vfncvt.bf16.s v8, v10
25+
# CHECK-ASM: encoding: [0x5b,0xc4,0xa0,0x00]
26+
# CHECK-ERROR: instruction requires the following: 'XAndesVBFHCvt' (Andes Vector BFLOAT16 Conversion Extension){{$}}
27+
nds.vfncvt.bf16.s v8, v10

llvm/unittests/TargetParser/RISCVISAInfoTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,7 @@ R"(All available -march extensions for RISC-V
11301130
svpbmt 1.0
11311131
svvptc 1.0
11321132
xandesperf 5.0
1133+
xandesvbfhcvt 5.0
11331134
xandesvdot 5.0
11341135
xandesvpackfph 5.0
11351136
xcvalu 1.0

0 commit comments

Comments
 (0)