Skip to content

[RISCV][MC] Add Q support for Zfa #139508

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 4 commits into from
May 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions llvm/lib/Target/RISCV/RISCVInstrInfoZfa.td
Original file line number Diff line number Diff line change
@@ -175,6 +175,28 @@ def FLEQ_H : FPCmp_rr<0b1010010, 0b100, "fleq.h", FPR16>;
}
} // Predicates = [HasStdExtZfa, HasStdExtZfh]

let Predicates = [HasStdExtZfa, HasStdExtQ] in {
let isReMaterializable = 1, isAsCheapAsAMove = 1 in
def FLI_Q : FPFLI_r<0b1111011, 0b00001, 0b000, FPR128, "fli.q">;

def FMINM_Q: FPALU_rr<0b0010111, 0b010, "fminm.q", FPR128, Commutable=1>;
def FMAXM_Q: FPALU_rr<0b0010111, 0b011, "fmaxm.q", FPR128, Commutable=1>;

def FROUND_Q : FPUnaryOp_r_frm<0b0100011, 0b00100, FPR128, FPR128, "fround.q">;
def FROUNDNX_Q : FPUnaryOp_r_frm<0b0100011, 0b00101, FPR128, FPR128,
"froundnx.q">;

def FLTQ_Q : FPCmp_rr<0b1010011, 0b101, "fltq.q", FPR128>;
def FLEQ_Q : FPCmp_rr<0b1010011, 0b100, "fleq.q", FPR128>;
} // Predicates = [HasStdExtZfa, HasStdExtQ]

let Predicates = [HasStdExtZfa, HasStdExtQ, IsRV64] in {
let mayRaiseFPException = 0 in {
def FMVH_X_Q : FPUnaryOp_r<0b1110011, 0b00001, 0b000, GPR, FPR128, "fmvh.x.q">;
def FMVP_Q_X : FPBinaryOp_rr<0b1011011, 0b000, FPR128, GPR, "fmvp.q.x">;
}
} // Predicates = [HasStdExtZfa, HasStdExtQ, IsRV64]

//===----------------------------------------------------------------------===//
// Pseudo-instructions and codegen patterns
//===----------------------------------------------------------------------===//
@@ -200,6 +222,13 @@ def : InstAlias<"fgeq.h $rd, $rs, $rt",
(FLEQ_H GPR:$rd, FPR16:$rt, FPR16:$rs), 0>;
}

let Predicates = [HasStdExtZfa, HasStdExtQ] in {
def : InstAlias<"fgtq.q $rd, $rs, $rt",
(FLTQ_Q GPR:$rd, FPR128:$rt, FPR128:$rs), 0>;
def : InstAlias<"fgeq.q $rd, $rs, $rt",
(FLEQ_Q GPR:$rd, FPR128:$rt, FPR128:$rs), 0>;
}

//===----------------------------------------------------------------------===//
// Codegen patterns
//===----------------------------------------------------------------------===//
19 changes: 19 additions & 0 deletions llvm/test/MC/RISCV/rv64zfa-only-valid.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# RUN: llvm-mc %s -triple=riscv64 -mattr=+zfa,+q,+zfh -M no-aliases -show-encoding \
# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+zfa,+q,+zfh < %s \
# RUN: | llvm-objdump --mattr=+zfa,+q,+zfh -M no-aliases -d -r - \
# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
#
# RUN: not llvm-mc -triple riscv64 -mattr=+q,+zfh \
# RUN: -M no-aliases -show-encoding < %s 2>&1 \
# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s

# CHECK-ASM-AND-OBJ: fmvh.x.q a1, fs1
# CHECK-ASM: encoding: [0xd3,0x85,0x14,0xe6]
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
fmvh.x.q a1, fs1

# CHECK-ASM-AND-OBJ: fmvp.q.x fs1, a1, a2
# CHECK-ASM: encoding: [0xd3,0x84,0xc5,0xb6]
# CHECK-NO-EXT: error: instruction requires the following: 'Zfa' (Additional Floating-Point){{$}}
fmvp.q.x fs1, a1, a2
13 changes: 11 additions & 2 deletions llvm/test/MC/RISCV/zfa-invalid.s
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RUN: not llvm-mc -triple riscv64 -mattr=+zfa,+d,+zfh < %s 2>&1 | FileCheck -check-prefixes=CHECK-NO-RV32 %s
# RUN: not llvm-mc -triple riscv32 -mattr=+zfa,+d,+zfh < %s 2>&1 | FileCheck -check-prefixes=CHECK-NO-RV64 %s
# RUN: not llvm-mc -triple riscv64 -mattr=+zfa,+q,+zfh < %s 2>&1 | FileCheck -check-prefixes=CHECK-NO-RV32 %s
# RUN: not llvm-mc -triple riscv32 -mattr=+zfa,+q,+zfh < %s 2>&1 | FileCheck -check-prefixes=CHECK-NO-RV64 %s

