Skip to main content
GameDev.net gamedev.net
🔒 Locked

Fast Zero Checking

Started by sQuid Mar 24, 2003 at 1:19 AM 1 replies 350+ views
Original Post
sQuid
sQuid
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
Jan Wassenberg
Jan Wassenberg
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.
E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3
sQuid
sQuid
thanks for that.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.