Mesa (master): mesa: Shrink the size of the enum string lookup struct.

Eric Anholt anholt at kemper.freedesktop.org
Mon Sep 23 19:50:16 UTC 2013


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

Author: Eric Anholt <eric at anholt.net>
Date:   Thu Sep 19 14:54:13 2013 -0700

mesa: Shrink the size of the enum string lookup struct.

Since it's only used for debug information, we can misalign the struct and
save the disk space.  Another 19k on a 64-bit build.

v2: Make a compiler.h macro to only use the attribute if we know we can.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick at .intel.com>

---

 src/mapi/glapi/gen/gl_enums.py |    6 ++++--
 src/mesa/main/compiler.h       |    9 +++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/mapi/glapi/gen/gl_enums.py b/src/mapi/glapi/gen/gl_enums.py
index e1ab600..a0c47f4 100644
--- a/src/mapi/glapi/gen/gl_enums.py
+++ b/src/mapi/glapi/gen/gl_enums.py
@@ -47,8 +47,8 @@ class PrintGlEnums(gl_XML.gl_print_base):
         print '#include "main/imports.h"'
         print '#include "main/mtypes.h"'
         print ''
-        print 'typedef struct {'
-        print '   size_t offset;'
+        print 'typedef struct PACKED {'
+        print '   uint16_t offset;'
         print '   int n;'
         print '} enum_elt;'
         print ''
@@ -78,6 +78,8 @@ static char token_tmp[20];
 
 const char *_mesa_lookup_enum_by_nr( int nr )
 {
+   STATIC_ASSERT(sizeof(enum_string_table) < (1 << 16));
+
    enum_elt *elt = _mesa_bsearch(& nr, enum_string_table_offsets,
                                  Elements(enum_string_table_offsets),
                                  sizeof(enum_string_table_offsets[0]),
diff --git a/src/mesa/main/compiler.h b/src/mesa/main/compiler.h
index fb7baf8..0f27d5a 100644
--- a/src/mesa/main/compiler.h
+++ b/src/mesa/main/compiler.h
@@ -270,6 +270,15 @@ static INLINE GLuint CPU_TO_LE32(GLuint x)
 #define NULL 0
 #endif
 
+/* Used to optionally mark structures with misaligned elements or size as
+ * packed, to trade off performance for space.
+ */
+#if (__GNUC__ >= 3)
+#define PACKED __attribute__((__packed__))
+#else
+#define PACKED
+#endif
+
 
 /**
  * LONGSTRING macro




More information about the mesa-commit mailing list