From feabbddc2a28e67af1bcf5652ac4fcf2009d9f8f Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Sat, 6 Apr 2024 11:42:18 -0400 Subject: [PATCH] asahi: calculate validity when unpacking for smarter printing. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/genxml/gen_pack.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/asahi/genxml/gen_pack.py b/src/asahi/genxml/gen_pack.py index 0dbc3342c8c..e26cd88515e 100644 --- a/src/asahi/genxml/gen_pack.py +++ b/src/asahi/genxml/gen_pack.py @@ -515,6 +515,7 @@ class Group(object): # First, verify there is no garbage in unused bits words = {} self.collect_words(self.fields, 0, '', words) + print(' bool valid = true;') print('#ifndef __OPENCL_VERSION__') for index in range(self.length // 4): @@ -526,7 +527,16 @@ class Group(object): ALL_ONES = 0xffffffff if mask != ALL_ONES: - TMPL = ' if (((const uint32_t *) cl)[{}] & {}) fprintf(fp, "XXX: Unknown field of {} unpacked at word {}: got %X, bad mask %X\\n", ((const uint32_t *) cl)[{}], ((const uint32_t *) cl)[{}] & {});' + TMPL = ''' + if (((const uint32_t *) cl)[{}] & {}) {{ + valid = false; + + if (fp != NULL) {{ + fprintf(fp, "XXX: Unknown field of {} unpacked at word {}: got %X, bad mask %X\\n", + ((const uint32_t *) cl)[{}], ((const uint32_t *) cl)[{}] & {}); + }} + }} + ''' print(TMPL.format(index, hex(mask ^ ALL_ONES), self.label, index, index, index, hex(mask ^ ALL_ONES))) print('#endif') @@ -709,12 +719,13 @@ class Parser(object): words)) def emit_unpack_function(self, name, group): - print("static inline void") + print("static inline bool") print("%s_unpack(FILE_TYPE *fp, CONSTANT uint8_t * restrict cl,\n%sstruct %s * restrict values)\n{" % (name.upper(), ' ' * (len(name) + 8), name)) group.emit_unpack_function() + print(" return valid;\n") print("}\n") def emit_print_function(self, name, group):