[Mesa-dev] [PATCH 1/2] ac: add ac_build_fmin/fmax helpers
Marek Olšák
maraeo at gmail.com
Thu Jan 4 00:55:13 UTC 2018
From: Marek Olšák <marek.olsak at amd.com>
---
src/amd/common/ac_llvm_build.c | 32 ++++++++++++++++++--------------
src/amd/common/ac_llvm_build.h | 5 ++++-
2 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c
index 96ad715..7100e52 100644
--- a/src/amd/common/ac_llvm_build.c
+++ b/src/amd/common/ac_llvm_build.c
@@ -1198,44 +1198,48 @@ ac_build_umsb(struct ac_llvm_context *ctx,
msb = LLVMBuildSub(ctx->builder, LLVMConstInt(ctx->i32, 31, false),
msb, "");
/* check for zero */
return LLVMBuildSelect(ctx->builder,
LLVMBuildICmp(ctx->builder, LLVMIntEQ, arg,
LLVMConstInt(ctx->i32, 0, 0), ""),
LLVMConstInt(ctx->i32, -1, true), msb, "");
}
+LLVMValueRef ac_build_fmin(struct ac_llvm_context *ctx, LLVMValueRef a,
+ LLVMValueRef b)
+{
+ LLVMValueRef args[2] = {a, b};
+ return ac_build_intrinsic(ctx, "llvm.minnum.f32", ctx->f32, args, 2,
+ AC_FUNC_ATTR_READNONE);
+}
+
+LLVMValueRef ac_build_fmax(struct ac_llvm_context *ctx, LLVMValueRef a,
+ LLVMValueRef b)
+{
+ LLVMValueRef args[2] = {a, b};
+ return ac_build_intrinsic(ctx, "llvm.maxnum.f32", ctx->f32, args, 2,
+ AC_FUNC_ATTR_READNONE);
+}
+
LLVMValueRef ac_build_umin(struct ac_llvm_context *ctx, LLVMValueRef a,
LLVMValueRef b)
{
LLVMValueRef cmp = LLVMBuildICmp(ctx->builder, LLVMIntULE, a, b, "");
return LLVMBuildSelect(ctx->builder, cmp, a, b, "");
}
LLVMValueRef ac_build_clamp(struct ac_llvm_context *ctx, LLVMValueRef value)
{
if (HAVE_LLVM >= 0x0500) {
- LLVMValueRef max[2] = {
- value,
- LLVMConstReal(ctx->f32, 0),
- };
- LLVMValueRef min[2] = {
- LLVMConstReal(ctx->f32, 1),
- };
-
- min[1] = ac_build_intrinsic(ctx, "llvm.maxnum.f32",
- ctx->f32, max, 2,
- AC_FUNC_ATTR_READNONE);
- return ac_build_intrinsic(ctx, "llvm.minnum.f32",
- ctx->f32, min, 2,
- AC_FUNC_ATTR_READNONE);
+ return ac_build_fmin(ctx, ac_build_fmax(ctx, value, ctx->f32_0),
+ ctx->f32_1);
}
LLVMValueRef args[3] = {
value,
LLVMConstReal(ctx->f32, 0),
LLVMConstReal(ctx->f32, 1),
};
return ac_build_intrinsic(ctx, "llvm.AMDGPU.clamp.", ctx->f32, args, 3,
AC_FUNC_ATTR_READNONE |
diff --git a/src/amd/common/ac_llvm_build.h b/src/amd/common/ac_llvm_build.h
index 3e0285b..0deb5b5 100644
--- a/src/amd/common/ac_llvm_build.h
+++ b/src/amd/common/ac_llvm_build.h
@@ -234,21 +234,24 @@ void ac_build_sendmsg(struct ac_llvm_context *ctx,
uint32_t msg,
LLVMValueRef wave_id);
LLVMValueRef ac_build_imsb(struct ac_llvm_context *ctx,
LLVMValueRef arg,
LLVMTypeRef dst_type);
LLVMValueRef ac_build_umsb(struct ac_llvm_context *ctx,
LLVMValueRef arg,
LLVMTypeRef dst_type);
-
+LLVMValueRef ac_build_fmin(struct ac_llvm_context *ctx, LLVMValueRef a,
+ LLVMValueRef b);
+LLVMValueRef ac_build_fmax(struct ac_llvm_context *ctx, LLVMValueRef a,
+ LLVMValueRef b);
LLVMValueRef ac_build_umin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
LLVMValueRef ac_build_clamp(struct ac_llvm_context *ctx, LLVMValueRef value);
struct ac_export_args {
LLVMValueRef out[4];
unsigned target;
unsigned enabled_channels;
bool compr;
bool done;
bool valid_mask;
--
2.7.4
More information about the mesa-dev
mailing list