用SSE汇编求向量的点积

ExpandedBlockStart.gif ContractedBlock.gif class  __declspec(align( 16 )) vector4  dot.gif {
InBlock.gif
public:
ExpandedSubBlockStart.gifContractedSubBlock.gif    union 
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
struct dot.giffloat x, y, z, w; };
InBlock.gif        __m128 mm;
ExpandedSubBlockEnd.gif    }
;
ExpandedBlockEnd.gif}
;
None.gif
None.gifinline 
void  dot3( vector4  &  r,  const  vector4  &  x,  const  vector4  &  y )
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//*register vector4    s;
InBlock.gif    s.mm = _mm_mul_ps( x.mm , y.mm );
InBlock.gif    r.mm = _mm_add_ss( s.mm , _mm_movehl_ps( s.mm , s.mm ) );
ExpandedSubBlockEnd.gif    r.mm = _mm_add_ss( r.mm , _mm_shuffle_ps( r.mm , r.mm , 1 ) );
*/

ExpandedSubBlockStart.gifContractedSubBlock.gif    __asm 
dot.gif{
InBlock.gif        mov        ecx, y
InBlock.gif        mov        edx, x
InBlock.gif        mov        eax, r
InBlock.gif        movaps    xmm0, xmmword ptr [ecx]
InBlock.gif        movaps    xmm1, xmmword ptr [edx]
InBlock.gif        mulps    xmm1, xmm0        
//    xmm1 = s0, s1, s2, s3
InBlock.gif
        movhlps    xmm0, xmm1        //    xmm0 = s2, s3, *, *
InBlock.gif
        addss    xmm0, xmm1        //    xmm0 = s0+s2, s3, *, *
InBlock.gif
        shufps    xmm1, xmm1, 1    //    xmm1 = s1, s0, s0, s0
InBlock.gif
        addss    xmm0, xmm1        //    xmm0 = s0+s2+s1, s3, *, *
InBlock.gif
        movaps    xmmword ptr [eax], xmm0
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
None.gifinline 
void  dot4( vector4  * r,  const  vector4  * x,  const  vector4  * y )
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//*register vector4    s;
InBlock.gif    s.mm = _mm_mul_ps( x->mm , y->mm );
InBlock.gif    r->mm = _mm_add_ss( s.mm , _mm_movehl_ps( s.mm , s.mm ) );
InBlock.gif    r->mm = _mm_add_ss( r->mm , _mm_shuffle_ps( r->mm , r->mm , 1 ) );
ExpandedSubBlockEnd.gif    r->mm = _mm_add_ss( r->mm , _mm_shuffle_ps( r->mm , r->mm , 3 ) );
*/

ExpandedSubBlockStart.gifContractedSubBlock.gif    __asm 
dot.gif{
InBlock.gif        mov        ecx, y
InBlock.gif        mov        edx, x
InBlock.gif        mov        eax, r
InBlock.gif        movaps    xmm0, xmmword ptr [ecx]
InBlock.gif        movaps    xmm1, xmmword ptr [edx]
InBlock.gif        mulps    xmm1, xmm0        
//    xmm1 = s0, s1, s2, s3
InBlock.gif
        movhlps    xmm0, xmm1        //    xmm0 = s2, s3, *, *
InBlock.gif
        addss    xmm0, xmm1        //    xmm0 = s0+s2, s3, *, *
InBlock.gif
        shufps    xmm1, xmm1, 253    //    xmm1 = s1, s3, s3, s3
InBlock.gif
        addss    xmm0, xmm1        //    xmm0 = s0+s2+s1, s3, *, *
InBlock.gif
        movhlps    xmm1, xmm1        //    xmm1 = s3, s3, s3, s3
InBlock.gif
        addss    xmm0, xmm1        //    xmm0 = s0+s2+s1+s3, s3, *, *
InBlock.gif
        movaps    xmmword ptr [eax], xmm0
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}
posted on 2007-07-14 17:15 Len3d 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/len3d/archive/2007/07/14/818165.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值