使用__m64数据类型实现if-else [英] Implementing if-else with __m64 data types
本文介绍了使用__m64数据类型实现if-else的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何使用if- else并在下面的代码段中处理第2步中的Adjust ??
how do i use if- else and treat Adjust in step 2 for the snippet codes below?
.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();
}
推荐答案
对我来说,您的目标不是很清楚,因为x0
是用于存储4个整数(每个16位),我想代码段中的if
-else
表示类似:如何对这4个数字中的每个进行这种条件计算" .
如果这是您的要求,可以使用以下公式解决问题:
short s = 1 - (n >> 15) * 2
其中n
是short
;如果n >= 0
,s
的值为1,如果n < 0
It''s not so clear for me what is your target, however, asx0
is an_m64
variable used to store 4 integers (16 bit each one), I suppose that with theif
-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
Wheren
is ashort
; the value ofs
will be 1 ifn >= 0
and -1 ifn < 0
这篇关于使用__m64数据类型实现if-else的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文