Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7944 Discussions

Using arithmetic operators with SIMD data types

masych__matvey
Beginner
1,098 Views

Recently, I found Intel post (from 2014) which describes using of arithmetic and logic operators with SIMD data types. I tried to use it in my program, but this doesn't seem to work - compiler just states: "error : no operator "+" matches these operands
1>            operand types are: __m128d + __m128d". I'm using Visuald Studio 2019 with Intel C++ Compiler 19.1. I couldn't find anymore information on that feature beside that one link. Is that a deleted feature? Am i doing something wrong? Am I getting something wrong?

0 Kudos
5 Replies
RahulV_intel
Moderator
1,098 Views

Hi,

I'm facing a similar issue with SIMD arithmetic ops on VS-2019. Whereas on Linux, arithmetic ops on SIMD works fine.

Could you try building this code snippet on VS-19 and tell us the exact error(screenshot would be better) that you are facing?

#include <immintrin.h>
#include <stdio.h>
int main()
{
    __m128 a1 = _mm_set_ps(4.0, 3.0, 2.0, 1.0);
    __m128 a2 = _mm_set_ps(1.0, 2.0, 3.0, 4.0);

    __m128 res = a1 + a2; //Instead of _mm_add_ps
    //__m128 res = _mm_add_ps(a1, a2); using function
    float *f = (float *)&res;

    printf("%f %f %f %f\n",f[0],f[1],f[2],f[3]);
    return 0;
}

Could you also try using _mm_add_ps() function call to add SIMD datatypes and let us know if it works on VS-19?

Thanks,

Rahul

0 Kudos
masych__matvey
Beginner
1,099 Views

Hello, Vaidya. 

So building this code fails:



Studio also shows two errors (the top one says exactly the same thing as the english one):

 

The function version works just fine:

0 Kudos
RahulV_intel
Moderator
1,099 Views

Hi,

Sounds like a bug to me. The documentation is relevant because it works fine on Linux. We will escalate this issue to the concerned team.

Thanks for reporting this.

 

--Rahul

0 Kudos
Viet_H_Intel
Moderator
1,099 Views

It may have to do with Microsoft compatibility. CL also gave error

C:\temp>cl t.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27040 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

t.c
t.c(8): error C2088: '+': illegal for union

C:\temp>icl t.c
Intel(R) C++ Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 19.1.1.216 Build 20200306
Copyright (C) 1985-2020 Intel Corporation.  All rights reserved.

t.c
t.c(8): error: expression must have arithmetic or pointer type
      __m128 res = a1 + a2; //Instead of _mm_add_ps
                   ^

compilation aborted for t.c (code 2)

C:\temp>notepad t.c

#include <immintrin.h>
#include <stdio.h>
int main()
{
    __m128 a1 = _mm_set_ps(4.0, 3.0, 2.0, 1.0);
    __m128 a2 = _mm_set_ps(1.0, 2.0, 3.0, 4.0);

    __m128 res = a1 + a2; //Instead of _mm_add_ps
    //__m128 res = _mm_add_ps(a1, a2);
        float *f = (float *)&res;

     printf("%f %f %f %f\n",f[0],f[1],f[2],f[3]);
     return 0;

}

0 Kudos
Viet_H_Intel
Moderator
946 Views

This issue is fixed in oneAPI2021.2.

$ icpc -V

Intel(R) C++ Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.2.0 Build 20210228_000000


I am going to close this thread.


0 Kudos
Reply