Skip to content

Commit

Permalink
Cherry-pick change from astcenc 4.1.0 (#623)
Browse files Browse the repository at this point in the history
Without the fix SSE2 and SSE4.1 builds that use the decompressor APIs can generate faults on masked stores, as _mm_maskmoveu_si128() doesn't suppress faults on any lanes that are disabled. AVX2 builds are not impacted by this - the AVX2 masked store does suppress faults on masked lanes.
  • Loading branch information
solidpixel authored Aug 18, 2022
1 parent 7149d4f commit f8dc35f
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion lib/astc-encoder/Source/astcenc_vecmathlib_sse_4.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,14 @@ struct vmask4
m = _mm_castsi128_ps(mask.m);
}

/**
* @brief Get the scalar value of a single lane.
*/
template <int l> ASTCENC_SIMD_INLINE float lane() const
{
return _mm_cvtss_f32(_mm_shuffle_ps(m, m, l));
}

/**
* @brief The vector ...
*/
Expand Down Expand Up @@ -1192,7 +1200,27 @@ ASTCENC_SIMD_INLINE void store_lanes_masked(int* base, vint4 data, vmask4 mask)
#if ASTCENC_AVX >= 2
_mm_maskstore_epi32(base, _mm_castps_si128(mask.m), data.m);
#else
_mm_maskmoveu_si128(data.m, _mm_castps_si128(mask.m), reinterpret_cast<char*>(base));
// Note - we cannot use _mm_maskmoveu_si128 as the underlying hardware doesn't guarantee
// fault suppression on masked lanes so we can get page faults at the end of an image.
if (mask.lane<3>() != 0.0f)
{
store(data, base);
}
else if(mask.lane<2>() != 0.0f)
{
base[0] = data.lane<0>();
base[1] = data.lane<1>();
base[2] = data.lane<2>();
}
else if(mask.lane<1>() != 0.0f)
{
base[0] = data.lane<0>();
base[1] = data.lane<1>();
}
else if(mask.lane<0>() != 0.0f)
{
base[0] = data.lane<0>();
}
#endif
}

Expand Down

0 comments on commit f8dc35f

Please sign in to comment.