Click here to Skip to main content
16,006,494 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how do a load b1 as an array of 4 rows?

b1 = -114 -113 -113 -112 row 0
-93 -95 -90 -92
-25 -26 -23 -25
36 35 35 38 row 3
in my codes f0 is loaded with 8 elements (column 1 and 2 of b1)
and f1 is loaded with 8 elements as well(columns 3 and 4).what i want is to change the loading to 4 elements according to rows.something like:
f0 =114 -113 -113 -112
f1 =-93 -95 -90 -92
f2 = -25 -26 -23 -25
f3 =36 35 35 38
how do i achieve this given my snippet codes


C++
void tom::add(void* btr)
{

__declspec(align(16))short* b =(short*)btr;

  _declspec(align(16))__m128i* b1=(__m128i*)b;
  __m128i f0,f1,f2,f3,temp;
            temp = (_mm_set_epi32(0,0,0,0));

    f0 = _mm_load_si128(b1);//-114,-93,-25,36,-113,-95,-26,35
    f1 = _mm_load_si128(b1+1);//-113,-90,-23,35,-112,-92,-25,38<</xml>
Posted
Updated 16-Aug-10 0:35am
v2

1 solution

May be a variant :) :
void tom::add(short* pshData, int iCount)
{
  if (4 * 4 <= iCount) {
    int* piData = new int[iCount];
    while (iCount--) {
      piData[iCount] = pshData[iCount];
    }

    _m128i* p128Data = (_m128i*) piData;
    _m128i f0 = _mm_load_si128(p128Data++);
    _m128i f1 = _mm_load_si128(p128Data++);
    _m128i f2 = _mm_load_si128(p128Data++);
    _m128i f3 = _mm_load_si128(p128Data);

    //..

    delete[] piData;
  }
}
 
Share this answer
 
v2
Comments
SMART LUBOBYA 16-Aug-10 9:07am    
i did this but i get error C2661, see codes below
void tom::add (short* ptr,int icount)
{
if (4*4<=icount){
int*block2 = new int[icount];
for(int i = 0; i < icount; i++)
{
block2[i]=ptr[i];
}
__m128i* block3=(__m128i*)block2;
__m128i f0 = *block3++;
__m128i f1 = *block3++;
__m128i f2 = *block3++;
__m128i f3 = *block3;
__m128i s0 = _mm_add_epi16(f0,f3);
__m128i s3 = _mm_sub_epi16(f0,f3);

delete[]block2;
}
}
void tom::add (void* pIn, void* pCoeff)
{

memcpy(pCoeff, pIn, sizeof(short) * 16);
add(pCoeff); //tom.cpp(280) : error C2661: ' tom::add' : no overloaded function takes 1 arguments
}
Eugen Podsypalnikov 16-Aug-10 9:11am    
Try to extend your call: add(pCoeff, 16); :)
SMART LUBOBYA 16-Aug-10 11:35am    
is there a way of achieving the same result changing the declaration of add from:
void tom::add(void* btr) to void tom::add (short* ptr,int icount)
{
i have several files connected to this .cpp file. kindly help.
SMART LUBOBYA 16-Aug-10 11:36am    
is there a way of achieving the same result without changing the declaration of add from:
void tom::add(void* btr) to void tom::add (short* ptr,int icount)
{
i have several files connected to this .cpp file. kindly help
Eugen Podsypalnikov 16-Aug-10 14:13pm    
Yes, there is...
...but the function will not be "safe"
(it will access up to short[15] without any knowledge, how many shorts were passed :)) :
void tom::add(void* pData)
{
short* pshData = (short*) pData;
int* piData = new int[16];
for (int i = 0; i < 16; i++) {
piData[i] = pshData[i]; // possible access outside of the bounderies (!)
}

//...

delete[] piData;
}

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