auto-compute FPSCR exception summary bits
authorJacob Lifshay <programmerjake@gmail.com>
Tue, 16 May 2023 04:34:20 +0000 (21:34 -0700)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 2 Jun 2023 18:51:18 +0000 (19:51 +0100)
src/openpower/fpscr.py
src/openpower/test_fpscr.py

index 1543948fc6f51ec3282ab1089d68e06c536d82d3..87640053ba2c1718932870a6e52893c4fd9d5860 100644 (file)
@@ -130,6 +130,7 @@ class FPSCR_FPRF(FieldSelectableInt):
 
 class FPSCRState(SelectableInt):
     def __init__(self, value=0):
+        self.__do_update_computed_bits = False
         SelectableInt.__init__(self, value, 64)
         self.fsi = {}
         offs = 0
@@ -163,6 +164,39 @@ class FPSCRState(SelectableInt):
                 fs = tuple(offs)
             v = FieldSelectableInt(self, fs)
             self.fsi[field] = v
+        self.__update_computed_bits()
+
+    @property
+    def value(self):
+        return self.__value
+
+    @value.setter
+    def value(self, value):
+        self.__value = value
+        if self.__do_update_computed_bits:
+            self.__update_computed_bits()
+
+    def __update_computed_bits(self):
+        self.__do_update_computed_bits = False
+        try:
+            # update summary bits -- FX is manually handled by pseudo-code,
+            # so we don't update it here
+            self.VX = (self.VXSNAN |
+                       self.VXISI |
+                       self.VXIDI |
+                       self.VXZDZ |
+                       self.VXIMZ |
+                       self.VXVC |
+                       self.VXSOFT |
+                       self.VXSQRT |
+                       self.VXCVI)
+            self.FEX = ((self.VX & self.VE) |
+                        (self.OX & self.OE) |
+                        (self.UX & self.UE) |
+                        (self.ZX & self.ZE) |
+                        (self.XX & self.XE))
+        finally:
+            self.__do_update_computed_bits = True
 
     @property
     def DRN(self):
index 6652b8f10dc27392c3ee7c2532cef886d2a8b282..00ea2f8feb0e79c7661058acc7fa6b5a37631425 100644 (file)
@@ -12,9 +12,12 @@ class TestFPSCR(unittest.TestCase):
         expected = 0x3
         self.assertEqual(FPSCR, expected)
         self.assertEqual(FPSCR.VXCVI, 0)
+        self.assertEqual(FPSCR.VX, 0)
         FPSCR.VXCVI = 1
         self.assertEqual(FPSCR.VXCVI, 1)
+        self.assertEqual(FPSCR.VX, 1)
         expected |= 1 << (64 - 55 - 1)
+        expected |= 1 << (64 - 34 - 1)
         self.assertEqual(FPSCR, expected)
         self.assertEqual(FPSCR.FX, 0)
         FPSCR.FX = 1
@@ -35,6 +38,15 @@ class TestFPSCR(unittest.TestCase):
         self.assertEqual(FPSCR, expected)
         self.assertEqual(FPSCR.FPRF, 0b10010)
         self.assertEqual(FPSCR.FPCC, 0b0010)
+        self.assertEqual(FPSCR.VE, 0)
+        self.assertEqual(FPSCR.VX, 1)
+        self.assertEqual(FPSCR.FEX, 0)
+        FPSCR.VE = 1
+        self.assertEqual(FPSCR.VE, 1)
+        self.assertEqual(FPSCR.FEX, 1)
+        expected |= 1 << (64 - 56 - 1)
+        expected |= 1 << (64 - 33 - 1)
+        self.assertEqual(FPSCR, expected)
 
 
 if __name__ == "__main__":