looks like here and in several other places you do not handle the case when ndisp is not divisible by 8. The common idiom is to use
<pre>
int loop_counter = 0;
#if &lt;USE_SIMD&gt;
    // unrolled part of the loop
    for( /* initialization section is omitted */ ; loop_counter <= max_value - unroll_factor; loop_counter += unroll_factor )
{ /* vectorized SIMD code */ }
#endif // note that we use endif, without else
for( /* initialization section is also omitted */ ; loop_counter < max_value; loop_counter++ )
{ /* scalar C code */ }
</pre>