# Invalid rounding modes
# CHECK-NO-RV64: error: operand must be 'rtz' floating-point rounding mode
@@ -35,6 +35,10 @@ fli.d ft1, 3.560000e+02
# CHECK-NO-RV32: error: operand must be a valid floating-point constant
fli.h ft1, 1.600000e+00

# CHECK-NO-RV64: error: operand must be a valid floating-point constant
# CHECK-NO-RV32: error: operand must be a valid floating-point constant
fli.q ft1, 2.250000e+00

# CHECK-NO-RV64: error: invalid floating point immediate
# CHECK-NO-RV32: error: invalid floating point immediate
fli.s ft1, -min
@@ -72,6 +76,11 @@ fli.d ft1, 1.1754943508222875079687365372222456778186655567720875215087517062784
# CHECK-NO-RV32: error: operand must be a valid floating-point constant
fli.h ft1, 1.1754943508222875079687365372222456778186655567720875215087517062784172594547271728515625e-38

# Don't accept single precision minimum for quad.
# CHECK-NO-RV64: error: operand must be a valid floating-point constant
# CHECK-NO-RV32: error: operand must be a valid floating-point constant
fli.q ft1, 1.1754943508222875079687365372222456778186655567720875215087517062784172594547271728515625e-38

# Don't accept integers.
# CHECK-NO-RV32: error: invalid floating point immediate
# CHECK-NO-RV64: error: invalid floating point immediate
42 changes: 42 additions & 0 deletions llvm/test/MC/RISCV/zfa-quad-invalid.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# RUN: not llvm-mc -triple riscv32 -mattr=+zfa,+zfh \
# RUN: -M no-aliases -show-encoding < %s 2>&1 \
# RUN: | FileCheck -check-prefixes=CHECK-NO-EXTQ %s
# RUN: not llvm-mc -triple riscv64 -mattr=+zfa,+zfh \
# RUN: -M no-aliases -show-encoding < %s 2>&1 \
# RUN: | FileCheck -check-prefixes=CHECK-NO-EXTQ %s

# CHECK-NO-EXTQ: error: instruction requires the following: 'Q' (Quad-Precision Floating-Point){{$}}
fminm.q fa0, fa1, fa2

# CHECK-NO-EXTQ: error: instruction requires the following: 'Q' (Quad-Precision Floating-Point){{$}}
fmaxm.q fs3, fs4, fs5

# CHECK-NO-EXTQ: error: instruction requires the following: 'Q' (Quad-Precision Floating-Point){{$}}
fround.q fs1, fs2

# CHECK-NO-EXTQ: error: instruction requires the following: 'Q' (Quad-Precision Floating-Point){{$}}
fround.q fs1, fs2, dyn

# CHECK-NO-EXTQ: error: instruction requires the following: 'Q' (Quad-Precision Floating-Point){{$}}
fround.q fs1, fs2, rtz

# CHECK-NO-EXTQ: error: instruction requires the following: 'Q' (Quad-Precision Floating-Point){{$}}
fround.q fs1, fs2, rne

# CHECK-NO-EXTQ: error: instruction requires the following: 'Q' (Quad-Precision Floating-Point){{$}}
froundnx.q fs1, fs2

# CHECK-NO-EXTQ: error: instruction requires the following: 'Q' (Quad-Precision Floating-Point){{$}}
froundnx.q fs1, fs2, dyn

# CHECK-NO-EXTQ: error: instruction requires the following: 'Q' (Quad-Precision Floating-Point){{$}}
froundnx.q fs1, fs2, rtz

# CHECK-NO-EXTQ: error: instruction requires the following: 'Q' (Quad-Precision Floating-Point){{$}}
froundnx.q fs1, fs2, rne

# CHECK-NO-EXTQ: error: instruction requires the following: 'Q' (Quad-Precision Floating-Point){{$}}
fltq.q a1, fs1, fs2

# CHECK-NO-EXTQ: error: instruction requires the following: 'Q' (Quad-Precision Floating-Point){{$}}
fleq.q a1, ft1, ft2
Loading
Loading