Mesa (master): nir: Get rid of __[u]int64_to_fp32() and __fp32_to_[u]int64()

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jul 30 17:09:35 UTC 2020


Module: Mesa
Branch: master
Commit: e1b114868a164f8b4e0e4aeb8e79647519abc5db
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=e1b114868a164f8b4e0e4aeb8e79647519abc5db

Author: Boris Brezillon <boris.brezillon at collabora.com>
Date:   Tue Jul 21 14:30:41 2020 +0200

nir: Get rid of __[u]int64_to_fp32() and __fp32_to_[u]int64()

Those are now handled by nir_lower_int64() which has native NIR
implementations.

Signed-off-by: Boris Brezillon <boris.brezillon at collabora.com>
Reviewed-by: Matt Turner <mattst88 at gmail.com>
Acked-by: Jason Ekstrand <jason at jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5588>

---

 src/compiler/glsl/float64.glsl          | 94 ---------------------------------
 src/compiler/nir/nir_lower_double_ops.c | 26 +++------
 2 files changed, 6 insertions(+), 114 deletions(-)

diff --git a/src/compiler/glsl/float64.glsl b/src/compiler/glsl/float64.glsl
index dd1179012ca..185f6dc9f4c 100644
--- a/src/compiler/glsl/float64.glsl
+++ b/src/compiler/glsl/float64.glsl
@@ -1092,66 +1092,6 @@ __fp64_to_int64(uint64_t a)
    return __roundAndPackInt64(aSign, aFracHi, aFracLo, zFrac2);
 }
 
-uint64_t
-__fp32_to_uint64(float f)
-{
-   uint a = floatBitsToUint(f);
-   uint aFrac = a & 0x007FFFFFu;
-   int aExp = int((a>>23) & 0xFFu);
-   uint aSign = a & 0x80000000u;
-   uint zFrac0 = 0u;
-   uint zFrac1 = 0u;
-   uint zFrac2 = 0u;
-   uint64_t default_nan = 0xFFFFFFFFFFFFFFFFUL;
-   int shiftCount = 0xBE - aExp;
-
-   if (shiftCount <0) {
-      if (aExp == 0xFF)
-         return default_nan;
-   }
-
-   aFrac = mix(aFrac, aFrac | 0x00800000u, aExp != 0);
-   __shortShift64Left(aFrac, 0, 40, zFrac0, zFrac1);
-
-   if (shiftCount != 0) {
-      __shift64ExtraRightJamming(zFrac0, zFrac1, zFrac2, shiftCount,
-                                 zFrac0, zFrac1, zFrac2);
-   }
-
-   return __roundAndPackUInt64(aSign, zFrac0, zFrac1, zFrac2);
-}
-
-int64_t
-__fp32_to_int64(float f)
-{
-   uint a = floatBitsToUint(f);
-   uint aFrac = a & 0x007FFFFFu;
-   int aExp = int((a>>23) & 0xFFu);
-   uint aSign = a & 0x80000000u;
-   uint zFrac0 = 0u;
-   uint zFrac1 = 0u;
-   uint zFrac2 = 0u;
-   int64_t default_NegNaN = -0x7FFFFFFFFFFFFFFEL;
-   int64_t default_PosNaN = 0xFFFFFFFFFFFFFFFFL;
-   int shiftCount = 0xBE - aExp;
-
-   if (shiftCount <0) {
-      if (aExp == 0xFF && aFrac != 0u)
-         return default_NegNaN;
-      return mix(default_NegNaN, default_PosNaN, aSign == 0u);
-   }
-
-   aFrac = mix(aFrac, aFrac | 0x00800000u, aExp != 0);
-   __shortShift64Left(aFrac, 0, 40, zFrac0, zFrac1);
-
-   if (shiftCount != 0) {
-      __shift64ExtraRightJamming(zFrac0, zFrac1, zFrac2, shiftCount,
-                                 zFrac0, zFrac1, zFrac2);
-   }
-
-   return __roundAndPackInt64(aSign, zFrac0, zFrac1, zFrac2);
-}
-
 uint64_t
 __int64_to_fp64(int64_t a)
 {
@@ -1347,40 +1287,6 @@ __fp64_to_fp32(uint64_t __a)
    return __roundAndPackFloat32(aSign, aExp - 0x381, zFrac);
 }
 
