From ee170c9d83e623e19fb07fed50f3d82b8a035bf4 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Fri, 30 Dec 2016 11:07:34 -0800 Subject: [PATCH] broadcom/genxml: Support unpacking fixed-point fractional values. This was an oversight in the original XML support, because unpacking wasn't used much. The new XML-based CL dumper will want it, though. --- src/broadcom/cle/gen_pack_header.py | 13 +++++++++---- src/broadcom/cle/v3d_packet_helpers.h | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/broadcom/cle/gen_pack_header.py b/src/broadcom/cle/gen_pack_header.py index d9ead68749e..528ff8fa439 100644 --- a/src/broadcom/cle/gen_pack_header.py +++ b/src/broadcom/cle/gen_pack_header.py @@ -326,6 +326,11 @@ class Group(object): if field.type != "mbo": convert = None + args = [] + args.append('cl') + args.append(str(start + field.start)) + args.append(str(start + field.end)) + if field.type == "address": convert = "__gen_unpack_address" elif field.type == "uint": @@ -339,17 +344,17 @@ class Group(object): elif field.type == "offset": convert = "__gen_unpack_offset" elif field.type == 'ufixed': + args.append(str(field.fractional_size)) convert = "__gen_unpack_ufixed" elif field.type == 'sfixed': + args.append(str(field.fractional_size)) convert = "__gen_unpack_sfixed" else: print("/* unhandled field %s, type %s */\n" % (name, field.type)) s = None - print(" values->%s = %s(cl, %s, %s);" % \ - (field.name, convert, \ - start + field.start, start + field.end)) - + print(" values->%s = %s(%s);" % \ + (field.name, convert, ', '.join(args))) class Value(object): def __init__(self, attrs): diff --git a/src/broadcom/cle/v3d_packet_helpers.h b/src/broadcom/cle/v3d_packet_helpers.h index d01ff6ef0ad..c86cad85266 100644 --- a/src/broadcom/cle/v3d_packet_helpers.h +++ b/src/broadcom/cle/v3d_packet_helpers.h @@ -176,6 +176,22 @@ __gen_unpack_sint(const uint8_t *restrict cl, uint32_t start, uint32_t end) return (val << (64 - size)) >> (64 - size); } +static inline float +__gen_unpack_sfixed(const uint8_t *restrict cl, uint32_t start, uint32_t end, + uint32_t fractional_size) +{ + int32_t bits = __gen_unpack_sint(cl, start, end); + return (float)bits / (1 << fractional_size); +} + +static inline float +__gen_unpack_ufixed(const uint8_t *restrict cl, uint32_t start, uint32_t end, + uint32_t fractional_size) +{ + int32_t bits = __gen_unpack_uint(cl, start, end); + return (float)bits / (1 << fractional_size); +} + static inline float __gen_unpack_float(const uint8_t *restrict cl, uint32_t start, uint32_t end) { -- 2.30.2