Mesa (master): util/format: Simplify the generated unpack code.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jan 15 19:15:28 UTC 2021


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

Author: Eric Anholt <eric at anholt.net>
Date:   Mon Nov 11 14:43:14 2019 -0800

util/format: Simplify the generated unpack code.

We were declaring the temps, then in the same order declaring
assignments to those temps.  The code is more legible (and shorter)
with the assignments moved in place.

Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6297>

---

 src/util/format/u_format_pack.py | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/src/util/format/u_format_pack.py b/src/util/format/u_format_pack.py
index b59630934dc..c65548256a9 100644
--- a/src/util/format/u_format_pack.py
+++ b/src/util/format/u_format_pack.py
@@ -452,14 +452,6 @@ def generate_unpack_kernel(format, dst_channel, dst_native_type):
         depth = format.block_size()
         print('         uint%u_t value = *(const uint%u_t *)src;' % (depth, depth)) 
 
-        # Declare the intermediate variables
-        for i in range(format.nr_channels()):
-            src_channel = channels[i]
-            if src_channel.type == UNSIGNED:
-                print('         uint%u_t %s;' % (depth, src_channel.name))
-            elif src_channel.type == SIGNED:
-                print('         int%u_t %s;' % (depth, src_channel.name))
-
         # Compute the intermediate unshifted values 
         for i in range(format.nr_channels()):
             src_channel = channels[i]
@@ -470,6 +462,7 @@ def generate_unpack_kernel(format, dst_channel, dst_native_type):
                     value = '%s >> %u' % (value, shift)
                 if shift + src_channel.size < depth:
                     value = '(%s) & 0x%x' % (value, (1 << src_channel.size) - 1)
+                print('         uint%u_t %s = %s;' % (depth, src_channel.name, value))
             elif src_channel.type == SIGNED:
                 if shift + src_channel.size < depth:
                     # Align the sign bit
@@ -481,12 +474,10 @@ def generate_unpack_kernel(format, dst_channel, dst_native_type):
                     # Align the LSB bit
                     rshift = depth - src_channel.size
                     value = '(%s) >> %u' % (value, rshift)
+                print('         int%u_t %s = %s;' % (depth, src_channel.name, value))
             else:
                 value = None
-                
-            if value is not None:
-                print('         %s = %s;' % (src_channel.name, value))
-                
+
         # Convert, swizzle, and store final values
         for i in range(4):
             swizzle = swizzles[i]



More information about the mesa-commit mailing list