ICC error on __m256 access

ICC error on __m256 access

 

Hi, I have this simple program where I try to store a floating point number in a __m256 variable from AVX

#include <stdio.h>
#include <stdlib.h>

#include <x86intrin.h>  


#ifndef __AVX__
#error AVX not defined
#endif

int main( int argc, char *argv[] )
{
        __m256 RR;
        __m256 BB;

        RR.m256_f32[0] = 1.0;
        BB.m256_f32[0] = 1.0;

        return 0;
}

 

But when I compile with ICC i get:

$ icc -march=native -g -O0 -std=c99 -g intel_test_a.c -o intel_test_a -rdynamic -ldl
intel_test_a.c(42): error: expression must have struct or union type
        RR.m256_f32[0] = 1.0;
        ^

intel_test_a.c(43): error: expression must have struct or union type
        BB.m256_f32[0] = 1.0;
        ^

compilation aborted for intel_test_a.c (code 2)

 

just wonder what I'm doing wrong? I am using linux (debian).

 

Thanks

 

 

 

 

 

7 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

 

Here is an even more simple example:

#include <stdio.h>
#include <stdlib.h>

typedef union __m256
{
    float inside[8];
}__m256;

int main(void)
{
    __m256 RR;

    RR.inside[0] = 1.1;

    printf("success, value is %3.2f\n", RR.inside[0]);

    exit(0);
}

 

ICC can not compile while gcc works fine

$ icc -std=c99 -W -Wall -o uacc union_access.c
union_access.c(16): error: expression must have struct or union type
      RR.inside[0] = 1.1;
      ^

union_access.c(18): error: expression must have struct or union type
      printf("success, value is %3.2f\n", RR.inside[0]);
                                          ^

compilation aborted for union_access.c (code 2)

$ gcc -std=c99 -W -Wall -o uacc union_access.c
$ ./uacc
success, value is 1.10

 

 

Did you try to include immintrin.h ?

 

Yes, same result.  But I found a workaround. With ICC to access individual fields in a union like this:

typedef union __m256 {
    float inside[8];
}__m256;
	 

Use this:

__m256 RR;
((float*)&RR)[0] = 1.0;

 

Hi,

The __m256 type is a reserved word in the Intel Compiler and is supported as the intrinsic type and is used to represent the contents of the extended SSE register the YMM register, used by the Intel® AVX intrinsics.

Since these data types are not basic ANSI C data types you must observe the following usage restrictions:
 -> Use data types only on either side of an assignment, as a return value, or as a parameter. You cannot use it with other arithmetic expressions (+, -, etc).
 -> Use data types as objects in aggregates, such as unions, to access the byte elements and structures.
 -> Use data types only with the intrinsics functions.

You should use the intrinsics functions (include immintrin.h) on these data types for all operations. You can refer to the guide at: https://software.intel.com/sites/landingpage/IntrinsicsGuide/ that contains many such functions.

In the last example you show, the reason the compiler outputs the error: "nion_access.c(18): error: expression must have struct or union type"  is because it's a "RESERVED" word in the compiler as mentioned above.

Hope that helps...

_Kittur

Thanks, yes this info was helpful.
 

Thanks for letting me know. As noted, the best method to extract, access and manipulate these data types is through the supported intrinsic functions in the compiler.....

_Kittur

Login to leave a comment.