[Mesa-dev] [PATCH] genxml: Remove a redundant identical code for different branches

Gwan-gyeong Mun elongbug at gmail.com
Tue Jul 25 09:51:22 UTC 2017


Before, it generates functions like this,

static inline uint32_t ATTRIBUTE_PURE
RENDER_SURFACE_STATE_RedClearColor_start(const struct gen_device_info *devinfo)
{
   switch (devinfo->gen) {
   case 10: return 384;
   case 9: return 384;
   case 8: return 255;
   case 7:
      if (devinfo->is_haswell) {
         return 255;
      } else {
         return 255;
      }
   case 6: return 0;
   case 5: return 0;
   case 4:
      if (devinfo->is_g4x) {
         return 0;
      } else {
         return 0;
      }
   default:
      unreachable("Invalid hardware generation");
   }
}

After, it generates fuctions without a redundant identical code for different
branches.

static inline uint32_t ATTRIBUTE_PURE
RENDER_SURFACE_STATE_RedClearColor_start(const struct gen_device_info *devinfo)
{
   switch (devinfo->gen) {
   case 10: return 384;
   case 9: return 384;
   case 8: return 255;
   case 7: return 255;
   case 6: return 0;
   case 5: return 0;
   case 4: return 0;
   default:
      unreachable("Invalid hardware generation");
   }
}

Signed-off-by: Mun Gwan-gyeong <elongbug at gmail.com>
---
 src/intel/genxml/gen_bits_header.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/intel/genxml/gen_bits_header.py b/src/intel/genxml/gen_bits_header.py
index 1b3504073b..8084facdb7 100644
--- a/src/intel/genxml/gen_bits_header.py
+++ b/src/intel/genxml/gen_bits_header.py
@@ -83,20 +83,28 @@ ${item.token_name}_${prop}(const struct gen_device_info *devinfo)
    case 10: return ${item.get_prop(prop, 10)};
    case 9: return ${item.get_prop(prop, 9)};
    case 8: return ${item.get_prop(prop, 8)};
+% if item.get_prop(prop, 7) == item.get_prop(prop, 7.5):
+   case 7: return ${item.get_prop(prop, 7)};
+% else:
    case 7:
       if (devinfo->is_haswell) {
          return ${item.get_prop(prop, 7.5)};
       } else {
          return ${item.get_prop(prop, 7)};
       }
+% endif
    case 6: return ${item.get_prop(prop, 6)};
    case 5: return ${item.get_prop(prop, 5)};
+% if item.get_prop(prop, 4) == item.get_prop(prop, 4.5):
+   case 4: return ${item.get_prop(prop, 4)};
+% else:
    case 4:
       if (devinfo->is_g4x) {
          return ${item.get_prop(prop, 4.5)};
       } else {
          return ${item.get_prop(prop, 4)};
       }
+% endif
    default:
       unreachable("Invalid hardware generation");
    }
-- 
2.13.3



More information about the mesa-dev mailing list