[Mesa-dev] [PATCH 07/11] swr: [rasterizer] Interpolation utility functions

Rowley, Timothy O timothy.o.rowley at intel.com
Tue Apr 19 20:52:20 UTC 2016


> On Apr 14, 2016, at 4:42 PM, Roland Scheidegger <sroland at vmware.com> wrote:
> 
> Am 14.04.2016 um 21:53 schrieb Tim Rowley:
>> 
>> diff --git a/src/gallium/drivers/swr/rasterizer/core/frontend.h b/src/gallium/drivers/swr/rasterizer/core/frontend.h
>> index 8307c0b..12e7ae4 100644
>> --- a/src/gallium/drivers/swr/rasterizer/core/frontend.h
>> +++ b/src/gallium/drivers/swr/rasterizer/core/frontend.h
>> @@ -307,6 +307,18 @@ bool CanUseSimplePoints(DRAW_CONTEXT *pDC)
>>             !state.rastState.pointSpriteEnable);
>> }
>> 
>> +INLINE
>> +bool vIsNaN(const __m128& vec)
>> +{
>> +    const __m128i& veci = _mm_castps_si128(vec);
>> +    const __m128i fraction = _mm_and_si128(veci, _mm_set1_epi32(0x007fffff));
>> +    const __m128i exponent = _mm_and_si128(veci, _mm_set1_epi32(0x7f800000));
>> +    __m128i result = _mm_cmpeq_epi32(exponent, _mm_set1_epi32(0));
>> +    result = _mm_andnot_si128(_mm_cmpeq_epi32(fraction, _mm_set1_epi32(0)), result);
>> +    int32_t mask = _mm_movemask_ps(_mm_castsi128_ps(result));
>> +    return (mask > 0);
>> +}
> You could do this simpler by just doing abs on the source (which is a and)
> followed by a single _mm_cmpgt_epi32() against max exponent (0x7f800000).
> Or do what lp_build_isnan does: just use _mm_cmp_ps with ordered/eq
> (using same source twice) and revert the bits. (Albeit I think we're not
> using the integer comparisons, which are nominally faster, in that code
> because we might have 8-wide vectors hence when avx but not avx2 isn't
> available this would be quite suboptimal.)
> That said, I'm actually wondering why not just doing a simple single
> unordered comparison, that should give the right result without having
> to invert the bits (though it's possible llvm does this on its own in
> the gallivm code).

Thanks for looking at this.  It turns out we use your suggested method in other areas of the code (VCMPPS_ISNAN in our jit builder, and ComputeNaNMask in the clipper).  An updated patch will be coming.

-Tim



More information about the mesa-dev mailing list