Skip to contentSkip to conversation

MIPS: math-emu: Add madd/msub/nmadd/nmsub emulation for Loongson-3

PATCH New Huacai Chen 1 participant 1 message Feb 6, 2019 MIPS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MIPS: math-emu: Add madd/msub/nmadd/nmsub emulation for Loongson-3

Add madd.s/madd.d/msub.s/msub.d/nmadd.s/nmadd.d/nmsub.s/nmsub.d emulation for Loongson-3. MIPS R2 suggest these instructions be unfused, but Loongson-3 suggest these instructions be fused, which is similar to maddf/msubf in MIPS R6.

---
 arch/mips/math-emu/cp1emu.c     | 32 +++++++++++++++++++++++++
 arch/mips/math-emu/dp_maddf.c   | 53 +++++++++++++++++++++++++++--------------
 arch/mips/math-emu/ieee754.h    | 16 +++++++++++++
 arch/mips/math-emu/ieee754int.h |  1 +
 arch/mips/math-emu/sp_maddf.c   | 53 +++++++++++++++++++++++++++--------------
 5 files changed, 119 insertions(+), 36 deletions(-)
arch/mips/math-emu/cp1emu.c +32 -0
index e60e290..2f99ec2 100644
@@ -1463,6 +1463,7 @@ static union ieee754sp fpemu_sp_rsqrt(union ieee754sp s)
 	return ieee754sp_div(ieee754sp_one(0), ieee754sp_sqrt(s));
 }
 
+#ifndef CONFIG_CPU_LOONGSON3
 DEF3OP(madd, sp, ieee754sp_mul, ieee754sp_add, );
 DEF3OP(msub, sp, ieee754sp_mul, ieee754sp_sub, );
 DEF3OP(nmadd, sp, ieee754sp_mul, ieee754sp_add, ieee754sp_neg);
@@ -1471,6 +1472,7 @@ DEF3OP(madd, dp, ieee754dp_mul, ieee754dp_add, );
 DEF3OP(msub, dp, ieee754dp_mul, ieee754dp_sub, );
 DEF3OP(nmadd, dp, ieee754dp_mul, ieee754dp_add, ieee754dp_neg);
 DEF3OP(nmsub, dp, ieee754dp_mul, ieee754dp_sub, ieee754dp_neg);
+#endif
 
 static int fpux_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
 	mips_instruction ir, void __user **fault_addr)
@@ -1525,6 +1527,20 @@ static int fpux_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
 			}
 			break;
 
+#ifdef CONFIG_CPU_LOONGSON3
+		case madd_s_op:
+			handler = ieee754sp_madd;
+			goto scoptop;
+		case msub_s_op:
+			handler = ieee754sp_msub;
+			goto scoptop;
+		case nmadd_s_op:
+			handler = ieee754sp_nmadd;
+			goto scoptop;
+		case nmsub_s_op:
+			handler = ieee754sp_nmsub;
+			goto scoptop;
+#else
 		case madd_s_op:
 			handler = fpemu_sp_madd;
 			goto scoptop;
@@ -1537,6 +1553,7 @@ static int fpux_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
 		case nmsub_s_op:
 			handler = fpemu_sp_nmsub;
 			goto scoptop;
+#endif
 
 		      scoptop:
 			SPFROMREG(fr, MIPSInst_FR(ir));
@@ -1621,6 +1638,20 @@ static int fpux_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
 			}
 			break;
 
+#ifdef CONFIG_CPU_LOONGSON3
+		case madd_d_op:
+			handler = ieee754dp_madd;
+			goto dcoptop;
+		case msub_d_op:
+			handler = ieee754dp_msub;
+			goto dcoptop;
+		case nmadd_d_op:
+			handler = ieee754dp_nmadd;
+			goto dcoptop;
+		case nmsub_d_op:
+			handler = ieee754dp_nmsub;
+			goto dcoptop;
+#else
 		case madd_d_op:
 			handler = fpemu_dp_madd;
 			goto dcoptop;
@@ -1633,6 +1664,7 @@ static int fpux_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
 		case nmsub_d_op:
 			handler = fpemu_dp_nmsub;
 			goto dcoptop;
+#endif
 
 		      dcoptop:
 			DPFROMREG(fr, MIPSInst_FR(ir));
arch/mips/math-emu/dp_maddf.c +35 -18

87 lines not on this page · raw message

arch/mips/math-emu/ieee754.h +16 -0
index e0eb7a9..e12bb9f 100644
@@ -80,6 +80,14 @@ union ieee754sp ieee754sp_maddf(union ieee754sp z, union ieee754sp x,
 				union ieee754sp y);
 union ieee754sp ieee754sp_msubf(union ieee754sp z, union ieee754sp x,
 				union ieee754sp y);
+union ieee754sp ieee754sp_madd(union ieee754sp z, union ieee754sp x,
+				union ieee754sp y);
+union ieee754sp ieee754sp_msub(union ieee754sp z, union ieee754sp x,
+				union ieee754sp y);
+union ieee754sp ieee754sp_nmadd(union ieee754sp z, union ieee754sp x,
+				union ieee754sp y);
+union ieee754sp ieee754sp_nmsub(union ieee754sp z, union ieee754sp x,
+				union ieee754sp y);
 int ieee754sp_2008class(union ieee754sp x);
 union ieee754sp ieee754sp_fmin(union ieee754sp x, union ieee754sp y);
 union ieee754sp ieee754sp_fmina(union ieee754sp x, union ieee754sp y);
@@ -115,6 +123,14 @@ union ieee754dp ieee754dp_maddf(union ieee754dp z, union ieee754dp x,
 				union ieee754dp y);
 union ieee754dp ieee754dp_msubf(union ieee754dp z, union ieee754dp x,
 				union ieee754dp y);
+union ieee754dp ieee754dp_madd(union ieee754dp z, union ieee754dp x,
+				union ieee754dp y);
+union ieee754dp ieee754dp_msub(union ieee754dp z, union ieee754dp x,
+				union ieee754dp y);
+union ieee754dp ieee754dp_nmadd(union ieee754dp z, union ieee754dp x,
+				union ieee754dp y);
+union ieee754dp ieee754dp_nmsub(union ieee754dp z, union ieee754dp x,
+				union ieee754dp y);
 int ieee754dp_2008class(union ieee754dp x);
 union ieee754dp ieee754dp_fmin(union ieee754dp x, union ieee754dp y);
 union ieee754dp ieee754dp_fmina(union ieee754dp x, union ieee754dp y);
arch/mips/math-emu/ieee754int.h +1 -0
index 06ac0e2..302815c 100644
@@ -28,6 +28,7 @@
 
 enum maddf_flags {
 	MADDF_NEGATE_PRODUCT	= 1 << 0,
+	MADDF_NEGATE_ADDITION	= 1 << 1,
 };
 
 static inline void ieee754_clearcx(void)
arch/mips/math-emu/sp_maddf.c +35 -18

87 lines not on this page · raw message

Signature · 1 line
2.7.0