util,gallivm: Explicitly enable/disable fma attribute.
authorJose Fonseca <jfonseca@vmware.com>
Tue, 24 May 2016 13:36:28 +0000 (22:36 +0900)
committerJose Fonseca <jfonseca@vmware.com>
Fri, 10 Jun 2016 12:47:35 +0000 (13:47 +0100)
As suggested by Roland Scheidegger.

Use the same logic as f16c, since fma requires VEX encoding.

But disable FMA on LLVM 3.3 without MCJIT.

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
src/gallium/auxiliary/gallivm/lp_bld_init.c
src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
src/gallium/auxiliary/util/u_cpu_detect.c
src/gallium/auxiliary/util/u_cpu_detect.h

index cf21ab0653b1a56181ee957ac9f92c594233eb73..22340c081f26390458ca0a02e648b47a22e60357 100644 (file)
@@ -420,6 +420,7 @@ lp_build_init(void)
       util_cpu_caps.has_avx = 0;
       util_cpu_caps.has_avx2 = 0;
       util_cpu_caps.has_f16c = 0;
+      util_cpu_caps.has_fma = 0;
    }
 #endif
 
@@ -454,6 +455,7 @@ lp_build_init(void)
       util_cpu_caps.has_avx = 0;
       util_cpu_caps.has_avx2 = 0;
       util_cpu_caps.has_f16c = 0;
+      util_cpu_caps.has_fma = 0;
    }
 
 #ifdef PIPE_ARCH_PPC_64
index 805a50be09964e9cd65b794e86651d5364389f47..5ffe09c9a1b6732698a41f0a80cf4ecd8437123c 100644 (file)
@@ -570,6 +570,15 @@ lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
     */
    MAttrs.push_back(util_cpu_caps.has_avx  ? "+avx"  : "-avx");
    MAttrs.push_back(util_cpu_caps.has_f16c ? "+f16c" : "-f16c");
+   if (HAVE_LLVM >= 0x0304 || useMCJIT) {
+      MAttrs.push_back(util_cpu_caps.has_fma  ? "+fma"  : "-fma");
+   } else {
+      /*
+       * The old JIT in LLVM 3.3 has a bug encoding llvm.fmuladd.f32 and
+       * llvm.fmuladd.v2f32 intrinsics when FMA is available.
+       */
+      MAttrs.push_back("-fma");
+   }
    MAttrs.push_back(util_cpu_caps.has_avx2 ? "+avx2" : "-avx2");
    /* disable avx512 and all subvariants */
 #if HAVE_LLVM >= 0x0304
index aa3c30af6e3d868fa1992135d2b8907716e4f1c6..3a51ab95cf042a0dfef4cf1230e4fb05638537b4 100644 (file)
@@ -369,6 +369,7 @@ util_cpu_detect(void)
                                     ((regs2[2] >> 27) & 1) && // OSXSAVE
                                     ((xgetbv() & 6) == 6);    // XMM & YMM
          util_cpu_caps.has_f16c   = ((regs2[2] >> 29) & 1) && util_cpu_caps.has_avx;
+         util_cpu_caps.has_fma    = ((regs2[2] >> 12) & 1) && util_cpu_caps.has_avx;
          util_cpu_caps.has_mmx2   = util_cpu_caps.has_sse; /* SSE cpus supports mmxext too */
 #if defined(PIPE_ARCH_X86_64)
          util_cpu_caps.has_daz = 1;
index 5ccfc931697f25e089474f58a27adc0af8f6d892..c873232beccb8acf67964d6580d6474ede54b91b 100644 (file)
@@ -66,6 +66,7 @@ struct util_cpu_caps {
    unsigned has_avx:1;
    unsigned has_avx2:1;
    unsigned has_f16c:1;
+   unsigned has_fma:1;
    unsigned has_3dnow:1;
    unsigned has_3dnow_ext:1;
    unsigned has_xop:1;