From da14c0af672ffc307fab2b4c9889a66bf354f5da Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 21 Mar 2025 09:05:46 -0700 Subject: [PATCH] intel/tools: move ascii85_decode to common code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We have 3 copies of this function, so put it in the shared static library. Reviewed-by: Tapani Pälli Part-of: --- src/intel/tools/aubinator_error_decode.c | 28 ------------------------ src/intel/tools/error2aub.c | 28 ------------------------ src/intel/tools/error2hangdump.c | 28 ------------------------ src/intel/tools/error_decode_lib.c | 28 ++++++++++++++++++++++++ src/intel/tools/error_decode_lib.h | 3 +++ 5 files changed, 31 insertions(+), 84 deletions(-) diff --git a/src/intel/tools/aubinator_error_decode.c b/src/intel/tools/aubinator_error_decode.c index 3352a955a63..2dd9dca5475 100644 --- a/src/intel/tools/aubinator_error_decode.c +++ b/src/intel/tools/aubinator_error_decode.c @@ -261,34 +261,6 @@ struct section { static unsigned num_sections; static struct section sections[MAX_SECTIONS]; -static int ascii85_decode(const char *in, uint32_t **out, bool inflate) -{ - int len = 0, size = 1024; - - *out = realloc(*out, sizeof(uint32_t)*size); - if (*out == NULL) - return 0; - - while (*in >= '!' && *in <= 'z') { - uint32_t v = 0; - - if (len == size) { - size *= 2; - *out = realloc(*out, sizeof(uint32_t)*size); - if (*out == NULL) - return 0; - } - - in = ascii85_decode_char(in, &v); - (*out)[len++] = v; - } - - if (!inflate) - return len; - - return zlib_inflate(out, len); -} - static int qsort_hw_context_first(const void *a, const void *b) { const struct section *sa = a, *sb = b; diff --git a/src/intel/tools/error2aub.c b/src/intel/tools/error2aub.c index 832c625a26a..907aa343e41 100644 --- a/src/intel/tools/error2aub.c +++ b/src/intel/tools/error2aub.c @@ -42,34 +42,6 @@ #define fail(...) fail_if(true, __VA_ARGS__) -static int ascii85_decode(const char *in, uint32_t **out, bool inflate) -{ - int len = 0, size = 1024; - - *out = realloc(*out, sizeof(uint32_t)*size); - if (*out == NULL) - return 0; - - while (*in >= '!' && *in <= 'z') { - uint32_t v = 0; - - if (len == size) { - size *= 2; - *out = realloc(*out, sizeof(uint32_t)*size); - if (*out == NULL) - return 0; - } - - in = ascii85_decode_char(in, &v); - (*out)[len++] = v; - } - - if (!inflate) - return len; - - return zlib_inflate(out, len); -} - static void print_help(const char *progname, FILE *file) { diff --git a/src/intel/tools/error2hangdump.c b/src/intel/tools/error2hangdump.c index a337d6a51c1..93c9bcff30a 100644 --- a/src/intel/tools/error2hangdump.c +++ b/src/intel/tools/error2hangdump.c @@ -41,34 +41,6 @@ #define XE_KMD_ERROR_DUMP_IDENTIFIER "**** Xe Device Coredump ****" -static int ascii85_decode(const char *in, uint32_t **out, bool inflate) -{ - int len = 0, size = 1024; - - *out = realloc(*out, sizeof(uint32_t)*size); - if (*out == NULL) - return 0; - - while (*in >= '!' && *in <= 'z') { - uint32_t v = 0; - - if (len == size) { - size *= 2; - *out = realloc(*out, sizeof(uint32_t)*size); - if (*out == NULL) - return 0; - } - - in = ascii85_decode_char(in, &v); - (*out)[len++] = v; - } - - if (!inflate) - return len; - - return zlib_inflate(out, len); -} - static void print_help(const char *progname, FILE *file) { diff --git a/src/intel/tools/error_decode_lib.c b/src/intel/tools/error_decode_lib.c index 35b8657cf3d..f1ac2c703ee 100644 --- a/src/intel/tools/error_decode_lib.c +++ b/src/intel/tools/error_decode_lib.c @@ -76,3 +76,31 @@ int zlib_inflate(uint32_t **ptr, int len) *ptr = out; return zstream.total_out / 4; } + +int ascii85_decode(const char *in, uint32_t **out, bool inflate) +{ + int len = 0, size = 1024; + + *out = realloc(*out, sizeof(uint32_t)*size); + if (*out == NULL) + return 0; + + while (*in >= '!' && *in <= 'z') { + uint32_t v = 0; + + if (len == size) { + size *= 2; + *out = realloc(*out, sizeof(uint32_t)*size); + if (*out == NULL) + return 0; + } + + in = ascii85_decode_char(in, &v); + (*out)[len++] = v; + } + + if (!inflate) + return len; + + return zlib_inflate(out, len); +} diff --git a/src/intel/tools/error_decode_lib.h b/src/intel/tools/error_decode_lib.h index 431c81480bb..e049f85d5c6 100644 --- a/src/intel/tools/error_decode_lib.h +++ b/src/intel/tools/error_decode_lib.h @@ -6,7 +6,10 @@ #pragma once #include +#include const char *ascii85_decode_char(const char *in, uint32_t *v); int zlib_inflate(uint32_t **ptr, int len); + +int ascii85_decode(const char *in, uint32_t **out, bool inflate);