[Mesa-dev] [PATCH] gallivm: Improve lp_build_rcp_refine.

Jose Fonseca jfonseca at vmware.com
Thu Jun 27 06:10:13 UTC 2019

On 25/06/2019 16:22, Roland Scheidegger wrote:
> Looks good to me, albeit it's potentially minimally slower, so I'm
> wondering if the higher precision is actually useful?

It gets you an extra bit, and is necessary if you want to reach 0.5 ULP 
(otherwise it never gets there.)

Anyway, it's still disabled.  This change is mostly for reference in 
case we once want to enable this code path.  We could still use, in 
situations where we don't get or don't care for inf.  Like perspective 
correct interpolation.

> I guess though the last two steps could use lp_build_fmuladd?

Good point.  I've updated to only use fmuladd.  It might be faster and 
converge even more quickly:

@@ -2724,12 +2724,12 @@ lp_build_rcp_refine(struct lp_build_context *bld,
                      LLVMValueRef rcp_a)
     LLVMBuilderRef builder = bld->gallivm->builder;
-   LLVMValueRef two = lp_build_const_vec(bld->gallivm, bld->type, 2.0);
+   LLVMValueRef neg_a;
     LLVMValueRef res;

-   res = LLVMBuildFMul(builder, a, rcp_a, "");
-   res = LLVMBuildFSub(builder, two, res, "");
-   res = LLVMBuildFMul(builder, rcp_a, res, "");
+   neg_a = LLVMBuildFNeg(builder, a, "");
+   res = lp_build_fmuladd(builder, neg_a, rcp_a, bld->one);
+   res = lp_build_fmuladd(builder, res, rcp_a, rcp_a);

     return res;


More information about the mesa-dev mailing list