1

I have the following code as a part of a program, but when I compile it I get the following error:

cannot convert ‘int’ to ‘__m128i {aka __vector(2) long long int}’ in assignment

Where the code is:

int t;
int s;
__m128i *array;
__m128i vector;

posix_memalign ((void **) &array, BYTE_ALIGNMENT, n * m * sizeof(__m128i) );

int l=0;
for (int i=0; i<n; i++)
{
  for (int j=0; j<m; j++)
  {
    array[l] = (condition) ? t : s;   // fill the array elements with s or t 
    l++;
  }
}
vector = _mm_load_si128( &array[index]);

The problem is in this line

array[l] = (condition) ? t : s;

I have found the instruction __m128i _mm_cvtsi32_si128(int a) but unfortunately, it is used for 32-bits elements only, while I have 16-bit elements (vector of size 8).

Paul R
  • 208,748
  • 37
  • 389
  • 560
MROF
  • 147
  • 1
  • 3
  • 9
  • Have you tried using an explicit cast to type `__m128i`? – David R Tribble Jan 30 '15 at 00:21
  • Do you mean like that? array[l] = (condition) ? (__m128i) t : (__m128i) s; It gives me the following error : error: can’t convert between vector values of different size – MROF Jan 30 '15 at 00:27
  • Are you looking for something like: `_mm_set1_epi16()` – Mysticial Jan 30 '15 at 00:39
  • Not exactly, because the set instruction fills the whole vector. While I want to set one element in the vector through every loop based on the condition in the IF statement – MROF Jan 30 '15 at 00:53
  • In another words, I would like to fill the array elements individually based on an IF statement; during the FOR loops. Then load the array to a vector ...While the set instruction will fill the whole array with a static values – MROF Jan 30 '15 at 00:56
  • Are `s` and `t` constant ? And what are the inputs to the `condition` test, i.e. what does `if (condition)` depend on ? – Paul R Jan 30 '15 at 08:47
  • S and T are input variables, and the condition depends on another variables. But we can say that if the condition happens the array [l]=T .. else =S – MROF Jan 30 '15 at 08:50

1 Answers1

0

Finally, i found this update is working properly

int t;
int s;
int16_t *array;
__m128i vector;

posix_memalign ((void **) &array, BYTE_ALIGNMENT, n * m * sizeof(int16_t) );

int l=0;
for (int i=0; i<n; i++)
{
  for (int j=0; j<m; j++)
  {
    array[l] = (condition) ? t : s;   // fill the array elements with s or t 
    l++;
  }
}
vector = _mm_load_si128( (__m128i*)&array[index]);

Thanks for you all

MROF
  • 147
  • 1
  • 3
  • 9
  • Oh - so you didn't even want to vectorise the code ? You were just trying to fix a syntax error ? My bad... – Paul R Feb 01 '15 at 08:16