comments in fp convert, fix carry out, comment out FPSCR for now
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 16 May 2021 12:39:48 +0000 (13:39 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 16 May 2021 12:39:48 +0000 (13:39 +0100)
openpower/isafunctions/fpfromint.mdwn
openpower/isafunctions/roundfloat.mdwn [deleted file]

index 86cf46c15d72827f4a254ee141ca21f05987d75e..df3ed6911697d947d44d1b6546e215d10831c084 100644 (file)
@@ -5,6 +5,53 @@ Convert From Integer instructions.
 
 <!-- Power ISA Book I Version 3.0B Section A.3 page 782 -->
 
+    def Round_Float( tgt_precision, sign, exp, frac, round_mode ):
+       inc <- 0
+       if tgt_precision = "single-precision" then
+           lsb <- frac[23]
+           gbit <- frac[24]
+           rbit <- frac[25]
+           xbit <- frac[26:63] > 0
+        else # tgt_precision = "double-precision"
+            lsb  <= frac[52]
+            gbit <= frac[53]
+            rbit <= frac[54]
+            xbit <= frac[55:63] > 0
+
+        if round_mode  = 0b00  then           # Round to Nearest
+            if lsb = 1 and gbit = 1              then inc <- 1
+            if lsb = 0 and gbit = 1 and rbit = 1 then inc <- 1
+            if lsb = 0 and gbit = 1 and xbit = 1 then inc <- 1
+        end
+        if round_mode  = 0b10  then           # Round toward + Infinity
+            if sign = 0 and gbit = 1 then inc <-1
+            if sign = 0 and rbit = 1 then inc <-1
+            if sign = 0 and xbit = 1 then inc <-1
+        end
+        if round_mode  = 0b11  then           # Round toward - Infinity
+            if sign = 1 and gbit = 1 then inc <-1
+            if sign = 1 and rbit = 1 then inc <-1
+            if sign = 1 and xbit = 1 then inc <-1
+        end
+        # increase fraction, record the top bit as a "carry out"
+        if tgt_precision = "single-precision" then
+            tmp = [0]*25
+            tmp[1:24] = frac[0:23]
+            tmp[0:24] <- tmp[0:24] + inc
+            carry_out = tmp[24]
+            frac[0:23] = tmp[1:24]
+        else # tgt_precision = "double-precision"
+            tmp = [0]*54
+            tmp[1:53] = frac[0:52]
+            tmp[0:53] <- tmp[0:53] + inc
+            carry_out = tmp[53]
+            frac[0:52] = tmp[1:54]
+        if carry_out = 1 then exp <- exp + 1
+        # TODO, later
+        # FPSCR[FR] <- inc
+        # FPSCR[FI] <- gbit | rbit | xbit
+        # FPSCR[XX] <- FPSCR[XX] | FPSCR[FI]
+
     def INT2FP(FR, cvt, RN):
         if cvt = "sint2double" then
             tgt_precision = "double-precision"
@@ -25,9 +72,11 @@ Convert From Integer instructions.
 
         if frac[0:63] = 0 then
             # Zero Operand
-            FPSCR[FR] <- 0b00
-            FPSCR[FI] <- 0b00
-            FPSCR[FPRF] <- "+ zero"
+            # TODO, FPSCR
+            #FPSCR[FR] <- 0b00
+            #FPSCR[FI] <- 0b00
+            #FPSCR[FPRF] <- "+ zero"
+            result = [0] * 64
         else
             if sign = 1 then frac[0:63] <- ¬frac[0:63] + 1
             # do the loop 0 times if FR = max negative 64-bit integer or
@@ -35,9 +84,11 @@ Convert From Integer instructions.
             do while frac[0] = 0
                 frac[0:63] <- frac[1:63] || 0b0
                 exp <- exp - 1
-            Round_Float( tgt_precision, sign, exp, frac0:63, RN )
-            if sign = 0 then FPSCR[FPRF] <- "+normal number"
-            if sign = 1 then FPSCR[FPRF] <- "-normal number"
+            # round to nearest
+            Round_Float( tgt_precision, sign, exp, frac, 0b00 )
+            # TODO, FPSCR
+            #if sign = 0 then FPSCR[FPRF] <- "+normal number"
+            #if sign = 1 then FPSCR[FPRF] <- "-normal number"
             result[0]    <- sign
             result[1:11] <- exp + 1023     # exp + bias
             result[12:63] <- frac[1:52]
diff --git a/openpower/isafunctions/roundfloat.mdwn b/openpower/isafunctions/roundfloat.mdwn
deleted file mode 100644 (file)
index 229e9bb..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-# A.3 Round to Float conversion
-
-<!-- Power ISA Book I Version 3.0B Section A.3 page 782 -->
-
-    def Round_Float( tgt_precision, sign, exp, frac, round_mode ):
-       inc <- 0
-       if tgt_precision = "single-precision" then
-           lsb <- frac[23]
-           gbit <- frac[24]
-           rbit <- frac[25]
-           xbit <- frac[26:63] > 0
-        else # tgt_precision = "double-precision"
-            lsb  <= frac[52]
-            gbit <= frac[53]
-            rbit <= frac[54]
-            xbit <= frac[55:63] > 0
-
-        if round_mode  = 0b00  then           # Round to Nearest
-            if lsb = 1 and gbit = 1              then inc <- 1
-            if lsb = 0 and gbit = 1 and rbit = 1 then inc <- 1
-            if lsb = 0 and gbit = 1 and xbit = 1 then inc <- 1
-        end
-        if round_mode  = 0b10  then           # Round toward + Infinity
-            if sign = 0 and gbit = 1 then inc <-1
-            if sign = 0 and rbit = 1 then inc <-1
-            if sign = 0 and xbit = 1 then inc <-1
-        end
-        if round_mode  = 0b11  then           # Round toward - Infinity
-            if sign = 1 and gbit = 1 then inc <-1
-            if sign = 1 and rbit = 1 then inc <-1
-            if sign = 1 and xbit = 1 then inc <-1
-        end
-        if tgt_precision = "single-precision" then
-            frac[0:23] <- frac[0:23] + inc
-        else # tgt_precision = "double-precision"
-            frac[0:52] <- frac[0:52] + inc
-        if carry_out = 1 then exp <- exp + 1
-        FPSCR[FR] <- inc
-        FPSCR[FI] <- gbit | rbit | xbit
-        FPSCR[XX] <- FPSCR[XX] | FPSCR[FI]
-