From 3424318ec3d60d0d2cf6d1b06e5b2e71a3c7277c Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Thu, 3 Dec 2020 15:18:45 -0800 Subject: [PATCH] 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 Part-of: --- 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 403140f..28e0b66 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; -- 2.7.4