Click here to Skip to main content
15,741,215 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all.

I have a question.

I try to use '_mm_extract_epi8' function, which has 'const int ndx' parameter.

int _mm_extract_epi8(
__m128i a,
const int ndx

If I want to use as below, what should I do?

__m128i my128i;

for (int i=0; i<16; i++)
    _mm_extract_epi8(my128i, i); // I want to increase position.

What I have tried:

I modified code as below, but it doesn't work.
for (int i=0; i<15; i++)
    const int idx=i;
    _mm_extract_epi8(my128i, idx);  // Compile Error!

Error message : error C2057: expected constant expression.

So, I copy and paste the function.
_mm_extract_epi8(my128i, 0);
_mm_extract_epi8(my128i, 1);
_mm_extract_epi8(my128i, 2);
_mm_extract_epi8(my128i, 15);
Updated 5-Dec-16 19:48pm
[no name] 5-Dec-16 20:31pm    
What EXACTLY is the compile errror? Use "Improve question".
Joe Pizzi 5-Dec-16 22:26pm    
Your error message is from the line, const int idx = i. Since i is not a constant, the compiler cannot generate code for that line. The code you have in the first code block (the one that says, "I want to increase position.") looks right to me. What isn't working in that code?

The expression, "const int ndx" in the parameter list is telling you that the called function, _mm_extract_epi8, will not alter the value of the variable passed in for position number 2 of the call. It does not restrict the value that you give it.

As an aside, between your first and second examples, you changed the maximum iteration of the loop from 15 to 14. I don't know if you intended that. There is nothing in your question that indicates that was not a mistake.
[no name] 6-Dec-16 0:22am    
"Your error message is from the line, const int idx = "
Not correct. It just means idx cannot be changed.

At first blush both code examples should compile. Something is missing.
Philippe Mori 7-Dec-16 11:06am    
Something is missing in that question as at first glance there are no visible problem. So the problem might be related to how some other symbol is defined.

Maybe there are some macro tricks or some platform/hardware specific stuff...

1 solution

All that const does on a function parameter is ensure that the variable cannot be changed inside the function body - so it is safe to pass a constant value such as 5 as well a variable value such as numberOfMembers because the function cannot alter the value.
So just call it inside the loop like a "normal" function:
_mm_extract_epi8(my128i, i);
Share this answer
CPallini 6-Dec-16 2:51am    
That's it. 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900