在装配单纯高位乘法? [英] Pure high-bit multiplication in assembly?

查看:1201
本文介绍了在装配单纯高位乘法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要实现0和1之间的实数,人们通常使用ANSI漂浮或双打。但是,0和1(小数模1)之间的固定的precision号可以有效地实现32位的整数或16位字,其中新增像普通整数/词,而是乘走错了路,意思是当你乘X倍Y,您保持产品的高位。这相当于乘以0.X和0.Y,其中X的所有位都在小数点后面。同样,签署数字之间-1和1也可实现这种方式与一个额外的位和移位。

To implement real numbers between 0 and 1, one usually uses ANSI floats or doubles. But fixed precision numbers between 0 and 1 (decimals modulo 1) can be efficiently implemented as 32 bit integers or 16 bit words, which add like normal integers/words, but which multiply the "wrong way", meaning that when you multiply X times Y, you keep the high order bits of the product. This is equivalent to multiplying 0.X and 0.Y, where all the bits of X are behind the decimal point. Likewise, signed numbers between -1 and 1 are also implementable this way with one extra bit and a shift.

一个人怎么会实现(尤其是在使用MMX或SSE)固定precision MOD 1或2的MOD用C?
我觉得这再presentation可能是酉矩阵的高效再presentation有用的,数字密集型的物理模拟。它使更多的MMX / SSE有整数数量,但你需要更高PMULHW级别的访问。

How would one implement fixed-precision mod 1 or mod 2 in C (especially using MMX or SSE)? I think this representation could be useful for efficient representation of unitary matrices, for numerically intensive physics simulations. It makes for more MMX/SSE to have integer quantities, but you need higher level access to PMULHW.

推荐答案

如果16位定点运算就足够了,你是在x86或类似的架构,可以直接使用SSE。搜索结果

If 16 bit fixed point arithmetic is sufficient and you are on x86 or a similar architecture, you can directly use SSE.

SSE3指令 pmulhrsw 直接实现签约0.15定点算术乘法运算(模2正如你所说的,从-1 .. + 1)硬件。除了不低于标准的16位矢量操作不同,只是用 PADDW

The SSE3 instruction pmulhrsw directly implements signed 0.15 fixed point arithmetic multiplication (mod 2 as you call it, from -1..+1) in hardware. Addition is not different than the standard 16 bit vector operations, just using paddw.

因此​​,这一次只处理乘法和加法八个符号的16位定点变量的库看起来是这样的:

So a library which handles multiplication and addition of eight signed 16 bit fixed point variables at a time could look like this:

typedef __v8hi fixed16_t;

fixed16_t mul(fixed16_t a, fixed16_t b) {
    return _mm_mulhrs_epi16(a,b);
}

fixed16_t add(fixed16_t a, fixed16_t b) {
    return _mm_add_epi16(a,b);
}

权限授予任何你喜欢的方式来使用它; - )

Permission granted to use it in any way you like ;-)

这篇关于在装配单纯高位乘法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