Skip to content

Commit

Permalink
dialects: (riscv) add double-precision fmadd and fmsub (#1790)
Browse files Browse the repository at this point in the history
  • Loading branch information
superlopuh authored Nov 16, 2023
1 parent e041198 commit 4b87e5b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/filecheck/dialects/riscv/riscv_assembly_emission.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@
riscv.fsd %0, %f0, 1 : (!riscv.reg<zero>, !riscv.freg<j5>) -> ()
// CHECK-NEXT: fsd j5, 1(zero)

%fmadd_d = riscv.fmadd.d %f0, %f1, %f2 : (!riscv.freg<j5>, !riscv.freg<j6>, !riscv.freg<j7>) -> !riscv.freg<j8>
// CHECK-NEXT: fmadd.d j8, j5, j6, j7
%fmsub_d = riscv.fmsub.d %f0, %f1, %f2 : (!riscv.freg<j5>, !riscv.freg<j6>, !riscv.freg<j7>) -> !riscv.freg<j8>
// CHECK-NEXT: fmsub.d j8, j5, j6, j7
%fadd_d= riscv.fadd.d %f0, %f1 : (!riscv.freg<j5>, !riscv.freg<j6>) -> !riscv.freg<j8>
// CHECK-NEXT: fadd.d j8, j5, j6
%fsub_d = riscv.fsub.d %f0, %f1 : (!riscv.freg<j5>, !riscv.freg<j6>) -> !riscv.freg<j8>
Expand Down
7 changes: 7 additions & 0 deletions tests/filecheck/dialects/riscv/riscv_ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@

// RV32F: 9 “D” Standard Extension for Single-Precision Floating-Point, Version 2.0

%fmadd_d = riscv.fmadd.d %f0, %f1, %f2 : (!riscv.freg<>, !riscv.freg<>, !riscv.freg<>) -> !riscv.freg<>
// CHECK-NEXT: %{{.*}} = riscv.fmadd.d %{{.*}}, %{{.*}}, %{{.*}} : (!riscv.freg<>, !riscv.freg<>, !riscv.freg<>) -> !riscv.freg<>
%fmsub_d = riscv.fmsub.d %f0, %f1, %f2 : (!riscv.freg<>, !riscv.freg<>, !riscv.freg<>) -> !riscv.freg<>
// CHECK-NEXT: %{{.*}} = riscv.fmsub.d %{{.*}}, %{{.*}}, %{{.*}} : (!riscv.freg<>, !riscv.freg<>, !riscv.freg<>) -> !riscv.freg<>

%fmin_d = riscv.fmin.d %f0, %f1 : (!riscv.freg<>, !riscv.freg<>) -> !riscv.freg<>
// CHECK-NEXT: %{{.*}} = riscv.fmin.d %{{.*}}, %{{.*}} : (!riscv.freg<>, !riscv.freg<>) -> !riscv.freg<>
%fmax_d = riscv.fmax.d %f0, %f1 : (!riscv.freg<>, !riscv.freg<>) -> !riscv.freg<>
Expand Down Expand Up @@ -418,6 +423,8 @@
// CHECK-GENERIC-NEXT: "riscv.fsd"(%0, %f0) {"immediate" = 1 : si12} : (!riscv.reg<>, !riscv.freg<>) -> ()
// CHECK-GENERIC-NEXT: %vfadd_s = "riscv.vfadd.s"(%f0, %f1) : (!riscv.freg<>, !riscv.freg<>) -> !riscv.freg<>
// CHECK-GENERIC-NEXT: %vfmul_s = "riscv.vfmul.s"(%f0, %f1) : (!riscv.freg<>, !riscv.freg<>) -> !riscv.freg<>
// CHECK-GENERIC-NEXT: %fmadd_d = "riscv.fmadd.d"(%f0, %f1, %f2) : (!riscv.freg<>, !riscv.freg<>, !riscv.freg<>) -> !riscv.freg<>
// CHECK-GENERIC-NEXT: %fmsub_d = "riscv.fmsub.d"(%f0, %f1, %f2) : (!riscv.freg<>, !riscv.freg<>, !riscv.freg<>) -> !riscv.freg<>
// CHECK-GENERIC-NEXT: %fmin_d = "riscv.fmin.d"(%f0, %f1) : (!riscv.freg<>, !riscv.freg<>) -> !riscv.freg<>
// CHECK-GENERIC-NEXT: %fmax_d = "riscv.fmax.d"(%f0, %f1) : (!riscv.freg<>, !riscv.freg<>) -> !riscv.freg<>
// CHECK-GENERIC-NEXT: %{{.*}} = "riscv.fcvt.d.w"(%{{.*}}) : (!riscv.reg<>) -> !riscv.freg<>
Expand Down
32 changes: 32 additions & 0 deletions xdsl/dialects/riscv.py
Original file line number Diff line number Diff line change
Expand Up @@ -3357,6 +3357,36 @@ def assembly_line(self) -> str | None:
# region RV32F: 9 “D” Standard Extension for Double-Precision Floating-Point, Version 2.0


@irdl_op_definition
class FMAddDOp(RdRsRsRsFloatOperation):
"""
Perform double-precision fused multiply addition.
f[rd] = f[rs1]×f[rs2]+f[rs3]
https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fmadd-d
"""

name = "riscv.fmadd.d"

traits = frozenset((Pure(),))


@irdl_op_definition
class FMSubDOp(RdRsRsRsFloatOperation):
"""
Perform double-precision fused multiply substraction.
f[rd] = f[rs1]×f[rs2]+f[rs3]
https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fmsub-d
"""

name = "riscv.fmsub.d"

traits = frozenset((Pure(),))


@irdl_op_definition
class FAddDOp(RdRsRsOperation[FloatRegisterType, FloatRegisterType, FloatRegisterType]):
"""
Expand Down Expand Up @@ -3715,6 +3745,8 @@ def _print_immediate_value(printer: Printer, immediate: AnyIntegerAttr | LabelAt
FMvWXOp,
FLwOp,
FSwOp,
FMAddDOp,
FMSubDOp,
FAddDOp,
FSubDOp,
FMulDOp,
Expand Down

0 comments on commit 4b87e5b

Please sign in to comment.