diff --git a/src/panfrost/lib/genxml/gen_pack.py b/src/panfrost/lib/genxml/gen_pack.py index 6dcdf6a74c8..a0e84b7799a 100644 --- a/src/panfrost/lib/genxml/gen_pack.py +++ b/src/panfrost/lib/genxml/gen_pack.py @@ -316,16 +316,16 @@ class Group(object): if field.modifier[0] == "shr": shift = field.modifier[1] mask = hex((1 << shift) - 1) - print(" assert((__unpacked->{} & {}) == 0);".format(field.name, mask)) + print(" assert(((__unpacked)->{} & {}) == 0); \\".format(field.name, mask)) elif field.modifier[0] == "minus": - print(" assert(__unpacked->{} >= {});".format(field.name, field.modifier[1])) + print(" assert((__unpacked)->{} >= {}); \\".format(field.name, field.modifier[1])) elif field.modifier[0] == "log2": - print(" assert(IS_POT_NONZERO(__unpacked->{}));".format(field.name)) + print(" assert(IS_POT_NONZERO((__unpacked)->{})); \\".format(field.name)) for index in range(self.length // 4): # Handle MBZ words if not index in words: - print(" __packed->opaque[%2d] = 0;" % index) + print(" __tmp_packed.opaque[%2d] = 0; \\" % index) continue word = words[index] @@ -333,7 +333,7 @@ class Group(object): word_start = index * 32 v = None - prefix = " __packed->opaque[%2d] =" % index + prefix = " __tmp_packed.opaque[%2d] =" % index for contributor in word.contributors: field = contributor.field @@ -344,7 +344,7 @@ class Group(object): start -= contrib_word_start end -= contrib_word_start - value = "__unpacked->{}".format(contributor.path) + value = "(__unpacked)->{}".format(contributor.path) if field.modifier is not None: if field.modifier[0] == "shr": value = "{} >> {}".format(value, field.modifier[1]) @@ -390,9 +390,9 @@ class Group(object): s = "%s >> %d" % (s, shift) if contributor == word.contributors[-1]: - print("%s %s;" % (prefix, s)) + print("%s %s; \\" % (prefix, s)) else: - print("%s %s |" % (prefix, s)) + print("%s %s | \\" % (prefix, s)) prefix = " " continue @@ -423,7 +423,7 @@ class Group(object): ALL_ONES = 0xffffffff if mask != ALL_ONES: - TMPL = ' if (__packed->opaque[{}] & {}) fprintf(stderr, "XXX: Invalid field of {} unpacked at word {}\\n");' + TMPL = ' if (__tmp_packed.opaque[{}] & {}) fprintf(stderr, "XXX: Invalid field of {} unpacked at word {}\\n"); \\' print(TMPL.format(index, hex(mask ^ ALL_ONES), self.label, index)) fieldrefs = [] @@ -433,7 +433,7 @@ class Group(object): convert = None args = [] - args.append('&__packed->opaque[0]') + args.append('&__tmp_packed.opaque[0]') args.append(str(fieldref.start)) args.append(str(fieldref.end)) @@ -468,10 +468,10 @@ class Group(object): decoded = '{}{}({}){}'.format(prefix, convert, ', '.join(args), suffix) - print(' __unpacked->{} = {};'.format(fieldref.path, decoded)) + print(' (__unpacked)->{} = {}; \\'.format(fieldref.path, decoded)) if field.modifier and field.modifier[0] == "align": mask = hex(field.modifier[1] - 1) - print(' assert(!(__unpacked->{} & {}));'.format(fieldref.path, mask)) + print(' assert(!((__unpacked)->{} & {})); \\'.format(fieldref.path, mask)) def emit_print_function(self): for field in self.fields: @@ -651,21 +651,19 @@ class Parser(object): print('#define {}_PACKED_T struct {}_packed'.format(name.upper(), name.lower())) def emit_pack_function(self, name, group): - print("static ALWAYS_INLINE void\n%s_pack(%s_PACKED_T * restrict __packed,\n%sconst struct %s * restrict __unpacked)\n{" % - (name, name.upper(), ' ' * (len(name) + 6), name)) - + print("#define {}_pack(__packed, __unpacked) \\".format(name)) + print("do { \\") + print(" {}_PACKED_T __tmp_packed; \\".format(name.upper())) group.emit_pack_function() - - print("}\n\n") + print(' *(__packed) = __tmp_packed; \\') + print("} while (0);\n") def emit_unpack_function(self, name, group): - print("static inline void") - print("%s_unpack(const %s_PACKED_T * restrict __packed,\n%sstruct %s * restrict __unpacked)\n{" % - (name.upper(), name.upper(), ' ' * (len(name) + 8), name)) - + print("#define {}_unpack(__packed, __unpacked) \\".format(name)) + print("do { \\") + print(" {}_PACKED_T __tmp_packed = *(__packed); \\".format(name)) group.emit_unpack_function() - - print("}\n") + print("} while (0);\n") def emit_print_function(self, name, group): print("static inline void") diff --git a/src/panfrost/lib/genxml/pan_pack_helpers.h b/src/panfrost/lib/genxml/pan_pack_helpers.h index 82aee99e0fd..a07f7d623c9 100644 --- a/src/panfrost/lib/genxml/pan_pack_helpers.h +++ b/src/panfrost/lib/genxml/pan_pack_helpers.h @@ -84,15 +84,15 @@ __gen_unpack_padded(const uint32_t *restrict cl, uint32_t start, uint32_t end) #define PREFIX4(A, B, C, D) MALI_##A##_##B##_##C##_##D #define pan_pack(dst, T, name) \ - for (struct PREFIX1(T) name = {PREFIX2(T, header)}, \ - *_loop_terminate = &name; \ + for (UNUSED struct PREFIX1(T) name = {PREFIX2(T, header)}, \ + *_loop_terminate = &name; \ __builtin_expect(_loop_terminate != NULL, 1); ({ \ PREFIX2(T, pack)((dst), &name); \ _loop_terminate = NULL; \ })) #define pan_pack_nodefaults(dst, T, name) \ - for (struct PREFIX1(T) name = {0}, *_loop_terminate = &name; \ + for (UNUSED struct PREFIX1(T) name = {0}, *_loop_terminate = &name; \ __builtin_expect(_loop_terminate != NULL, 1); ({ \ PREFIX2(T, pack)((dst), &name); \ _loop_terminate = NULL; \ @@ -105,7 +105,7 @@ __gen_unpack_padded(const uint32_t *restrict cl, uint32_t start, uint32_t end) pan_pack_nodefaults((PREFIX2(T, PACKED_T) *)dst, T, name) #define pan_unpack(src, T, name) \ - struct PREFIX1(T) name; \ + UNUSED struct PREFIX1(T) name; \ PREFIX2(T, unpack)((src), &name) #define pan_cast_and_unpack(src, T, name) \ @@ -123,15 +123,16 @@ __gen_unpack_padded(const uint32_t *restrict cl, uint32_t start, uint32_t end) pan_section_offset(A, S))) #define pan_section_pack(dst, A, S, name) \ - for (PREFIX4(A, SECTION, S, TYPE) name = {PREFIX4(A, SECTION, S, header)}, \ - *_loop_terminate = (void *)(dst); \ + for (UNUSED PREFIX4(A, SECTION, S, TYPE) \ + name = {PREFIX4(A, SECTION, S, header)}, \ + *_loop_terminate = (void *)(dst); \ __builtin_expect(_loop_terminate != NULL, 1); ({ \ PREFIX4(A, SECTION, S, pack)(pan_section_ptr(dst, A, S), &name); \ _loop_terminate = NULL; \ })) #define pan_section_unpack(src, A, S, name) \ - PREFIX4(A, SECTION, S, TYPE) name; \ + UNUSED PREFIX4(A, SECTION, S, TYPE) name; \ PREFIX4(A, SECTION, S, unpack)(pan_section_ptr(src, A, S), &name) #define pan_section_print(fp, A, S, var, indent) \