add fmadds and fmsubs to Power ISA pseudo-code, add unit test (scalar)
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 15 Jun 2021 15:36:59 +0000 (16:36 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 15 Jun 2021 15:36:59 +0000 (16:36 +0100)
openpower/isa/fparith.mdwn
src/openpower/decoder/helpers.py
src/openpower/decoder/isa/test_caller_fp.py
src/openpower/decoder/pseudo/pywriter.py

index 2ce6a2cdbc07b6c21ec3fd5306926a85070fea0b..1c80d0e16330e720ebebb1623e975ea28832203c 100644 (file)
@@ -145,3 +145,40 @@ Special Registers Altered:
     FX OX UX XX
     VXSNAN VXISI
     CR1          (if Rc=1)
+
+# Floating Multiply-Add [Single]
+
+A-Form
+
+* fmadds FRT,FRA,FRC,FRB (Rc=0)
+* fmadds. FRT,FRA,FRC,FRB (Rc=0)
+
+Pseudo-code:
+
+    FRT <- FPMULADD32(FRA, FRC, FRB, 1)
+
+Special Registers Altered:
+
+    FPRF FR FI
+    FX OX UX XX
+    VXSNAN VXISI VXIMZ
+    CR1          (if Rc=1)
+
+# Floating Multiply-Sub [Single]
+
+A-Form
+
+* fmsubs FRT,FRA,FRC,FRB (Rc=0)
+* fmsubs. FRT,FRA,FRC,FRB (Rc=0)
+
+Pseudo-code:
+
+    FRT <- FPMULADD32(FRA, FRC, FRB, -1)
+
+Special Registers Altered:
+
+    FPRF FR FI
+    FX OX UX XX
+    VXSNAN VXISI VXIMZ
+    CR1          (if Rc=1)
+
index e9406070b82cd0ee334893b64fda5022cffd36aa..5440217f9f70be7a3b4d138cd65da4b97b0d4cc0 100644 (file)
@@ -287,6 +287,26 @@ def FPMUL32(FRA, FRB):
     return cvt
 
 
+def FPMULADD32(FRA, FRB, FRC, sign):
+    from openpower.decoder.isafunctions.double2single import DOUBLE2SINGLE
+    #return FPMUL64(FRA, FRB)
+    #FRA = DOUBLE(SINGLE(FRA))
+    #FRB = DOUBLE(SINGLE(FRB))
+    if sign == 1:
+        result = float(FRA) * float(FRB) + float(FRC)
+    elif sign == -1:
+        result = float(FRA) * float(FRB) - float(FRC)
+    elif sign == 0:
+        result = float(FRA) * float(FRB)
+    log ("FPMULADD32", FRA, FRB, FRC,
+                       float(FRA), float(FRB), float(FRC),
+                       result)
+    cvt = fp64toselectable(result)
+    cvt = DOUBLE2SINGLE(cvt)
+    log ("      cvt", cvt)
+    return cvt
+
+
 def FPDIV32(FRA, FRB):
     #return FPDIV64(FRA, FRB)
     #FRA = DOUBLE(SINGLE(FRA))
index bdb9351ebb35b7a55e2f7b29b9f9a82b3c16791c..cc87701a0a0100c9398a754d67a1416db6c2e167 100644 (file)
@@ -211,21 +211,6 @@ class DecoderTestCase(FHDLTestCase):
             self.assertEqual(sim.fpr(2), SelectableInt(0xC02399999999999A, 64))
             self.assertEqual(sim.fpr(3), SelectableInt(0xc051266640000000, 64))
 
-    def test_fp_muls2(self):
-        """>>> lst = ["fmuls 3, 1, 2",
-                     ]
-        """
-        lst = ["fmuls 3, 1, 2", #
-                     ]
-
-        fprs = [0] * 32
-        fprs[1] = 0xbfc4e9d700000000
-        fprs[2] = 0xbdc5000000000000
-
-        with Program(lst, bigendian=False) as program:
-            sim = self.run_tst_program(program, initial_fprs=fprs)
-            self.assertEqual(sim.fpr(3), SelectableInt(0x3d9b72ea40000000, 64))
-
     def test_fp_muls3(self):
         """>>> lst = ["fmuls 3, 1, 2",
                      ]
@@ -289,6 +274,38 @@ class DecoderTestCase(FHDLTestCase):
             self.assertEqual(sim.fpr(2), SelectableInt(0xC02399999999999A, 64))
             self.assertEqual(sim.fpr(3), SelectableInt(0xC051266666666667, 64))
 
+    def test_fp_madd1(self):
+        """>>> lst = ["fmadds 3, 1, 2, 4",
+                     ]
+        """
+        lst = ["fmadds 3, 1, 2, 4", # 7.0 * -9.8 + 2 = -66.6
+                     ]
+
+        fprs = [0] * 32
+        fprs[1] = 0x401C000000000000  # 7.0
+        fprs[2] = 0xC02399999999999A  # -9.8
+        fprs[4] = 0x4000000000000000  # 2.0
+
+        with Program(lst, bigendian=False) as program:
+            sim = self.run_tst_program(program, initial_fprs=fprs)
+            self.assertEqual(sim.fpr(3), SelectableInt(0xC050A66660000000, 64))
+
+    def test_fp_msub1(self):
+        """>>> lst = ["fmsubs 3, 1, 2, 4",
+                     ]
+        """
+        lst = ["fmsubs 3, 1, 2, 4", # 7.0 * -9.8 + 2 = -70.6
+                     ]
+
+        fprs = [0] * 32
+        fprs[1] = 0x401C000000000000  # 7.0
+        fprs[2] = 0xC02399999999999A  # -9.8
+        fprs[4] = 0x4000000000000000  # 2.0
+
+        with Program(lst, bigendian=False) as program:
+            sim = self.run_tst_program(program, initial_fprs=fprs)
+            self.assertEqual(sim.fpr(3), SelectableInt(0xc051a66660000000, 64))
+
     def test_fp_fcfids(self):
         """>>> lst = ["fcfids 1, 2",
                lst = ["fcfids 3, 4",
index 0ba05007be1b6d3439ac0fe4a9f351020c5e983e..766f7929d70f57507e0a7a61ad3ecd3646d917c9 100644 (file)
@@ -40,6 +40,7 @@ from openpower.decoder.helpers import (
                                  DOUBLE, SINGLE,
                                  FPADD32, FPSUB32, FPMUL32, FPDIV32,
                                  FPADD64, FPSUB64, FPMUL64, FPDIV64,
+                                 FPMULADD32,
                                 )
 from openpower.decoder.isafunctions.fpfromint import INT2FP