diff --git a/src/util/format/u_format_pack.py b/src/util/format/u_format_pack.py index 72f66ef107f..94b326e6d82 100644 --- a/src/util/format/u_format_pack.py +++ b/src/util/format/u_format_pack.py @@ -410,13 +410,21 @@ def conversion_expr(src_channel, # Convert double or float to non-float if dst_channel.type != FLOAT: - if dst_channel.norm or dst_channel.type == FIXED: - dst_one = get_one(dst_channel) - if dst_channel.size <= 23: - value = 'util_iround(%s * 0x%x)' % (value, dst_one) - else: - # bigger than single precision mantissa, use double - value = '(%s * (double)0x%x)' % (value, dst_one) + if not dst_channel.pure: + if dst_channel.norm or dst_channel.type == FIXED: + dst_one = get_one(dst_channel) + if dst_channel.size <= 23: + value = 'util_iround(%s * 0x%x)' % (value, dst_one) + else: + # bigger than single precision mantissa, use double + value = '(%s * (double)0x%x)' % (value, dst_one) + + # Cast to an integer with the correct signedness first + if dst_channel.type == UNSIGNED: + value = '(uint%u_t)(%s) ' % (max(dst_channel.size, 32), value) + elif dst_channel.type == SIGNED: + value = '(int%u_t)(%s) ' % (max(dst_channel.size, 32), value) + value = '(%s)%s' % (dst_native_type, value) else: # Cast double to float when converting to either half or float