Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Raphael_C_
Beginner
142 Views

Complex types in Intel C Compiler 17 appear not to conform to specs

Consider

#include <complex.h>
complex float f(complex float x) {
  return x*x;
}

If you compile it with -O3 -march=core-avx2 -fp-model strict using the Intel Compiler you get:

f:
        vmovsldup xmm1, xmm0                                    #3.12
        vmovshdup xmm2, xmm0                                    #3.12
        vshufps   xmm3, xmm0, xmm0, 177                         #3.12
        vmulps    xmm4, xmm1, xmm0                              #3.12
        vmulps    xmm5, xmm2, xmm3                              #3.12
        vaddsubps xmm0, xmm4, xmm5                              #3.12
        ret 

The good news is that the code is much simpler than what you get from gcc and clang. The bad news is that it doesn't handle Infinity and NaN according to the C99 specs as far I can tell (which is why it is so much simpler).

Is the compiler intended to be C99 conforming with these flag options or is there another set of flags that forces it to be?

 

 

0 Kudos
7 Replies
SergeyKostrov
Valued Contributor II
142 Views

>>...Is the compiler intended to be C99 conforming with these flag options or is there another set of flags that forces it to be? Execute icl.exe -help ( on Windows ) or icpc -help ( on Linux ) and look for a section Language for a list of all supported C/C++ languages standards.
Raphael_C_
Beginner
142 Views

I get exactly the same code when I specify -std=c99  .

As far I can tell this is a bug in ICC's support for complex float/double.   As a non-corporate user is there some way I can report this bug?  I am just using the version of icpc installed at my university.

 

SergeyKostrov
Valued Contributor II
142 Views

>>#include [complex.h] >>complex float f(complex float x) >>{ >> return x*x; >>} 1. I don't think this is a bug because at compile time Intel C++ compiler doesn't have any information about values in the variable x. 2. At runtime a Floating Point Unit ( FPU ) takes care about all processing situations you've mentioned and I'm absolutely confident that all these processing situations are properly handled according to IEEE 754 Standard ( released in 1985 as far as I remember, that is 14 years before 1999 ). 3. I also think that if an option to emulate FPU is used then additional code could be generated.
Raphael_C_
Beginner
142 Views

The point is that in order to be compliant, as I specified in the question, the code needs to check for infinities.  The code to do that correctly is given in Annex G.5.1.6.  Here is a link that discusses it:

https://locklessinc.com/articles/complex_multiplication/

The code ICC produces simply doesn't do any of these checks.

 

SergeyKostrov
Valued Contributor II
142 Views

>>...The code ICC produces simply doesn't do any of these checks. The best way to proceed is to create a test case that does some processing with Infinity and NaN values in the variable x of type complex.
Raphael_C_
Beginner
142 Views

If you use INF + i NAN as input for the ICC function the result is NaN + i NaN while it should be a complex number with at least one component infinite (per standard).    I don't know how to test this except directly using the assembly.

I also asked a very similar question with x*y for which it's easier to make  a test case only in C. Take a look at it here https://software.intel.com/en-us/forums/intel-c-compiler/topic/711186 .

SergeyKostrov
Valued Contributor II
142 Views

Please do not post any comments in that thread since all discussions are now in . https://software.intel.com/en-us/forums/intel-c-compiler/topic/711186 Thanks in advance.
Reply