• Advertisement

Archived

This topic is now archived and is closed to further replies.

Fast Zero Checking

This topic is 5451 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there, Does anyone know a fast method for checking if an array of floats are all equal to zero? Is there an assembly instruction for checking contiguous memory? tia

Share this post


Link to post
Share on other sites
Advertisement
Yes.

xor eax, eax
mov ecx, cnt
mov edi, buf
repz scasd
jnz not_all_0


A loop will likely be faster, though, on >= 586 CPUs.
Compare dwords, not floats (requires fcom, fnstsw, lahf => sloow), and unroll the loop. If the array is really big, think about checking qwords at a time; also, prefetch.

Share this post


Link to post
Share on other sites

  • Advertisement