[Git][ghc/ghc][wip/andreask/riscv_minmax] Add support for fp min/max to riscv
Andreas Klebinger (@AndreasK)
gitlab at gitlab.haskell.org
Mon Sep 30 10:21:36 UTC 2024
Andreas Klebinger pushed to branch wip/andreask/riscv_minmax at Glasgow Haskell Compiler / GHC
Commits:
238d5325 by Andreas Klebinger at 2024-09-30T12:02:21+02:00
Add support for fp min/max to riscv
- - - - -
3 changed files:
- compiler/GHC/CmmToAsm/RV64/CodeGen.hs
- compiler/GHC/CmmToAsm/RV64/Instr.hs
- compiler/GHC/CmmToAsm/RV64/Ppr.hs
Changes:
=====================================
compiler/GHC/CmmToAsm/RV64/CodeGen.hs
=====================================
@@ -1109,6 +1109,8 @@ getRegister' config plat expr =
MO_F_Mul w -> floatOp w (\d x y -> unitOL $ annExpr expr (MUL d x y))
MO_F_Quot w -> floatOp w (\d x y -> unitOL $ annExpr expr (DIV d x y))
-- Floating point comparison
+ MO_F_Min w -> floatOp w (\d x y -> unitOL $ annExpr expr (FMIN d x y))
+ MO_F_Max w -> floatOp w (\d x y -> unitOL $ annExpr expr (FMAX d x y))
MO_F_Eq w -> floatCond w (\d x y -> unitOL $ annExpr expr (CSET d x y EQ))
MO_F_Ne w -> floatCond w (\d x y -> unitOL $ annExpr expr (CSET d x y NE))
MO_F_Ge w -> floatCond w (\d x y -> unitOL $ annExpr expr (CSET d x y FGE))
@@ -2208,6 +2210,8 @@ makeFarBranches {- only used when debugging -} _platform statics basic_blocks =
FENCE {} -> 1
FCVT {} -> 1
FABS {} -> 1
+ FMIN {} -> 1
+ FMAX {} -> 1
FMA {} -> 1
-- estimate the subsituted size for jumps to lables
-- jumps to registers have size 1
=====================================
compiler/GHC/CmmToAsm/RV64/Instr.hs
=====================================
@@ -107,6 +107,8 @@ regUsageOfInstr platform instr = case instr of
FENCE _ _ -> usage ([], [])
FCVT _variant dst src -> usage (regOp src, regOp dst)
FABS dst src -> usage (regOp src, regOp dst)
+ FMIN dst src1 src2 -> usage (regOp src1 ++ regOp src2, regOp dst)
+ FMAX dst src1 src2 -> usage (regOp src1 ++ regOp src2, regOp dst)
FMA _ dst src1 src2 src3 ->
usage (regOp src1 ++ regOp src2 ++ regOp src3, regOp dst)
_ -> panic $ "regUsageOfInstr: " ++ instrCon instr
@@ -203,6 +205,8 @@ patchRegsOfInstr instr env = case instr of
FENCE o1 o2 -> FENCE o1 o2
FCVT variant o1 o2 -> FCVT variant (patchOp o1) (patchOp o2)
FABS o1 o2 -> FABS (patchOp o1) (patchOp o2)
+ FMIN o1 o2 o3 -> FMIN (patchOp o1) (patchOp o2) (patchOp o3)
+ FMAX o1 o2 o3 -> FMAX (patchOp o1) (patchOp o2) (patchOp o3)
FMA s o1 o2 o3 o4 ->
FMA s (patchOp o1) (patchOp o2) (patchOp o3) (patchOp o4)
_ -> panic $ "patchRegsOfInstr: " ++ instrCon instr
@@ -603,6 +607,13 @@ data Instr
FCVT FcvtVariant Operand Operand
| -- | Floating point ABSolute value
FABS Operand Operand
+
+ | -- | Min
+ -- dest = min(r1)
+ FMIN Operand Operand Operand
+ | -- | Max
+ FMAX Operand Operand Operand
+
| -- | Floating-point fused multiply-add instructions
--
-- - fmadd : d = r1 * r2 + r3
@@ -658,6 +669,8 @@ instrCon i =
FENCE {} -> "FENCE"
FCVT {} -> "FCVT"
FABS {} -> "FABS"
+ FMIN {} -> "FMIN"
+ FMAX {} -> "FMAX"
FMA variant _ _ _ _ ->
case variant of
FMAdd -> "FMADD"
=====================================
compiler/GHC/CmmToAsm/RV64/Ppr.hs
=====================================
@@ -666,6 +666,10 @@ pprInstr platform instr = case instr of
$ line (pprOp platform o1 <> text "->" <> pprOp platform o2)
FABS o1 o2 | isSingleOp o2 -> op2 (text "\tfabs.s") o1 o2
FABS o1 o2 | isDoubleOp o2 -> op2 (text "\tfabs.d") o1 o2
+ FMIN o1 o2 o3 | isSingleOp o1 -> op3 (text "\tfmin.s") o1 o2 o3
+ | isDoubleOp o2 -> op3 (text "\tfmin.d") o1 o2 o3
+ FMAX o1 o2 o3 | isSingleOp o1 -> op3 (text "\tfmax.s") o1 o2 o3
+ | isDoubleOp o2 -> op3 (text "\tfmax.d") o1 o2 o3
FMA variant d r1 r2 r3 ->
let fma = case variant of
FMAdd -> text "\tfmadd" <> dot <> floatPrecission d
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/238d5325c561dd276e1217b8edbbec017aef49ae
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/238d5325c561dd276e1217b8edbbec017aef49ae
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240930/b3b9b764/attachment-0001.html>
More information about the ghc-commits
mailing list