diff mbox

[libdrm] intel: Mark large read only local arrays as static const

Message ID CADyApD1Hw4LAxOgQzxVPRFnmHrffLgRuAQVbi8ou4zsyF44ihw@mail.gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Arjan van de Ven June 17, 2013, 12:01 a.m. UTC
From 27eef3eba293163a0c2348566d2470978c3f6c0e Mon Sep 17 00:00:00 2001
From: Arjan van de Ven <arjanvandeven@gmail.com>
Date: Sun, 16 Jun 2013 10:56:35 -0700
Subject: [PATCH 1/2] intel: Mark large read only local arrays as static const

In the instruction decoder, various arrays that are local to functions,
but are read only, were not declared static const... causing the compiler
to construct said array on the stack each call.
Rather than using code to do this... just declare these arrays
static const.

In addition, to avoid relocations, use char [] instead of char *
(as per DSOHowto), this may appear to waste a little bit of space,
but that is very limited in practice, and it means these arrays
can just be mapped in the read-only section.

on x86-64, some basic size results

Before:
libdrm_intel.so.1.0.0: 76 relocations, 69 relative (90%), 56 PLT
entries, 11 for local syms (19%)
[11] .text                PROGBITS     0000000000002c80 00002c80
00013c48  0 AX     0   0 16
[13] .rodata              PROGBITS     00000000000168e0 000168e0
00005c3b  0 A      0   0 32
[19] .data.rel.ro         PROGBITS     000000000021f018 0001f018
00000008  0 WA     0   0  8
[23] .data                PROGBITS     000000000021f440 0001f440
00000640  0 WA     0   0 32
[24] .bss                 NOBITS       000000000021fa80 0001fa80
00000020  0 WA     0   0  8

After:
libdrm_intel.so.1.0.0: 32 relocations, 25 relative (78%), 56 PLT
entries, 11 for local syms (19%)
[11] .text                PROGBITS     0000000000002860 00002860
00011db8  0 AX     0   0 16
[13] .rodata              PROGBITS     0000000000014640 00014640
00005c63  0 A      0   0 32
[19] .data.rel.ro         PROGBITS     000000000021d020 0001d020
00001a08  0 WA     0   0 32
[23] .data                PROGBITS     000000000021ee48 0001ee48
00000008  0 WA     0   0  4
[24] .bss                 NOBITS       000000000021ee50 0001ee50
00000048  0 WA     0   0  8

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
---
 intel/intel_decode.c | 48 ++++++++++++++++++++++++------------------------
 1 file changed, 24 insertions(+), 24 deletions(-)

  { 0x7828, 0x00ff, 2, 2, "3DSTATE_BINDING_TABLE_POINTERS_DS" },
@@ -3208,10 +3208,10 @@ decode_3d_965(struct drm_intel_decode *ctx)
  { 0x782d, 0x00ff, 2, 2, "3DSTATE_SAMPLER_STATE_POINTERS_DS" },
  { 0x782e, 0x00ff, 2, 2, "3DSTATE_SAMPLER_STATE_POINTERS_GS" },
  { 0x782f, 0x00ff, 2, 2, "3DSTATE_SAMPLER_STATE_POINTERS_PS" },
- { 0x7830, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_URB_VS },
- { 0x7831, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_URB_HS },
- { 0x7832, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_URB_DS },
- { 0x7833, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_URB_GS },
+ { 0x7830, 0x00ff, 2, 2, "", 7, gen7_3DSTATE_URB_VS },
+ { 0x7831, 0x00ff, 2, 2, "", 7, gen7_3DSTATE_URB_HS },
+ { 0x7832, 0x00ff, 2, 2, "", 7, gen7_3DSTATE_URB_DS },
+ { 0x7833, 0x00ff, 2, 2, "", 7, gen7_3DSTATE_URB_GS },
  { 0x7900, 0xffff, 4, 4, "3DSTATE_DRAWING_RECTANGLE" },
  { 0x7901, 0xffff, 5, 5, "3DSTATE_CONSTANT_COLOR" },
  { 0x7905, 0xffff, 5, 7, "3DSTATE_DEPTH_BUFFER" },
@@ -3233,8 +3233,8 @@ decode_3d_965(struct drm_intel_decode *ctx)
  { 0x7917, 0x00ff, 2, 2+128*2, "3DSTATE_SO_DECL_LIST" },
  { 0x7918, 0x00ff, 4, 4, "3DSTATE_SO_BUFFER" },
  { 0x7a00, 0x00ff, 4, 6, "PIPE_CONTROL" },
- { 0x7b00, 0x00ff, 7, 7, NULL, 7, gen7_3DPRIMITIVE },
- { 0x7b00, 0x00ff, 6, 6, NULL, 0, gen4_3DPRIMITIVE },
+ { 0x7b00, 0x00ff, 7, 7, "", 7, gen7_3DPRIMITIVE },
+ { 0x7b00, 0x00ff, 6, 6, "", 0, gen4_3DPRIMITIVE },
  }, *opcode_3d = NULL;

  opcode = (data[0] & 0xffff0000) >> 16;
@@ -3751,11 +3751,11 @@ decode_3d_i830(struct drm_intel_decode *ctx)
  uint32_t opcode;
  uint32_t *data = ctx->data;

