gallivm: add no-signed-zeros-fp-math option to lp_create_builder (v2)
authorMarek Olšák <marek.olsak@amd.com>
Sun, 29 Jan 2017 21:45:36 +0000 (22:45 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 21 Feb 2017 20:27:23 +0000 (21:27 +0100)
v2: define lp_float_mode

Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
src/gallium/auxiliary/gallivm/lp_bld_misc.h
src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c

index e005469a56575145bafd5d9eb7dc9a4b5eb8a334..444686fdc799497d84af72e33cc9810aaa7c35e7 100644 (file)
@@ -781,15 +781,24 @@ lp_is_function(LLVMValueRef v)
 }
 
 extern "C" LLVMBuilderRef
-lp_create_builder(LLVMContextRef ctx, bool unsafe_fpmath)
+lp_create_builder(LLVMContextRef ctx, enum lp_float_mode float_mode)
 {
    LLVMBuilderRef builder = LLVMCreateBuilderInContext(ctx);
 
 #if HAVE_LLVM >= 0x0308
-   if (unsafe_fpmath) {
-      llvm::FastMathFlags flags;
+   llvm::FastMathFlags flags;
+
+   switch (float_mode) {
+   case LP_FLOAT_MODE_DEFAULT:
+      break;
+   case LP_FLOAT_MODE_NO_SIGNED_ZEROS_FP_MATH:
+      flags.setNoSignedZeros();
+      llvm::unwrap(builder)->setFastMathFlags(flags);
+      break;
+   case LP_FLOAT_MODE_UNSAFE_FP_MATH:
       flags.setUnsafeAlgebra();
       llvm::unwrap(builder)->setFastMathFlags(flags);
+      break;
    }
 #endif
 
index c499a6f51ebbea43b7f3decf02586c11b1f1c83b..6abb30d73fa7fd182a4477fe892e3790d81e017c 100644 (file)
@@ -82,8 +82,14 @@ lp_get_called_value(LLVMValueRef call);
 extern bool
 lp_is_function(LLVMValueRef v);
 
+enum lp_float_mode {
+   LP_FLOAT_MODE_DEFAULT,
+   LP_FLOAT_MODE_NO_SIGNED_ZEROS_FP_MATH,
+   LP_FLOAT_MODE_UNSAFE_FP_MATH,
+};
+
 extern LLVMBuilderRef
-lp_create_builder(LLVMContextRef ctx, bool unsafe_fpmath);
+lp_create_builder(LLVMContextRef ctx, enum lp_float_mode float_mode);
 
 #ifdef __cplusplus
 }
index 6618009610a70d90b04e8e45b4bd894dd7ae43d8..69eaf0c6364567c1710e8ba948b98e57dd7bc6ad 100644 (file)
@@ -1267,8 +1267,12 @@ void si_llvm_context_init(struct si_shader_context *ctx,
 #endif
 
        bool unsafe_fpmath = (sscreen->b.debug_flags & DBG_UNSAFE_MATH) != 0;
+       enum lp_float_mode float_mode =
+               unsafe_fpmath ? LP_FLOAT_MODE_UNSAFE_FP_MATH :
+                               LP_FLOAT_MODE_DEFAULT;
+
        ctx->gallivm.builder = lp_create_builder(ctx->gallivm.context,
-                                                unsafe_fpmath);
+                                                float_mode);
 
        ac_llvm_context_init(&ctx->ac, ctx->gallivm.context);
        ctx->ac.module = ctx->gallivm.module;