From 9b58301766740d79453061ad16fea700deda9421 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Wed, 3 Apr 2024 12:43:57 -0700 Subject: [PATCH] intel/tools: Move ascii85_decode_char() to error_decode_lib MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This was re-implemented in several places, so lets share it. Reviewed-by: Lionel Landwerlin Signed-off-by: José Roberto de Souza Part-of: --- src/intel/tools/aubinator_error_decode.c | 1 + src/intel/tools/aubinator_error_decode_lib.c | 19 --------------- src/intel/tools/aubinator_error_decode_lib.h | 2 -- src/intel/tools/aubinator_error_decode_xe.c | 1 + src/intel/tools/error2aub.c | 12 ++-------- src/intel/tools/error2hangdump.c | 12 ++-------- src/intel/tools/error_decode_lib.c | 25 ++++++++++++++++++++ src/intel/tools/error_decode_lib.h | 10 ++++++++ src/intel/tools/meson.build | 12 ++++++++-- 9 files changed, 51 insertions(+), 43 deletions(-) create mode 100644 src/intel/tools/error_decode_lib.c create mode 100644 src/intel/tools/error_decode_lib.h diff --git a/src/intel/tools/aubinator_error_decode.c b/src/intel/tools/aubinator_error_decode.c index 9f716269a36..a484d26844b 100644 --- a/src/intel/tools/aubinator_error_decode.c +++ b/src/intel/tools/aubinator_error_decode.c @@ -44,6 +44,7 @@ #include "compiler/elk/elk_compiler.h" #include "decoder/intel_decoder.h" #include "dev/intel_debug.h" +#include "error_decode_lib.h" #include "util/macros.h" #define MIN(a, b) ((a) < (b) ? (a) : (b)) diff --git a/src/intel/tools/aubinator_error_decode_lib.c b/src/intel/tools/aubinator_error_decode_lib.c index 7ad6ac5e5fa..2336bdab757 100644 --- a/src/intel/tools/aubinator_error_decode_lib.c +++ b/src/intel/tools/aubinator_error_decode_lib.c @@ -68,22 +68,3 @@ dump_shader_binary(void *user_data, const char *short_name, fwrite(data, data_length, 1, f); fclose(f); } - -const char * -ascii85_decode_char(const char *in, uint32_t *v) -{ - *v = 0; - - if (*in == 'z') { - in++; - } else { - *v += in[0] - 33; *v *= 85; - *v += in[1] - 33; *v *= 85; - *v += in[2] - 33; *v *= 85; - *v += in[3] - 33; *v *= 85; - *v += in[4] - 33; - in += 5; - } - - return in; -} diff --git a/src/intel/tools/aubinator_error_decode_lib.h b/src/intel/tools/aubinator_error_decode_lib.h index 6984259fceb..b1b5094e7f9 100644 --- a/src/intel/tools/aubinator_error_decode_lib.h +++ b/src/intel/tools/aubinator_error_decode_lib.h @@ -13,5 +13,3 @@ void dump_shader_binary(void *user_data, const char *short_name, uint64_t address, const void *data, unsigned data_length); - -const char *ascii85_decode_char(const char *in, uint32_t *v); \ No newline at end of file diff --git a/src/intel/tools/aubinator_error_decode_xe.c b/src/intel/tools/aubinator_error_decode_xe.c index d90e15960b7..a9058922734 100644 --- a/src/intel/tools/aubinator_error_decode_xe.c +++ b/src/intel/tools/aubinator_error_decode_xe.c @@ -10,6 +10,7 @@ #include #include "aubinator_error_decode_lib.h" +#include "error_decode_lib.h" #include "error_decode_xe_lib.h" #include "intel/compiler/brw_isa_info.h" #include "intel/dev/intel_device_info.h" diff --git a/src/intel/tools/error2aub.c b/src/intel/tools/error2aub.c index 601e08a00f3..19e09aede3f 100644 --- a/src/intel/tools/error2aub.c +++ b/src/intel/tools/error2aub.c @@ -35,6 +35,7 @@ #include "util/list.h" #include "aub_write.h" +#include "error_decode_lib.h" #include "intel_aub.h" #define fail_if(cond, ...) _fail_if(cond, NULL, __VA_ARGS__) @@ -107,16 +108,7 @@ static int ascii85_decode(const char *in, uint32_t **out, bool inflate) return 0; } - if (*in == 'z') { - in++; - } else { - v += in[0] - 33; v *= 85; - v += in[1] - 33; v *= 85; - v += in[2] - 33; v *= 85; - v += in[3] - 33; v *= 85; - v += in[4] - 33; - in += 5; - } + in = ascii85_decode_char(in, &v); (*out)[len++] = v; } diff --git a/src/intel/tools/error2hangdump.c b/src/intel/tools/error2hangdump.c index 0a9d74deaa8..5ea0375d1be 100644 --- a/src/intel/tools/error2hangdump.c +++ b/src/intel/tools/error2hangdump.c @@ -36,6 +36,7 @@ #include "common/intel_hang_dump.h" +#include "error_decode_lib.h" #include "intel/dev/intel_device_info.h" static inline void @@ -127,16 +128,7 @@ static int ascii85_decode(const char *in, uint32_t **out, bool inflate) return 0; } - if (*in == 'z') { - in++; - } else { - v += in[0] - 33; v *= 85; - v += in[1] - 33; v *= 85; - v += in[2] - 33; v *= 85; - v += in[3] - 33; v *= 85; - v += in[4] - 33; - in += 5; - } + in = ascii85_decode_char(in, &v); (*out)[len++] = v; } diff --git a/src/intel/tools/error_decode_lib.c b/src/intel/tools/error_decode_lib.c new file mode 100644 index 00000000000..2f2b240dadc --- /dev/null +++ b/src/intel/tools/error_decode_lib.c @@ -0,0 +1,25 @@ +/* + * Copyright 2024 Intel Corporation + * SPDX-License-Identifier: MIT + */ + +#include "error_decode_lib.h" + +const char * +ascii85_decode_char(const char *in, uint32_t *v) +{ + *v = 0; + + if (*in == 'z') { + in++; + } else { + *v += in[0] - 33; *v *= 85; + *v += in[1] - 33; *v *= 85; + *v += in[2] - 33; *v *= 85; + *v += in[3] - 33; *v *= 85; + *v += in[4] - 33; + in += 5; + } + + return in; +} diff --git a/src/intel/tools/error_decode_lib.h b/src/intel/tools/error_decode_lib.h new file mode 100644 index 00000000000..357787edc71 --- /dev/null +++ b/src/intel/tools/error_decode_lib.h @@ -0,0 +1,10 @@ +/* + * Copyright 2024 Intel Corporation + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include + +const char *ascii85_decode_char(const char *in, uint32_t *v); diff --git a/src/intel/tools/meson.build b/src/intel/tools/meson.build index d637515170b..fd8b9a59fd1 100644 --- a/src/intel/tools/meson.build +++ b/src/intel/tools/meson.build @@ -49,6 +49,8 @@ aubinator_error_decode = executable( 'aubinator_error_decode_lib.h', 'aubinator_error_decode_xe.c', 'aubinator_error_decode_xe.h', + 'error_decode_lib.c', + 'error_decode_lib.h', 'error_decode_xe_lib.c', 'error_decode_xe_lib.h'), dependencies : [idep_mesautil, dep_zlib, dep_thread, idep_intel_dev, @@ -63,7 +65,11 @@ aubinator_error_decode = executable( error2aub = executable( 'intel_error2aub', - files('aub_write.h', 'aub_write.c', 'error2aub.c'), + files('aub_write.h', + 'aub_write.c', + 'error2aub.c', + 'error_decode_lib.c', + 'error_decode_lib.h'), dependencies : [dep_zlib, dep_dl, dep_thread, dep_m, idep_intel_dev], include_directories : [inc_include, inc_src, inc_intel], c_args : [no_override_init_args], @@ -73,7 +79,9 @@ error2aub = executable( error2hangdump = executable( 'intel_error2hangdump', - files('error2hangdump.c'), + files('error2hangdump.c', + 'error_decode_lib.c', + 'error_decode_lib.h'), dependencies : [dep_zlib, dep_dl, dep_thread, dep_m, idep_intel_dev], include_directories : [inc_include, inc_src, inc_intel], c_args : [no_override_init_args],