Mesa (main): ac/llvm,radv: implement uadd_sat/iadd_sat

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Sep 3 13:50:24 UTC 2021


Module: Mesa
Branch: main
Commit: d6619d0a0191cd2c4b986670762073e1b469585e
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=d6619d0a0191cd2c4b986670762073e1b469585e

Author: Rhys Perry <pendingchaos02 at gmail.com>
Date:   Mon Aug 30 14:02:38 2021 +0100

ac/llvm,radv: implement uadd_sat/iadd_sat

Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12617>

---

 src/amd/llvm/ac_nir_to_llvm.c  | 9 +++++++++
 src/amd/vulkan/radv_pipeline.c | 4 +---
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/amd/llvm/ac_nir_to_llvm.c b/src/amd/llvm/ac_nir_to_llvm.c
index c25c677b520..804a1dcd69b 100644
--- a/src/amd/llvm/ac_nir_to_llvm.c
+++ b/src/amd/llvm/ac_nir_to_llvm.c
@@ -626,6 +626,15 @@ static void visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr)
       else
          result = LLVMBuildAdd(ctx->ac.builder, src[0], src[1], "");
       break;
+   case nir_op_uadd_sat:
+   case nir_op_iadd_sat: {
+      char name[64], type[64];
+      ac_build_type_name_for_intr(def_type, type, sizeof(type));
+      snprintf(name, sizeof(name), "llvm.%cadd.sat.%s",
+               instr->op == nir_op_uadd_sat ? 'u' : 's', type);
+      result = ac_build_intrinsic(&ctx->ac, name, def_type, src, 2, AC_FUNC_ATTR_READNONE);
+      break;
+   }
    case nir_op_fadd:
       src[0] = ac_to_float(&ctx->ac, src[0]);
       src[1] = ac_to_float(&ctx->ac, src[1]);
diff --git a/src/amd/vulkan/radv_pipeline.c b/src/amd/vulkan/radv_pipeline.c
index 2f39744148d..3b01545ed6d 100644
--- a/src/amd/vulkan/radv_pipeline.c
+++ b/src/amd/vulkan/radv_pipeline.c
@@ -3495,9 +3495,7 @@ radv_create_shaders(struct radv_pipeline *pipeline, struct radv_device *device,
          /* lower ALU operations */
          nir_lower_int64(nir[i]);
 
-         /* TODO: Implement nir_op_uadd_sat with LLVM. */
-         if (!radv_use_llvm_for_stage(device, i))
-            nir_opt_idiv_const(nir[i], 8);
+         nir_opt_idiv_const(nir[i], 8);
 
          nir_lower_idiv(nir[i],
                         &(nir_lower_idiv_options){



More information about the mesa-commit mailing list