Module: Mesa
Branch: main
Commit: 3424318ec3d60d0d2cf6d1b06e5b2e71a3c7277c
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=3424318ec3d60d0d2cf6d1b06e5b2e71a3c7277c

Author: Eric Anholt <[email protected]>
Date:   Thu Dec  3 15:18:45 2020 -0800

gallium/tgsi_exec: Simplify bounds checks on the const file.

We were doing two < 0 checks, when we can just treat the value as unsigned
and check against our unsigned size limit.  Cuts 2k of text from the
various inlined copies of this function.

Reviewed-by: Adam Jackson <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10605>

---

 src/gallium/auxiliary/tgsi/tgsi_exec.c | 34 ++++++++++++++--------------------
 1 file changed, 14 insertions(+), 20 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c 
b/src/gallium/auxiliary/tgsi/tgsi_exec.c
index 403140fc58a..28e0b66f2be 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_exec.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c
@@ -1452,28 +1452,22 @@ fetch_src_file_channel(const struct tgsi_exec_machine 
*mach,
    switch (file) {
    case TGSI_FILE_CONSTANT:
       for (i = 0; i < TGSI_QUAD_SIZE; i++) {
-         assert(index2D->i[i] >= 0 && index2D->i[i] < 
PIPE_MAX_CONSTANT_BUFFERS);
-
-         if (index->i[i] < 0) {
+         /* NOTE: copying the const value as a uint instead of float */
+         const uint constbuf = index2D->i[i];
+         const unsigned pos = index->i[i] * 4 + swizzle;
+         /* const buffer bounds check */
+         if (pos >= mach->ConstsSize[constbuf] / 4) {
+            if (0) {
+               /* Debug: print warning */
+               static int count = 0;
+               if (count++ < 100)
+                  debug_printf("TGSI Exec: const buffer index %d"
+                                 " out of bounds\n", pos);
+            }
             chan->u[i] = 0;
          } else {
-            /* NOTE: copying the const value as a uint instead of float */
-            const uint constbuf = index2D->i[i];
-            const int pos = index->i[i] * 4 + swizzle;
-            /* const buffer bounds check */
-            if (pos < 0 || pos >= (int) mach->ConstsSize[constbuf] / 4) {
-               if (0) {
-                  /* Debug: print warning */
-                  static int count = 0;
-                  if (count++ < 100)
-                     debug_printf("TGSI Exec: const buffer index %d"
-                                  " out of bounds\n", pos);
-               }
-               chan->u[i] = 0;
-            } else {
-               const uint *buf = (const uint *)mach->Consts[constbuf];
-               chan->u[i] = buf[pos];
-            }
+            const uint *buf = (const uint *)mach->Consts[constbuf];
+            chan->u[i] = buf[pos];
          }
       }
       break;

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to