2017-12-07 11:26:05 +01:00
|
|
|
//===-- RISCVInstrInfoF.td - RISC-V 'F' instructions -------*- tablegen -*-===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// 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
|
2017-12-07 11:26:05 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file describes the RISC-V instructions from the standard 'F',
|
|
|
|
// Single-Precision Floating-Point instruction set extension.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-01-31 23:48:38 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// RISC-V specific DAG Nodes.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
def SDT_RISCVFMV_W_X_RV64
|
|
|
|
: SDTypeProfile<1, 1, [SDTCisVT<0, f32>, SDTCisVT<1, i64>]>;
|
|
|
|
def SDT_RISCVFMV_X_ANYEXTW_RV64
|
|
|
|
: SDTypeProfile<1, 1, [SDTCisVT<0, i64>, SDTCisVT<1, f32>]>;
|
|
|
|
|
|
|
|
def riscv_fmv_w_x_rv64
|
|
|
|
: SDNode<"RISCVISD::FMV_W_X_RV64", SDT_RISCVFMV_W_X_RV64>;
|
|
|
|
def riscv_fmv_x_anyextw_rv64
|
|
|
|
: SDNode<"RISCVISD::FMV_X_ANYEXTW_RV64", SDT_RISCVFMV_X_ANYEXTW_RV64>;
|
|
|
|
|
2017-12-07 11:26:05 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Operand and SDNode transformation definitions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// Floating-point rounding mode
|
|
|
|
|
|
|
|
def FRMArg : AsmOperandClass {
|
|
|
|
let Name = "FRMArg";
|
|
|
|
let RenderMethod = "addFRMArgOperands";
|
|
|
|
let DiagnosticType = "InvalidFRMArg";
|
|
|
|
}
|
|
|
|
|
|
|
|
def frmarg : Operand<XLenVT> {
|
|
|
|
let ParserMatchClass = FRMArg;
|
|
|
|
let PrintMethod = "printFRMArg";
|
[RISCV] Fix crash in decoding instruction with unknown floating point rounding mode
Summary:
Instead of crashing in printFRMArg, decode and warn about invalid instruction.
This bug was uncovered by a LLVM MC Disassembler Protocol Buffer Fuzzer
for the RISC-V assembly language.
Reviewers: asb
Reviewed By: asb
Subscribers: rbar, johnrusso, simoncook, sabuasal, niosHD, kito-cheng, shiva0217, zzheng, edward-jones, mgrang, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, PkmX, jocewei, asb
Differential Revision: https://reviews.llvm.org/D51705
llvm-svn: 341691
2018-09-07 20:43:43 +02:00
|
|
|
let DecoderMethod = "decodeFRMArg";
|
2017-12-07 11:26:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Instruction class templates
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
|
|
|
|
class FPFMAS_rrr_frm<RISCVOpcode opcode, string opcodestr>
|
|
|
|
: RVInstR4<0b00, opcode, (outs FPR32:$rd),
|
|
|
|
(ins FPR32:$rs1, FPR32:$rs2, FPR32:$rs3, frmarg:$funct3),
|
|
|
|
opcodestr, "$rd, $rs1, $rs2, $rs3, $funct3">;
|
|
|
|
|
|
|
|
class FPFMASDynFrmAlias<FPFMAS_rrr_frm Inst, string OpcodeStr>
|
|
|
|
: InstAlias<OpcodeStr#" $rd, $rs1, $rs2, $rs3",
|
|
|
|
(Inst FPR32:$rd, FPR32:$rs1, FPR32:$rs2, FPR32:$rs3, 0b111)>;
|
|
|
|
|
|
|
|
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
|
|
|
|
class FPALUS_rr<bits<7> funct7, bits<3> funct3, string opcodestr>
|
|
|
|
: RVInstR<funct7, funct3, OPC_OP_FP, (outs FPR32:$rd),
|
2020-02-24 07:21:26 +01:00
|
|
|
(ins FPR32:$rs1, FPR32:$rs2), opcodestr, "$rd, $rs1, $rs2">;
|
2017-12-07 11:26:05 +01:00
|
|
|
|
|
|
|
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
|
|
|
|
class FPALUS_rr_frm<bits<7> funct7, string opcodestr>
|
|
|
|
: RVInstRFrm<funct7, OPC_OP_FP, (outs FPR32:$rd),
|
|
|
|
(ins FPR32:$rs1, FPR32:$rs2, frmarg:$funct3), opcodestr,
|
|
|
|
"$rd, $rs1, $rs2, $funct3">;
|
|
|
|
|
|
|
|
class FPALUSDynFrmAlias<FPALUS_rr_frm Inst, string OpcodeStr>
|
|
|
|
: InstAlias<OpcodeStr#" $rd, $rs1, $rs2",
|
|
|
|
(Inst FPR32:$rd, FPR32:$rs1, FPR32:$rs2, 0b111)>;
|
|
|
|
|
|
|
|
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
|
|
|
|
class FPUnaryOp_r<bits<7> funct7, bits<3> funct3, RegisterClass rdty,
|
|
|
|
RegisterClass rs1ty, string opcodestr>
|
|
|
|
: RVInstR<funct7, funct3, OPC_OP_FP, (outs rdty:$rd), (ins rs1ty:$rs1),
|
|
|
|
opcodestr, "$rd, $rs1">;
|
|
|
|
|
|
|
|
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
|
|
|
|
class FPUnaryOp_r_frm<bits<7> funct7, RegisterClass rdty, RegisterClass rs1ty,
|
|
|
|
string opcodestr>
|
|
|
|
: RVInstRFrm<funct7, OPC_OP_FP, (outs rdty:$rd),
|
|
|
|
(ins rs1ty:$rs1, frmarg:$funct3), opcodestr,
|
|
|
|
"$rd, $rs1, $funct3">;
|
|
|
|
|
|
|
|
class FPUnaryOpDynFrmAlias<FPUnaryOp_r_frm Inst, string OpcodeStr,
|
|
|
|
RegisterClass rdty, RegisterClass rs1ty>
|
|
|
|
: InstAlias<OpcodeStr#" $rd, $rs1",
|
|
|
|
(Inst rdty:$rd, rs1ty:$rs1, 0b111)>;
|
|
|
|
|
|
|
|
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
|
|
|
|
class FPCmpS_rr<bits<3> funct3, string opcodestr>
|
|
|
|
: RVInstR<0b1010000, funct3, OPC_OP_FP, (outs GPR:$rd),
|
2020-01-23 21:51:04 +01:00
|
|
|
(ins FPR32:$rs1, FPR32:$rs2), opcodestr, "$rd, $rs1, $rs2">,
|
|
|
|
Sched<[WriteFCmp32, ReadFCmp32, ReadFCmp32]>;
|
2017-12-07 11:26:05 +01:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Instructions
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
let Predicates = [HasStdExtF] in {
|
|
|
|
let hasSideEffects = 0, mayLoad = 1, mayStore = 0 in
|
|
|
|
def FLW : RVInstI<0b010, OPC_LOAD_FP, (outs FPR32:$rd),
|
|
|
|
(ins GPR:$rs1, simm12:$imm12),
|
2020-01-23 21:51:04 +01:00
|
|
|
"flw", "$rd, ${imm12}(${rs1})">,
|
2020-02-24 07:21:26 +01:00
|
|
|
Sched<[WriteFLD32, ReadFMemBase]>;
|
2017-12-07 11:26:05 +01:00
|
|
|
|
|
|
|
// Operands for stores are in the order srcreg, base, offset rather than
|
|
|
|
// reflecting the order these fields are specified in the instruction
|
|
|
|
// encoding.
|
|
|
|
let hasSideEffects = 0, mayLoad = 0, mayStore = 1 in
|
|
|
|
def FSW : RVInstS<0b010, OPC_STORE_FP, (outs),
|
|
|
|
(ins FPR32:$rs2, GPR:$rs1, simm12:$imm12),
|
2020-01-23 21:51:04 +01:00
|
|
|
"fsw", "$rs2, ${imm12}(${rs1})">,
|
2020-02-24 07:21:26 +01:00
|
|
|
Sched<[WriteFST32, ReadStoreData, ReadFMemBase]>;
|
2017-12-07 11:26:05 +01:00
|
|
|
|
2020-01-23 21:51:04 +01:00
|
|
|
def FMADD_S : FPFMAS_rrr_frm<OPC_MADD, "fmadd.s">,
|
|
|
|
Sched<[WriteFMulAdd32, ReadFMulAdd32, ReadFMulAdd32, ReadFMulAdd32]>;
|
2017-12-07 11:26:05 +01:00
|
|
|
def : FPFMASDynFrmAlias<FMADD_S, "fmadd.s">;
|
2020-01-23 21:51:04 +01:00
|
|
|
def FMSUB_S : FPFMAS_rrr_frm<OPC_MSUB, "fmsub.s">,
|
|
|
|
Sched<[WriteFMulSub32, ReadFMulSub32, ReadFMulSub32, ReadFMulSub32]>;
|
2017-12-07 11:26:05 +01:00
|
|
|
def : FPFMASDynFrmAlias<FMSUB_S, "fmsub.s">;
|
2020-01-23 21:51:04 +01:00
|
|
|
def FNMSUB_S : FPFMAS_rrr_frm<OPC_NMSUB, "fnmsub.s">,
|
|
|
|
Sched<[WriteFMulSub32, ReadFMulSub32, ReadFMulSub32, ReadFMulSub32]>;
|
2017-12-07 11:26:05 +01:00
|
|
|
def : FPFMASDynFrmAlias<FNMSUB_S, "fnmsub.s">;
|
2020-01-23 21:51:04 +01:00
|
|
|
def FNMADD_S : FPFMAS_rrr_frm<OPC_NMADD, "fnmadd.s">,
|
|
|
|
Sched<[WriteFMulAdd32, ReadFMulAdd32, ReadFMulAdd32, ReadFMulAdd32]>;
|
2017-12-07 11:26:05 +01:00
|
|
|
def : FPFMASDynFrmAlias<FNMADD_S, "fnmadd.s">;
|
|
|
|
|
2020-01-23 21:51:04 +01:00
|
|
|
def FADD_S : FPALUS_rr_frm<0b0000000, "fadd.s">,
|
|
|
|
Sched<[WriteFALU32, ReadFALU32, ReadFALU32]>;
|
2017-12-07 11:26:05 +01:00
|
|
|
def : FPALUSDynFrmAlias<FADD_S, "fadd.s">;
|
2020-01-23 21:51:04 +01:00
|
|
|
def FSUB_S : FPALUS_rr_frm<0b0000100, "fsub.s">,
|
|
|
|
Sched<[WriteFALU32, ReadFALU32, ReadFALU32]>;
|
2017-12-07 11:26:05 +01:00
|
|
|
def : FPALUSDynFrmAlias<FSUB_S, "fsub.s">;
|
2020-01-23 21:51:04 +01:00
|
|
|
def FMUL_S : FPALUS_rr_frm<0b0001000, "fmul.s">,
|
|
|
|
Sched<[WriteFMul32, ReadFMul32, ReadFMul32]>;
|
2017-12-07 11:26:05 +01:00
|
|
|
def : FPALUSDynFrmAlias<FMUL_S, "fmul.s">;
|
2020-01-23 21:51:04 +01:00
|
|
|
def FDIV_S : FPALUS_rr_frm<0b0001100, "fdiv.s">,
|
|
|
|
Sched<[WriteFDiv32, ReadFDiv32, ReadFDiv32]>;
|
2017-12-07 11:26:05 +01:00
|
|
|
def : FPALUSDynFrmAlias<FDIV_S, "fdiv.s">;
|
|
|
|
|
2020-01-23 21:51:04 +01:00
|
|
|
def FSQRT_S : FPUnaryOp_r_frm<0b0101100, FPR32, FPR32, "fsqrt.s">,
|
|
|
|
Sched<[WriteFSqrt32, ReadFSqrt32]> {
|
2017-12-07 11:26:05 +01:00
|
|
|
let rs2 = 0b00000;
|
|
|
|
}
|
|
|
|
def : FPUnaryOpDynFrmAlias<FSQRT_S, "fsqrt.s", FPR32, FPR32>;
|
|
|
|
|
2020-02-24 07:21:26 +01:00
|
|
|
def FSGNJ_S : FPALUS_rr<0b0010000, 0b000, "fsgnj.s">,
|
|
|
|
Sched<[WriteFSGNJ32, ReadFSGNJ32, ReadFSGNJ32]>;
|
|
|
|
def FSGNJN_S : FPALUS_rr<0b0010000, 0b001, "fsgnjn.s">,
|
|
|
|
Sched<[WriteFSGNJ32, ReadFSGNJ32, ReadFSGNJ32]>;
|
|
|
|
def FSGNJX_S : FPALUS_rr<0b0010000, 0b010, "fsgnjx.s">,
|
|
|
|
Sched<[WriteFSGNJ32, ReadFSGNJ32, ReadFSGNJ32]>;
|
|
|
|
def FMIN_S : FPALUS_rr<0b0010100, 0b000, "fmin.s">,
|
|
|
|
Sched<[WriteFMinMax32, ReadFMinMax32, ReadFMinMax32]>;
|
|
|
|
def FMAX_S : FPALUS_rr<0b0010100, 0b001, "fmax.s">,
|
|
|
|
Sched<[WriteFMinMax32, ReadFMinMax32, ReadFMinMax32]>;
|
2017-12-07 11:26:05 +01:00
|
|
|
|
2020-01-23 21:51:04 +01:00
|
|
|
def FCVT_W_S : FPUnaryOp_r_frm<0b1100000, GPR, FPR32, "fcvt.w.s">,
|
|
|
|
Sched<[WriteFCvtF32ToI32, ReadFCvtF32ToI32]> {
|
2017-12-07 11:26:05 +01:00
|
|
|
let rs2 = 0b00000;
|
|
|
|
}
|
|
|
|
def : FPUnaryOpDynFrmAlias<FCVT_W_S, "fcvt.w.s", GPR, FPR32>;
|
|
|
|
|
2020-01-23 21:51:04 +01:00
|
|
|
def FCVT_WU_S : FPUnaryOp_r_frm<0b1100000, GPR, FPR32, "fcvt.wu.s">,
|
|
|
|
Sched<[WriteFCvtF32ToI32, ReadFCvtF32ToI32]> {
|
2017-12-07 11:26:05 +01:00
|
|
|
let rs2 = 0b00001;
|
|
|
|
}
|
|
|
|
def : FPUnaryOpDynFrmAlias<FCVT_WU_S, "fcvt.wu.s", GPR, FPR32>;
|
|
|
|
|
2020-01-23 21:51:04 +01:00
|
|
|
def FMV_X_W : FPUnaryOp_r<0b1110000, 0b000, GPR, FPR32, "fmv.x.w">,
|
|
|
|
Sched<[WriteFMovF32ToI32, ReadFMovF32ToI32]> {
|
2017-12-07 11:26:05 +01:00
|
|
|
let rs2 = 0b00000;
|
|
|
|
}
|
|
|
|
|
|
|
|
def FEQ_S : FPCmpS_rr<0b010, "feq.s">;
|
|
|
|
def FLT_S : FPCmpS_rr<0b001, "flt.s">;
|
|
|
|
def FLE_S : FPCmpS_rr<0b000, "fle.s">;
|
|
|
|
|
2020-01-23 21:51:04 +01:00
|
|
|
def FCLASS_S : FPUnaryOp_r<0b1110000, 0b001, GPR, FPR32, "fclass.s">,
|
|
|
|
Sched<[WriteFClass32, ReadFClass32]> {
|
2017-12-07 11:26:05 +01:00
|
|
|
let rs2 = 0b00000;
|
|
|
|
}
|
|
|
|
|
2020-01-23 21:51:04 +01:00
|
|
|
def FCVT_S_W : FPUnaryOp_r_frm<0b1101000, FPR32, GPR, "fcvt.s.w">,
|
|
|
|
Sched<[WriteFCvtI32ToF32, ReadFCvtI32ToF32]> {
|
2017-12-07 11:26:05 +01:00
|
|
|
let rs2 = 0b00000;
|
|
|
|
}
|
|
|
|
def : FPUnaryOpDynFrmAlias<FCVT_S_W, "fcvt.s.w", FPR32, GPR>;
|
|
|
|
|
2020-01-23 21:51:04 +01:00
|
|
|
def FCVT_S_WU : FPUnaryOp_r_frm<0b1101000, FPR32, GPR, "fcvt.s.wu">,
|
|
|
|
Sched<[WriteFCvtI32ToF32, ReadFCvtI32ToF32]> {
|
2017-12-07 11:26:05 +01:00
|
|
|
let rs2 = 0b00001;
|
|
|
|
}
|
|
|
|
def : FPUnaryOpDynFrmAlias<FCVT_S_WU, "fcvt.s.wu", FPR32, GPR>;
|
|
|
|
|
2020-01-23 21:51:04 +01:00
|
|
|
def FMV_W_X : FPUnaryOp_r<0b1111000, 0b000, FPR32, GPR, "fmv.w.x">,
|
|
|
|
Sched<[WriteFMovI32ToF32, ReadFMovI32ToF32]> {
|
2017-12-07 11:26:05 +01:00
|
|
|
let rs2 = 0b00000;
|
|
|
|
}
|
|
|
|
} // Predicates = [HasStdExtF]
|
2017-12-07 12:02:55 +01:00
|
|
|
|
|
|
|
let Predicates = [HasStdExtF, IsRV64] in {
|
2020-01-23 21:51:04 +01:00
|
|
|
def FCVT_L_S : FPUnaryOp_r_frm<0b1100000, GPR, FPR32, "fcvt.l.s">,
|
|
|
|
Sched<[WriteFCvtF32ToI64, ReadFCvtF32ToI64]> {
|
2017-12-07 12:02:55 +01:00
|
|
|
let rs2 = 0b00010;
|
|
|
|
}
|
|
|
|
def : FPUnaryOpDynFrmAlias<FCVT_L_S, "fcvt.l.s", GPR, FPR32>;
|
|
|
|
|
2020-01-23 21:51:04 +01:00
|
|
|
def FCVT_LU_S : FPUnaryOp_r_frm<0b1100000, GPR, FPR32, "fcvt.lu.s">,
|
|
|
|
Sched<[WriteFCvtF32ToI64, ReadFCvtF32ToI64]> {
|
2017-12-07 12:02:55 +01:00
|
|
|
let rs2 = 0b00011;
|
|
|
|
}
|
|
|
|
def : FPUnaryOpDynFrmAlias<FCVT_LU_S, "fcvt.lu.s", GPR, FPR32>;
|
|
|
|
|
2020-01-23 21:51:04 +01:00
|
|
|
def FCVT_S_L : FPUnaryOp_r_frm<0b1101000, FPR32, GPR, "fcvt.s.l">,
|
|
|
|
Sched<[WriteFCvtI64ToF32, ReadFCvtI64ToF32]> {
|
2017-12-07 12:02:55 +01:00
|
|
|
let rs2 = 0b00010;
|
|
|
|
}
|
|
|
|
def : FPUnaryOpDynFrmAlias<FCVT_S_L, "fcvt.s.l", FPR32, GPR>;
|
|
|
|
|
2020-01-23 21:51:04 +01:00
|
|
|
def FCVT_S_LU : FPUnaryOp_r_frm<0b1101000, FPR32, GPR, "fcvt.s.lu">,
|
|
|
|
Sched<[WriteFCvtI64ToF32, ReadFCvtI64ToF32]> {
|
2017-12-07 12:02:55 +01:00
|
|
|
let rs2 = 0b00011;
|
|
|
|
}
|
|
|
|
def : FPUnaryOpDynFrmAlias<FCVT_S_LU, "fcvt.s.lu", FPR32, GPR>;
|
|
|
|
} // Predicates = [HasStdExtF, IsRV64]
|
2017-12-13 12:37:19 +01:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Assembler Pseudo Instructions (User-Level ISA, Version 2.2, Chapter 20)
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
let Predicates = [HasStdExtF] in {
|
2019-02-21 15:09:34 +01:00
|
|
|
def : InstAlias<"flw $rd, (${rs1})", (FLW FPR32:$rd, GPR:$rs1, 0), 0>;
|
|
|
|
def : InstAlias<"fsw $rs2, (${rs1})", (FSW FPR32:$rs2, GPR:$rs1, 0), 0>;
|
|
|
|
|
2017-12-13 12:37:19 +01:00
|
|
|
def : InstAlias<"fmv.s $rd, $rs", (FSGNJ_S FPR32:$rd, FPR32:$rs, FPR32:$rs)>;
|
|
|
|
def : InstAlias<"fabs.s $rd, $rs", (FSGNJX_S FPR32:$rd, FPR32:$rs, FPR32:$rs)>;
|
|
|
|
def : InstAlias<"fneg.s $rd, $rs", (FSGNJN_S FPR32:$rd, FPR32:$rs, FPR32:$rs)>;
|
|
|
|
|
2018-06-20 16:03:02 +02:00
|
|
|
// fgt.s/fge.s are recognised by the GNU assembler but the canonical
|
|
|
|
// flt.s/fle.s forms will always be printed. Therefore, set a zero weight.
|
|
|
|
def : InstAlias<"fgt.s $rd, $rs, $rt",
|
|
|
|
(FLT_S GPR:$rd, FPR32:$rt, FPR32:$rs), 0>;
|
|
|
|
def : InstAlias<"fge.s $rd, $rs, $rt",
|
|
|
|
(FLE_S GPR:$rd, FPR32:$rt, FPR32:$rs), 0>;
|
|
|
|
|
2017-12-13 12:37:19 +01:00
|
|
|
// The following csr instructions actually alias instructions from the base ISA.
|
|
|
|
// However, it only makes sense to support them when the F extension is enabled.
|
|
|
|
// NOTE: "frcsr", "frrm", and "frflags" are more specialized version of "csrr".
|
[RISCV][NFC] Replace hard-coded CSR duplication with symbolic references
Reviewers: asb, lenary
Reviewed By: asb, lenary
Subscribers: MaskRay, hiraditya, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, kito-cheng, shiva0217, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, PkmX, jocewei, psnobl, benna, Jim, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64139
Patch by James Clarke (jrtc27)
llvm-svn: 365195
2019-07-05 14:16:40 +02:00
|
|
|
def : InstAlias<"frcsr $rd", (CSRRS GPR:$rd, FCSR.Encoding, X0), 2>;
|
|
|
|
def : InstAlias<"fscsr $rd, $rs", (CSRRW GPR:$rd, FCSR.Encoding, GPR:$rs)>;
|
|
|
|
def : InstAlias<"fscsr $rs", (CSRRW X0, FCSR.Encoding, GPR:$rs), 2>;
|
|
|
|
|
2019-10-03 17:47:28 +02:00
|
|
|
// frsr, fssr are obsolete aliases replaced by frcsr, fscsr, so give them
|
|
|
|
// zero weight.
|
|
|
|
def : InstAlias<"frsr $rd", (CSRRS GPR:$rd, FCSR.Encoding, X0), 0>;
|
|
|
|
def : InstAlias<"fssr $rd, $rs", (CSRRW GPR:$rd, FCSR.Encoding, GPR:$rs), 0>;
|
|
|
|
def : InstAlias<"fssr $rs", (CSRRW X0, FCSR.Encoding, GPR:$rs), 0>;
|
|
|
|
|
[RISCV][NFC] Replace hard-coded CSR duplication with symbolic references
Reviewers: asb, lenary
Reviewed By: asb, lenary
Subscribers: MaskRay, hiraditya, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, kito-cheng, shiva0217, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, PkmX, jocewei, psnobl, benna, Jim, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64139
Patch by James Clarke (jrtc27)
llvm-svn: 365195
2019-07-05 14:16:40 +02:00
|
|
|
def : InstAlias<"frrm $rd", (CSRRS GPR:$rd, FRM.Encoding, X0), 2>;
|
|
|
|
def : InstAlias<"fsrm $rd, $rs", (CSRRW GPR:$rd, FRM.Encoding, GPR:$rs)>;
|
|
|
|
def : InstAlias<"fsrm $rs", (CSRRW X0, FRM.Encoding, GPR:$rs), 2>;
|
|
|
|
def : InstAlias<"fsrmi $rd, $imm", (CSRRWI GPR:$rd, FRM.Encoding, uimm5:$imm)>;
|
|
|
|
def : InstAlias<"fsrmi $imm", (CSRRWI X0, FRM.Encoding, uimm5:$imm), 2>;
|
|
|
|
|
|
|
|
def : InstAlias<"frflags $rd", (CSRRS GPR:$rd, FFLAGS.Encoding, X0), 2>;
|
|
|
|
def : InstAlias<"fsflags $rd, $rs", (CSRRW GPR:$rd, FFLAGS.Encoding, GPR:$rs)>;
|
|
|
|
def : InstAlias<"fsflags $rs", (CSRRW X0, FFLAGS.Encoding, GPR:$rs), 2>;
|
|
|
|
def : InstAlias<"fsflagsi $rd, $imm", (CSRRWI GPR:$rd, FFLAGS.Encoding, uimm5:$imm)>;
|
|
|
|
def : InstAlias<"fsflagsi $imm", (CSRRWI X0, FFLAGS.Encoding, uimm5:$imm), 2>;
|
2018-06-20 20:42:25 +02:00
|
|
|
|
|
|
|
// fmv.w.x and fmv.x.w were previously known as fmv.s.x and fmv.x.s. Both
|
|
|
|
// spellings should be supported by standard tools.
|
|
|
|
def : MnemonicAlias<"fmv.s.x", "fmv.w.x">;
|
|
|
|
def : MnemonicAlias<"fmv.x.s", "fmv.x.w">;
|
2019-02-20 04:31:32 +01:00
|
|
|
|
|
|
|
def PseudoFLW : PseudoFloatLoad<"flw", FPR32>;
|
|
|
|
def PseudoFSW : PseudoStore<"fsw", FPR32>;
|
2017-12-13 12:37:19 +01:00
|
|
|
} // Predicates = [HasStdExtF]
|
2018-03-20 13:45:35 +01:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Pseudo-instructions and codegen patterns
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-03-20 10:22:48 +01:00
|
|
|
/// Floating point constants
|
|
|
|
def fpimm0 : PatLeaf<(fpimm), [{ return N->isExactlyValue(+0.0); }]>;
|
|
|
|
|
2018-03-20 13:45:35 +01:00
|
|
|
/// Generic pattern classes
|
|
|
|
class PatFpr32Fpr32<SDPatternOperator OpNode, RVInstR Inst>
|
|
|
|
: Pat<(OpNode FPR32:$rs1, FPR32:$rs2), (Inst $rs1, $rs2)>;
|
|
|
|
|
|
|
|
class PatFpr32Fpr32DynFrm<SDPatternOperator OpNode, RVInstRFrm Inst>
|
|
|
|
: Pat<(OpNode FPR32:$rs1, FPR32:$rs2), (Inst $rs1, $rs2, 0b111)>;
|
|
|
|
|
|
|
|
let Predicates = [HasStdExtF] in {
|
|
|
|
|
2020-03-20 10:22:48 +01:00
|
|
|
/// Float constants
|
|
|
|
def : Pat<(f32 (fpimm0)), (FMV_W_X X0)>;
|
|
|
|
|
2018-03-20 13:45:35 +01:00
|
|
|
/// Float conversion operations
|
|
|
|
|
2018-10-03 13:35:22 +02:00
|
|
|
// [u]int32<->float conversion patterns must be gated on IsRV32 or IsRV64, so
|
|
|
|
// are defined later.
|
2018-03-20 13:45:35 +01:00
|
|
|
|
|
|
|
/// Float arithmetic operations
|
|
|
|
|
|
|
|
def : PatFpr32Fpr32DynFrm<fadd, FADD_S>;
|
|
|
|
def : PatFpr32Fpr32DynFrm<fsub, FSUB_S>;
|
|
|
|
def : PatFpr32Fpr32DynFrm<fmul, FMUL_S>;
|
|
|
|
def : PatFpr32Fpr32DynFrm<fdiv, FDIV_S>;
|
|
|
|
|
|
|
|
def : Pat<(fsqrt FPR32:$rs1), (FSQRT_S FPR32:$rs1, 0b111)>;
|
|
|
|
|
|
|
|
def : Pat<(fneg FPR32:$rs1), (FSGNJN_S $rs1, $rs1)>;
|
|
|
|
def : Pat<(fabs FPR32:$rs1), (FSGNJX_S $rs1, $rs1)>;
|
|
|
|
|
|
|
|
def : PatFpr32Fpr32<fcopysign, FSGNJ_S>;
|
|
|
|
def : Pat<(fcopysign FPR32:$rs1, (fneg FPR32:$rs2)), (FSGNJN_S $rs1, $rs2)>;
|
|
|
|
|
[RISCV] Add support for the various RISC-V FMA instruction variants
Adds support for the various RISC-V FMA instructions (fmadd, fmsub, fnmsub, fnmadd).
The criteria for choosing whether a fused add or subtract is used, as well as
whether the product is negated or not, is whether some of the arguments to the
llvm.fma.* intrinsic are negated or not. In the tests, extraneous fadd
instructions were added to avoid the negation being performed using a xor
trick, which prevented the proper FMA forms from being selected and thus
tested.
The FMA instruction patterns might seem incorrect (e.g., fnmadd: -rs1 * rs2 -
rs3), but they should be correct. The misleading names were inherited from
MIPS, where the negation happens after computing the sum.
The llvm.fmuladd.* intrinsics still do not generate RISC-V FMA instructions,
as that depends on TargetLowering::isFMAFasterthanFMulAndFAdd.
Some comments in the test files about what type of instructions are there
tested were updated, to better reflect the current content of those test
files.
Differential Revision: https://reviews.llvm.org/D54205
Patch by Luís Marques.
llvm-svn: 349023
2018-12-13 11:49:05 +01:00
|
|
|
// fmadd: rs1 * rs2 + rs3
|
|
|
|
def : Pat<(fma FPR32:$rs1, FPR32:$rs2, FPR32:$rs3),
|
|
|
|
(FMADD_S $rs1, $rs2, $rs3, 0b111)>;
|
|
|
|
|
|
|
|
// fmsub: rs1 * rs2 - rs3
|
|
|
|
def : Pat<(fma FPR32:$rs1, FPR32:$rs2, (fneg FPR32:$rs3)),
|
|
|
|
(FMSUB_S FPR32:$rs1, FPR32:$rs2, FPR32:$rs3, 0b111)>;
|
|
|
|
|
|
|
|
// fnmsub: -rs1 * rs2 + rs3
|
|
|
|
def : Pat<(fma (fneg FPR32:$rs1), FPR32:$rs2, FPR32:$rs3),
|
|
|
|
(FNMSUB_S FPR32:$rs1, FPR32:$rs2, FPR32:$rs3, 0b111)>;
|
|
|
|
|
|
|
|
// fnmadd: -rs1 * rs2 - rs3
|
|
|
|
def : Pat<(fma (fneg FPR32:$rs1), FPR32:$rs2, (fneg FPR32:$rs3)),
|
|
|
|
(FNMADD_S FPR32:$rs1, FPR32:$rs2, FPR32:$rs3, 0b111)>;
|
|
|
|
|
2018-03-20 13:45:35 +01:00
|
|
|
// The RISC-V 2.2 user-level ISA spec defines fmin and fmax as returning the
|
|
|
|
// canonical NaN when given a signaling NaN. This doesn't match the LLVM
|
|
|
|
// behaviour (see https://bugs.llvm.org/show_bug.cgi?id=27363). However, the
|
|
|
|
// draft 2.3 ISA spec changes the definition of fmin and fmax in a way that
|
|
|
|
// matches LLVM's fminnum and fmaxnum
|
|
|
|
// <https://github.com/riscv/riscv-isa-manual/commit/cd20cee7efd9bac7c5aa127ec3b451749d2b3cce>.
|
|
|
|
def : PatFpr32Fpr32<fminnum, FMIN_S>;
|
|
|
|
def : PatFpr32Fpr32<fmaxnum, FMAX_S>;
|
|
|
|
|
2018-03-21 16:11:02 +01:00
|
|
|
/// Setcc
|
|
|
|
|
|
|
|
def : PatFpr32Fpr32<seteq, FEQ_S>;
|
2018-03-20 13:45:35 +01:00
|
|
|
def : PatFpr32Fpr32<setoeq, FEQ_S>;
|
2018-03-21 16:11:02 +01:00
|
|
|
def : PatFpr32Fpr32<setlt, FLT_S>;
|
2018-03-20 13:45:35 +01:00
|
|
|
def : PatFpr32Fpr32<setolt, FLT_S>;
|
2018-03-21 16:11:02 +01:00
|
|
|
def : PatFpr32Fpr32<setle, FLE_S>;
|
2018-03-20 13:45:35 +01:00
|
|
|
def : PatFpr32Fpr32<setole, FLE_S>;
|
2018-03-20 14:26:12 +01:00
|
|
|
|
2018-03-21 16:11:02 +01:00
|
|
|
def Select_FPR32_Using_CC_GPR : SelectCC_rrirr<FPR32, GPR>;
|
|
|
|
|
2018-03-20 14:26:12 +01:00
|
|
|
/// Loads
|
|
|
|
|
|
|
|
defm : LdPat<load, FLW>;
|
|
|
|
|
|
|
|
/// Stores
|
|
|
|
|
|
|
|
defm : StPat<store, FSW, FPR32>;
|
|
|
|
|
2018-03-20 13:45:35 +01:00
|
|
|
} // Predicates = [HasStdExtF]
|
2018-10-03 13:35:22 +02:00
|
|
|
|
|
|
|
let Predicates = [HasStdExtF, IsRV32] in {
|
2020-12-03 19:29:10 +01:00
|
|
|
// Moves (no conversion)
|
2020-11-06 00:44:49 +01:00
|
|
|
def : Pat<(bitconvert GPR:$rs1), (FMV_W_X GPR:$rs1)>;
|
|
|
|
def : Pat<(bitconvert FPR32:$rs1), (FMV_X_W FPR32:$rs1)>;
|
|
|
|
|
2018-10-03 13:35:22 +02:00
|
|
|
// float->[u]int. Round-to-zero must be used.
|
|
|
|
def : Pat<(fp_to_sint FPR32:$rs1), (FCVT_W_S $rs1, 0b001)>;
|
|
|
|
def : Pat<(fp_to_uint FPR32:$rs1), (FCVT_WU_S $rs1, 0b001)>;
|
|
|
|
|
|
|
|
// [u]int->float. Match GCC and default to using dynamic rounding mode.
|
|
|
|
def : Pat<(sint_to_fp GPR:$rs1), (FCVT_S_W $rs1, 0b111)>;
|
|
|
|
def : Pat<(uint_to_fp GPR:$rs1), (FCVT_S_WU $rs1, 0b111)>;
|
|
|
|
} // Predicates = [HasStdExtF, IsRV32]
|
2019-01-31 23:48:38 +01:00
|
|
|
|
|
|
|
let Predicates = [HasStdExtF, IsRV64] in {
|
2020-12-03 19:29:10 +01:00
|
|
|
// Moves (no conversion)
|
2019-01-31 23:48:38 +01:00
|
|
|
def : Pat<(riscv_fmv_w_x_rv64 GPR:$src), (FMV_W_X GPR:$src)>;
|
|
|
|
def : Pat<(riscv_fmv_x_anyextw_rv64 FPR32:$src), (FMV_X_W FPR32:$src)>;
|
2020-11-27 20:11:41 +01:00
|
|
|
def : Pat<(sext_inreg (riscv_fmv_x_anyextw_rv64 FPR32:$src), i32),
|
2019-01-31 23:48:38 +01:00
|
|
|
(FMV_X_W FPR32:$src)>;
|
|
|
|
|
|
|
|
// FP->[u]int32 is mostly handled by the FP->[u]int64 patterns. This is safe
|
|
|
|
// because fpto[u|s]i produces poison if the value can't fit into the target.
|
|
|
|
// We match the single case below because fcvt.wu.s sign-extends its result so
|
|
|
|
// is cheaper than fcvt.lu.s+sext.w.
|
|
|
|
def : Pat<(sext_inreg (assertzexti32 (fp_to_uint FPR32:$rs1)), i32),
|
|
|
|
(FCVT_WU_S $rs1, 0b001)>;
|
|
|
|
|
|
|
|
// FP->[u]int64
|
|
|
|
def : Pat<(fp_to_sint FPR32:$rs1), (FCVT_L_S $rs1, 0b001)>;
|
|
|
|
def : Pat<(fp_to_uint FPR32:$rs1), (FCVT_LU_S $rs1, 0b001)>;
|
|
|
|
|
|
|
|
// [u]int->fp. Match GCC and default to using dynamic rounding mode.
|
2020-12-05 03:36:14 +01:00
|
|
|
def : Pat<(sint_to_fp (sexti32 GPR:$rs1)), (FCVT_S_W $rs1, 0b111)>;
|
2019-01-31 23:48:38 +01:00
|
|
|
def : Pat<(uint_to_fp (zexti32 GPR:$rs1)), (FCVT_S_WU $rs1, 0b111)>;
|
|
|
|
def : Pat<(sint_to_fp GPR:$rs1), (FCVT_S_L $rs1, 0b111)>;
|
|
|
|
def : Pat<(uint_to_fp GPR:$rs1), (FCVT_S_LU $rs1, 0b111)>;
|
|
|
|
} // Predicates = [HasStdExtF, IsRV64]
|