[LAD] A more efficient way to detect INF and/or NAN in a block of samples

Kjetil Matheussen k.s.matheussen at gmail.com
Sun Oct 6 11:34:47 UTC 2013


I want to detect INFs and NANs in my DSP graph to avoid having
them spread and cause various trouble.

Here is the straight forward way:

int i;
for (i=0;i<num_samples;i++)
  if (!isfinite(samples[i])) break

if(i!=num_samples)
  error();

But is this as efficient as we get it?


I'm wondering if comparing samples using for instance SIMD
instructions, for instance, could make it around 4 times faster,
Something like this:

for(i=0;i<num_samples;i++)
  if(samples[i]!=samples[i]))
     break;

where the samples[i]!=samples[i] test would succeed
if it was a nan or inf, since INFs and NANs don't behave normally.

I don't think this particular example works though (?),
but perhaps something similar could?

Anyone doing something like this?


More information about the Linux-audio-dev mailing list