[Mesa-dev] suspect rcp code in llvmpipe

Jose Fonseca jfonseca at vmware.com
Fri Nov 30 07:38:39 PST 2012


----- Original Message -----
> On 11/30/2012 03:10 AM, Dave Airlie wrote:
> > coverity pointed out the below as suspect, since num_iterations =
> > 0,
> > and we do a loop from 0..0
> >
> > Dave.
> >
> >   if (FALSE&&  ((util_cpu_caps.has_sse&&  type.width == 32&&
> > type.length == 4) ||
> >           (util_cpu_caps.has_avx&&  type.width == 32&&  type.length
> >           == 8))){
> >        const unsigned num_iterations = 0;
> >        LLVMValueRef res;
> >        unsigned i;
> >        const char *intrinsic = NULL;
> >
> >        if (type.length == 4) {
> >           intrinsic = "llvm.x86.sse.rcp.ps";
> >        }
> >        else {
> >           intrinsic = "llvm.x86.avx.rcp.ps.256";
> >        }
> >
> >        res = lp_build_intrinsic_unary(builder, intrinsic,
> >        bld->vec_type, a);
> >
> >        for (i = 0; i<  num_iterations; ++i) {
> >           res = lp_build_rcp_refine(bld, a, res);
> >        }
> > _______________________________________________
> > mesa-dev mailing list
> > mesa-dev at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/mesa-dev
> 
> I guess we could set num_iterations = 1 for now but it doesn't really
> matter since this block of code is disabled (note the "if (FALSE)"
> part).
> 
> Jose, I think you wrote that code.

The code is correct with  num_iterations = 0. This means no Newton-Raphson iterations.

But as Brian said, this is disabled, because RCP + Newton-Raphson gives wrong results for 0 / Inf, which causes bad rendering on certain apps. So we just use DIV. But I'd rather keep the code there fore reference, as these things might change. (In particular, in certain cases we can be sure that input is not 0/Inf/Nan, so we could use this there).

Jose


More information about the mesa-dev mailing list