- struct {
+ static const struct {
  uint32_t opcode;
  unsigned int min_len;
  unsigned int max_len;
- const char *name;
+ const char name[28];
  } opcodes_3d[] = {
  { 0x02, 1, 1, "3DSTATE_MODES_3" },
  { 0x03, 1, 1, "3DSTATE_ENABLES_1" },
--
1.7.11.7
diff mbox

Patch

diff --git a/intel/intel_decode.c b/intel/intel_decode.c
index ff19f92..fdbbe0c 100644
--- a/intel/intel_decode.c
+++ b/intel/intel_decode.c
@@ -229,12 +229,12 @@  decode_mi(struct drm_intel_decode *ctx)
  const char *post_sync_op = "";
  uint32_t *data = ctx->data;

- struct {
+ static const struct {
  uint32_t opcode;
  int len_mask;
  unsigned int min_len;
  unsigned int max_len;
- const char *name;
+ const char name[24];
  int (*func)(struct drm_intel_decode *ctx);
  } opcodes_mi[] = {
  { 0x08, 0, 1, 1, "MI_ARB_ON_OFF" },
@@ -420,11 +420,11 @@  decode_2d(struct drm_intel_decode *ctx)
  unsigned int opcode, len;
  uint32_t *data = ctx->data;

- struct {
+ static const struct {
  uint32_t opcode;
  unsigned int min_len;
  unsigned int max_len;
- const char *name;
+ const char name[38];
  } opcodes_2d[] = {
  { 0x40, 5, 5, "COLOR_BLT" },
  { 0x43, 6, 6, "SRC_COPY_BLT" },
@@ -1271,12 +1271,12 @@  decode_3d_1d(struct drm_intel_decode *ctx)
  uint32_t *data = ctx->data;
  uint32_t devid = ctx->devid;

- struct {
+ static const struct {
  uint32_t opcode;
  int i830_only;
  unsigned int min_len;
  unsigned int max_len;
- const char *name;
+ const char name[34];
  } opcodes_3d_1d[] = {
  { 0x86, 0, 4, 4, "3DSTATE_CHROMA_KEY" },
  { 0x88, 0, 2, 2, "3DSTATE_CONSTANT_BLEND_COLOR" },
@@ -2543,11 +2543,11 @@  decode_3d(struct drm_intel_decode *ctx)
  unsigned int idx;
  uint32_t *data = ctx->data;

- struct {
+ static const struct {
  uint32_t opcode;
  unsigned int min_len;
  unsigned int max_len;
- const char *name;
+ const char name[34];
  } opcodes_3d[] = {
  { 0x06, 1, 1, "3DSTATE_ANTI_ALIASING" },
  { 0x08, 1, 1, "3DSTATE_BACKFACE_STENCIL_OPS" },
@@ -3138,12 +3138,12 @@  decode_3d_965(struct drm_intel_decode *ctx)
  uint32_t *data = ctx->data;
  uint32_t devid = ctx->devid;

- struct {
+ static const struct {
  uint32_t opcode;
  uint32_t len_mask;
  int unsigned min_len;
  int unsigned max_len;
- const char *name;
+ const char name[34];
  int gen;
  int (*func)(struct drm_intel_decode *ctx);
  } opcodes_3d[] = {
@@ -3169,8 +3169,8 @@  decode_3d_965(struct drm_intel_decode *ctx)
  { 0x780a, 0x00ff, 3, 3, "3DSTATE_INDEX_BUFFER" },
  { 0x780b, 0xffff, 1, 1, "3DSTATE_VF_STATISTICS" },
  { 0x780d, 0x00ff, 4, 4, "3DSTATE_VIEWPORT_STATE_POINTERS" },
- { 0x780e, 0xffff, 4, 4, NULL, 6, gen6_3DSTATE_CC_STATE_POINTERS },
- { 0x780e, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_CC_STATE_POINTERS },
+ { 0x780e, 0xffff, 4, 4, "", 6, gen6_3DSTATE_CC_STATE_POINTERS },
+ { 0x780e, 0x00ff, 2, 2, "", 7, gen7_3DSTATE_CC_STATE_POINTERS },
  { 0x780f, 0x00ff, 2, 2, "3DSTATE_SCISSOR_POINTERS" },
  { 0x7810, 0x00ff, 6, 6, "3DSTATE_VS" },
  { 0x7811, 0x00ff, 7, 7, "3DSTATE_GS" },
@@ -3194,10 +3194,10 @@  decode_3d_965(struct drm_intel_decode *ctx)
  { 0x781e, 0x00ff, 3, 3, "3DSTATE_STREAMOUT" },
  { 0x781f, 0x00ff, 14, 14, "3DSTATE_SBE" },
  { 0x7820, 0x00ff, 8, 8, "3DSTATE_PS" },
- { 0x7821, 0x00ff, 2, 2, NULL, 7,
gen7_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP },
- { 0x7823, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_VIEWPORT_STATE_POINTERS_CC },
- { 0x7824, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_BLEND_STATE_POINTERS },
- { 0x7825, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS },
+ { 0x7821, 0x00ff, 2, 2, "", 7, gen7_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP },
+ { 0x7823, 0x00ff, 2, 2, "", 7, gen7_3DSTATE_VIEWPORT_STATE_POINTERS_CC },
+ { 0x7824, 0x00ff, 2, 2, "", 7, gen7_3DSTATE_BLEND_STATE_POINTERS },
+ { 0x7825, 0x00ff, 2, 2, "", 7, gen7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS },
  { 0x7826, 0x00ff, 2, 2, "3DSTATE_BINDING_TABLE_POINTERS_VS" },
  { 0x7827, 0x00ff, 2, 2, "3DSTATE_BINDING_TABLE_POINTERS_HS" },