Fix undefined behavior in array overflow. The GCC 5.2 warning that

brought this to my attention was:

src/nvtt/squish/simd_sse.h:90:28: warning: iteration 16u invokes
undefined behavior [-Waggressive-loop-optimizations]
   m_v = _mm_add_ps( m_v, v.m_v );

src/nvtt/squish/fastclusterfit.cpp:146:22: note: containing loop
  for( int c0 = 0; c0 <= 16; c0++)

and again for the loop on line 259.  In the latter case this loop
construct results in writes to m_unweighted[16] which is declated as
"VecX m_unweighted[16]".  I did not analyze the prior loop as
carefully.  I believe that this commit was what was intended, but I'm
not certain.
pull/231/head
cfcohen 9 years ago
parent f55b7d438a
commit ea2ac753b0

@ -143,11 +143,11 @@ void FastClusterFit::Compress3( void* block )
int i = 0;
// check all possible clusters for this total order
for( int c0 = 0; c0 <= 16; c0++)
for( int c0 = 0; c0 < 16; c0++)
{
x1 = zero;
for( int c1 = 0; c1 <= 16-c0; c1++)
for( int c1 = 0; c1 < 16-c0; c1++)
{
Vec4 const constants = Vec4((const float *)&s_threeElement[i]);
Vec4 const alpha2_sum = constants.SplatX();
@ -256,15 +256,15 @@ void FastClusterFit::Compress4( void* block )
int i = 0;
// check all possible clusters for this total order
for( int c0 = 0; c0 <= 16; c0++)
for( int c0 = 0; c0 < 16; c0++)
{
Vec4 x1 = zero;
for( int c1 = 0; c1 <= 16-c0; c1++)
for( int c1 = 0; c1 < 16-c0; c1++)
{
Vec4 x2 = zero;
for( int c2 = 0; c2 <= 16-c0-c1; c2++)
for( int c2 = 0; c2 < 16-c0-c1; c2++)
{
Vec4 const constants = Vec4((const float *)&s_fourElement[i]);
Vec4 const alpha2_sum = constants.SplatX();

Loading…
Cancel
Save