Click here to Skip to main content
15,890,946 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how do i use if- else and treat Adjust in step 2 for the snippet codes below?
C#
.h file
 class tom
{
.
.
.
protected:
    static const int Adjust[6];

protected:
    int _mode;

    int _q;
    int _qm;
    int _qe;
    int _f;
    int _scale
};

.cpp file
const int tom::Adjust[6] =
{
    107,
    916,
    182,
    362,
    192,
    282
};

tom::tom()
{

    _q          = 1;
     _qm        =_q % 6;
    _qe         = _q/6;
    _f          = (1 << (15+_qe))/6;
    _scale  = 15+_qe;
}

void tom::calculate(void* ptr)
{
    short* block = (short *)ptr;
    int j;

     __m64*block1 = (__m64*)block;
     __m64 s0,s1,s2,s3,x0,x1,x2,x3;
      j=0;
        //step 1
s0 =_mm_add_pi16(block1[j],block1[j+3]);
s3 =_mm_sub_pi16(block1[j],block1[j+3]);
s1 =_mm_add_pi16(block1[j+1],block1[j+2]);
s2 =_mm_sub_pi16(block1[j+1],block1[j+2]);

      // step 2
 x0 =_mm_add_pi16(s0,s1);
 if(x0 < 0)
block[j] = (short)(-( (((-x0) * Adjust[_qm]) + _f) >> _scale ));
else
block[j] = (short)( ((x0 * Adjust[_qm]) + _f) >> _scale );
.
.
.
.

_mm_empty();

}
Posted
Updated 30-Sep-10 1:01am
v2

1 solution

It's not so clear for me what is your target, however, as x0 is an _m64 variable used to store 4 integers (16 bit each one), I suppose that with the if-else in your snippet, you mean something like: "how to do this kind of conditional calculation for each of the 4 numbers".
If this is your requirement, pheraps you can work around this formula:

short s = 1 - (n >> 15) * 2

Where n is a short; the value of s will be 1 if n >= 0 and -1 if n < 0
 
Share this answer
 
Comments
SMART LUBOBYA 30-Sep-10 7:18am    
yes, is n=x0 and s=block[j]?thanks for you reply. i will try the formula
Sauro Viti 30-Sep-10 7:49am    
I think you have to implement:
block[j] = (1 - (x0 >> 15) * 2) * (((1 - (x0 >> 15) * 2) * x0 * Adjust[_qm] + _f) >> _scale)
where x0 and block[j] are vectors and all the others are scalar values
SMART LUBOBYA 1-Oct-10 4:18am    
in _m64 intrinsics, how do i write Adjust[_qm]?
SMART LUBOBYA 1-Oct-10 4:19am    
is also possible to write the whole if-else statement in _m64 intrinsics?
Sauro Viti 1-Oct-10 4:33am    
In MMX intrinsics I don't know about operations that involve a vector and a scalar, then I think you have to initialize three__m64 variables for the Adjust, _f and _scale and initialize them with the right values (i.e. with all the 4 fields equals to your current scalar value)

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