aco: add and use RegClass::get() helper
authorRhys Perry <pendingchaos02@gmail.com>
Tue, 14 Apr 2020 19:32:39 +0000 (20:32 +0100)
committerMarge Bot <eric+marge@anholt.net>
Fri, 24 Apr 2020 18:52:54 +0000 (18:52 +0000)
Eventually, we'll probably want to replace the current
RegClass(type, size) constructor with this.

This has a functional change in that get_reg_class() now creates v1/v2
instead of v4b/v8b.

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4639>

src/amd/compiler/aco_instruction_selection_setup.cpp
src/amd/compiler/aco_ir.h

index 7d404b425689cd97d71cd79a4047ea43925cee6c..08f8782e8fa2baa17c8a3850d2fc03254ec09959 100644 (file)
@@ -226,21 +226,10 @@ sanitize_cf_list(nir_function_impl *impl, bool *divergent, struct exec_list *cf_
 
 RegClass get_reg_class(isel_context *ctx, RegType type, unsigned components, unsigned bitsize)
 {
-   switch (bitsize) {
-   case 1:
+   if (bitsize == 1)
       return RegClass(RegType::sgpr, ctx->program->lane_mask.size() * components);
-   case 8:
-      return type == RegType::sgpr ? s1 : RegClass(type, components).as_subdword();
-   case 16:
-      return type == RegType::sgpr ? RegClass(type, DIV_ROUND_UP(components, 2)) :
-                                     RegClass(type, 2 * components).as_subdword();
-   case 32:
-      return RegClass(type, components);
-   case 64:
-      return RegClass(type, components * 2);
-   default:
-      unreachable("Unsupported bit size");
-   }
+   else
+      return RegClass::get(type, components * bitsize / 8u);
 }
 
 void init_context(isel_context *ctx, nir_shader *shader)
index 812a116eb292da236ca3d5333143b73b1365d3c8..d63526e90f33e6df85ac09598465962de591917f 100644 (file)
@@ -230,6 +230,15 @@ struct RegClass {
    constexpr RegClass as_linear() const { return RegClass((RC) (rc | (1 << 6))); }
    constexpr RegClass as_subdword() const { return RegClass((RC) (rc | 1 << 7)); }
 
+   static constexpr RegClass get(RegType type, unsigned bytes) {
+      if (type == RegType::sgpr) {
+         return RegClass(type, DIV_ROUND_UP(bytes, 4u));
+      } else {
+         return bytes % 4u ? RegClass(type, bytes).as_subdword() :
+                             RegClass(type, bytes / 4u);
+      }
+   }
+
 private:
    RC rc;
 };