diff options
author | Eric Anholt <[email protected]> | 2019-08-15 09:48:53 -0700 |
---|---|---|
committer | Eric Anholt <[email protected]> | 2019-08-28 10:39:36 -0700 |
commit | 309ef968cde48d6d0cadf2da7c66a28519cbabe1 (patch) | |
tree | 57b794914829119b12a6809eeba8bf35257f62f0 /src/gallium/auxiliary | |
parent | 174240c5e49732dd5ec8b9d5fbd10c3e35babbc6 (diff) |
gallium: Drop the useless union wrapper on pack/unpack.
Nothing accessed the .value field, just the .chan. Unwrap all the
code from the union, for clarity (and 13k less generated code).
Reviewed-by: Roland Scheidegger <[email protected]>
Acked-by: Adam Jackson <[email protected]>
Reviewed-by: Marek Olšák <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r-- | src/gallium/auxiliary/util/u_format_pack.py | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/src/gallium/auxiliary/util/u_format_pack.py b/src/gallium/auxiliary/util/u_format_pack.py index dbffb9bef6b..e2fd1520dde 100644 --- a/src/gallium/auxiliary/util/u_format_pack.py +++ b/src/gallium/auxiliary/util/u_format_pack.py @@ -79,18 +79,18 @@ def generate_format_type(format): for channel in channels: if channel.type == VOID: if channel.size: - print(' unsigned %s:%u;' % (channel.name, channel.size)) + print(' unsigned %s:%u;' % (channel.name, channel.size)) elif channel.type == UNSIGNED: - print(' unsigned %s:%u;' % (channel.name, channel.size)) + print(' unsigned %s:%u;' % (channel.name, channel.size)) elif channel.type in (SIGNED, FIXED): - print(' int %s:%u;' % (channel.name, channel.size)) + print(' int %s:%u;' % (channel.name, channel.size)) elif channel.type == FLOAT: if channel.size == 64: - print(' double %s;' % (channel.name)) + print(' double %s;' % (channel.name)) elif channel.size == 32: - print(' float %s;' % (channel.name)) + print(' float %s;' % (channel.name)) else: - print(' unsigned %s:%u;' % (channel.name, channel.size)) + print(' unsigned %s:%u;' % (channel.name, channel.size)) else: assert 0 @@ -99,39 +99,33 @@ def generate_format_type(format): assert channel.size % 8 == 0 and is_pot(channel.size) if channel.type == VOID: if channel.size: - print(' uint%u_t %s;' % (channel.size, channel.name)) + print(' uint%u_t %s;' % (channel.size, channel.name)) elif channel.type == UNSIGNED: - print(' uint%u_t %s;' % (channel.size, channel.name)) + print(' uint%u_t %s;' % (channel.size, channel.name)) elif channel.type in (SIGNED, FIXED): - print(' int%u_t %s;' % (channel.size, channel.name)) + print(' int%u_t %s;' % (channel.size, channel.name)) elif channel.type == FLOAT: if channel.size == 64: - print(' double %s;' % (channel.name)) + print(' double %s;' % (channel.name)) elif channel.size == 32: - print(' float %s;' % (channel.name)) + print(' float %s;' % (channel.name)) elif channel.size == 16: - print(' uint16_t %s;' % (channel.name)) + print(' uint16_t %s;' % (channel.name)) else: assert 0 else: assert 0 - print('union util_format_%s {' % format.short_name()) - - if format.block_size() in (8, 16, 32, 64): - print(' uint%u_t value;' % (format.block_size(),)) - use_bitfields = False for channel in format.le_channels: if channel.size % 8 or not is_pot(channel.size): use_bitfields = True - print(' struct {') + print('struct util_format_%s {' % format.short_name()) if use_bitfields: print_channels(format, generate_bitfields) else: print_channels(format, generate_full_fields) - print(' } chan;') print('};') print() @@ -501,7 +495,7 @@ def generate_unpack_kernel(format, dst_channel, dst_native_type): if src_colorspace == SRGB and i == 3: # Alpha channel is linear src_colorspace = RGB - value = src_channel.name + value = src_channel.name value = conversion_expr(src_channel, dst_channel, dst_native_type, value, @@ -516,8 +510,8 @@ def generate_unpack_kernel(format, dst_channel, dst_native_type): assert False print(' dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i])) - def unpack_from_union(channels, swizzles): - print(' union util_format_%s pixel;' % format.short_name()) + def unpack_from_struct(channels, swizzles): + print(' struct util_format_%s pixel;' % format.short_name()) print(' memcpy(&pixel, src, sizeof pixel);') for i in range(4): @@ -528,7 +522,7 @@ def generate_unpack_kernel(format, dst_channel, dst_native_type): if src_colorspace == SRGB and i == 3: # Alpha channel is linear src_colorspace = RGB - value = 'pixel.chan.%s' % src_channel.name + value = 'pixel.%s' % src_channel.name value = conversion_expr(src_channel, dst_channel, dst_native_type, value, @@ -546,7 +540,7 @@ def generate_unpack_kernel(format, dst_channel, dst_native_type): if format.is_bitmask(): print_channels(format, unpack_from_bitmask) else: - print_channels(format, unpack_from_union) + print_channels(format, unpack_from_struct) def generate_pack_kernel(format, src_channel, src_native_type): @@ -592,10 +586,10 @@ def generate_pack_kernel(format, src_channel, src_native_type): print(' *(uint%u_t *)dst = value;' % depth) - def pack_into_union(channels, swizzles): + def pack_into_struct(channels, swizzles): inv_swizzle = inv_swizzles(swizzles) - print(' union util_format_%s pixel;' % format.short_name()) + print(' struct util_format_%s pixel;' % format.short_name()) for i in range(4): dst_channel = channels[i] @@ -611,14 +605,14 @@ def generate_pack_kernel(format, src_channel, src_native_type): dst_channel, dst_native_type, value, dst_colorspace = dst_colorspace) - print(' pixel.chan.%s = %s;' % (dst_channel.name, value)) + print(' pixel.%s = %s;' % (dst_channel.name, value)) print(' memcpy(dst, &pixel, sizeof pixel);') if format.is_bitmask(): print_channels(format, pack_into_bitmask) else: - print_channels(format, pack_into_union) + print_channels(format, pack_into_struct) def generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix): |