Mesa (master): i965: Mark brw_reg_type and register_file enums as PACKED.

Matt Turner mattst88 at kemper.freedesktop.org
Sat Feb 22 06:50:00 UTC 2014


Module: Mesa
Branch: master
Commit: 98e2654880ef57617e82b6a75578d2ac5f2d6c6c
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=98e2654880ef57617e82b6a75578d2ac5f2d6c6c

Author: Matt Turner <mattst88 at gmail.com>
Date:   Wed Feb 19 18:37:11 2014 -0800

i965: Mark brw_reg_type and register_file enums as PACKED.

The C99 spec says the type of an enum is implementation defined (but can
be char, signed int, or unsigned int). gcc appears to always give enums
four bytes, even when they can fit in less. It does so because this is
what other compilers seem to do [0] and therefore to maintain ABI
compatibility with them.

gcc has an -fshort-enum flag that tells the compiler to use only as much
space as needed for an enum. Adding __attribute__((__packed__)) to an
enum definition has the same behavior, but on a per-enum basis.

brw_reg_type and register_file are not part of the ABI, so we can safely
mark them as PACKED so that they'll take only a byte, rather than four.

[0] http://gcc.gnu.org/onlinedocs/gcc/Non-bugs.html#index-fshort-enums-3868

Acked-by: Kenneth Graunke <kenneth at whitecape.org>

---

 src/mesa/drivers/dri/i965/brw_reg.h    |    3 ++-
 src/mesa/drivers/dri/i965/brw_shader.h |    3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_reg.h b/src/mesa/drivers/dri/i965/brw_reg.h
index a0de75e..38c0ae5 100644
--- a/src/mesa/drivers/dri/i965/brw_reg.h
+++ b/src/mesa/drivers/dri/i965/brw_reg.h
@@ -44,6 +44,7 @@
 
 #include <stdbool.h>
 #include "main/imports.h"
+#include "main/compiler.h"
 #include "program/prog_instruction.h"
 #include "brw_defines.h"
 
@@ -91,7 +92,7 @@ brw_is_single_value_swizzle(int swiz)
            swiz == BRW_SWIZZLE_WWWW);
 }
 
-enum brw_reg_type {
+enum PACKED brw_reg_type {
    BRW_REGISTER_TYPE_UD = 0,
    BRW_REGISTER_TYPE_D,
    BRW_REGISTER_TYPE_UW,
diff --git a/src/mesa/drivers/dri/i965/brw_shader.h b/src/mesa/drivers/dri/i965/brw_shader.h
index 4c79861..4d98cbc 100644
--- a/src/mesa/drivers/dri/i965/brw_shader.h
+++ b/src/mesa/drivers/dri/i965/brw_shader.h
@@ -23,11 +23,12 @@
 
 #include <stdint.h>
 #include "brw_defines.h"
+#include "main/compiler.h"
 #include "glsl/ir.h"
 
 #pragma once
 
-enum register_file {
+enum PACKED register_file {
    BAD_FILE,
    GRF,
    MRF,




More information about the mesa-commit mailing list