-float
-__uint64_to_fp32(uint64_t __a)
-{
-   uvec2 aFrac = unpackUint2x32(__a);
-   int shiftCount = mix(__countLeadingZeros32(aFrac.y) - 33,
-                        __countLeadingZeros32(aFrac.x) - 1,
-                        aFrac.y == 0u);
-
-   if (0 <= shiftCount)
-      __shortShift64Left(aFrac.y, aFrac.x, shiftCount, aFrac.y, aFrac.x);
-   else
-      __shift64RightJamming(aFrac.y, aFrac.x, -shiftCount, aFrac.y, aFrac.x);
-
-   return __roundAndPackFloat32(0u, 0x9C - shiftCount, aFrac.x);
-}
-
-float
-__int64_to_fp32(int64_t __a)
-{
-   uint aSign = uint(unpackInt2x32(__a).y) & 0x80000000u;
-   uint64_t absA = mix(uint64_t(__a), uint64_t(-__a), __a < 0);
-   uvec2 aFrac = unpackUint2x32(absA);
-   int shiftCount = mix(__countLeadingZeros32(aFrac.y) - 33,
-                        __countLeadingZeros32(aFrac.x) - 1,
-                        aFrac.y == 0u);
-
-   if (0 <= shiftCount)
-      __shortShift64Left(aFrac.y, aFrac.x, shiftCount, aFrac.y, aFrac.x);
-   else
-      __shift64RightJamming(aFrac.y, aFrac.x, -shiftCount, aFrac.y, aFrac.x);
-
-   return __roundAndPackFloat32(aSign, 0x9C - shiftCount, aFrac.x);
-}
-
 /* Returns the result of converting the single-precision floating-point value
  * `a' to the double-precision floating-point format.
  */
diff --git a/src/compiler/nir/nir_lower_double_ops.c b/src/compiler/nir/nir_lower_double_ops.c
index 138fddeea5a..a6a9b958426 100644
--- a/src/compiler/nir/nir_lower_double_ops.c
+++ b/src/compiler/nir/nir_lower_double_ops.c
@@ -471,17 +471,15 @@ lower_doubles_instr_to_soft(nir_builder *b, nir_alu_instr *instr,
 
    switch (instr->op) {
    case nir_op_f2i64:
-      if (instr->src[0].src.ssa->bit_size == 64)
-         name = "__fp64_to_int64";
-      else
-         name = "__fp32_to_int64";
+      if (instr->src[0].src.ssa->bit_size != 64)
+         return false;
+      name = "__fp64_to_int64";
       return_type = glsl_int64_t_type();
       break;
    case nir_op_f2u64:
-      if (instr->src[0].src.ssa->bit_size == 64)
-         name = "__fp64_to_uint64";
-      else
-         name = "__fp32_to_uint64";
+      if (instr->src[0].src.ssa->bit_size != 64)
+         return false;
+      name = "__fp64_to_uint64";
       break;
    case nir_op_f2f64:
       name = "__fp32_to_fp64";
@@ -506,18 +504,6 @@ lower_doubles_instr_to_soft(nir_builder *b, nir_alu_instr *instr,
    case nir_op_b2f64:
       name = "__bool_to_fp64";
       break;
-   case nir_op_i2f32:
-      if (instr->src[0].src.ssa->bit_size != 64)
-         return false;
-      name = "__int64_to_fp32";
-      return_type = glsl_float_type();
-      break;
-   case nir_op_u2f32:
-      if (instr->src[0].src.ssa->bit_size != 64)
-         return false;
-      name = "__uint64_to_fp32";
-      return_type = glsl_float_type();
-      break;
    case nir_op_i2f64:
       if (instr->src[0].src.ssa->bit_size == 64)
          name = "__int64_to_fp64";



More information about the mesa-commit mailing list