[LAD] is this a compiler issue??

Jens M Andreasen jens.andreasen at comhem.se
Wed Aug 19 11:06:16 UTC 2009


#include <xmmintrin.h> 

#define CPUID(f,ax,bx,cx,dx) __asm__ __volatile__ \
("cpuid": "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) : "a" (f))

// denormal protection

static int  set_DAZ_and_FTZ(int /*bool*/ on)
{
   int sse_level = 0;
   
   if(on)    
   {
      unsigned long ax, bx, cx, dx;
      
      CPUID(0x00,ax,bx,cx,dx);
      CPUID(0x01,ax,bx,cx,dx);
            
      if (dx & 0x02000000) 
      {
	 sse_level = 1;  
	 // set FLUSH_TO_ZERO to ON and
	 // set round towards zero (RZ)
	 _mm_setcsr(_mm_getcsr() | 0x8000|0x6000);

	 if (dx & 0x04000000) 
	 {
	    sse_level = 2;
              
	    if (cx & 0x00000001) 
	    {
	       sse_level = 3;
	       // set DENORMALS_ARE_ZERO to ON
	       _mm_setcsr(_mm_getcsr() | 0x0040); 
	    }
	    // we should have checked for AMD K8 without SSE3 here:
	    // if(AMD_K8_NO_SSE3) 
            // .. but I can't recall how to that :-/        
	 }
      }
   } else  
      // clear underflow and precision flags 
      // and set DAZ and FTZ to OFF 
      // and restore round to nearest (RN)
      _mm_setcsr(_mm_getcsr() & ~(0x0030|0x8000|0x0040|0x6000));
   
   return sse_level;
}


On Wed, 2009-08-19 at 12:37 +0200, Tim Goetze wrote:
> [Conrad Berhörster]
> >But i try to understand, what happens here. Is the compiler overoptimizing 
> >zeros. 
> 
> It'd be a lot more helpful to see the full source but from what you're 
> writing I'd be willing to bet you're encountering denormals.
> 
> Cheers, Tim





More information about the Linux-audio-dev mailing list