用汇编语言写的光线追踪核心求交代码

ExpandedBlockStart.gif ContractedBlock.gif     __asm  dot.gif {
InBlock.gif
InBlock.gif        
//    dot_nd = - ( normal.x * ray_dir.x + normal.y * ray_dir.y + normal.z * ray_dir.z );
InBlock.gif
InBlock.gif        
//    optimized version :
InBlock.gif
InBlock.gif        
//        xmm0 <--------------------------- 0
InBlock.gif        
//        xmm1
InBlock.gif        
//        xmm2
InBlock.gif        
//        xmm3 <--------------------------- ray->src
InBlock.gif        
//        xmm4 <--------------------------- ray->dir
InBlock.gif        
//        xmm5 <--------------------------- dot_nd
InBlock.gif        
//        xmm6 <--------------------------- t
InBlock.gif        
//        xmm7
InBlock.gif

InBlock.gif        xorps        xmm0, xmm0                                ;
InBlock.gif        mov            ebx, dword ptr ray                        ;
InBlock.gif        mov            edi, dword ptr state                    ;
InBlock.gif        mov            esi, dword ptr 
this                        ;
InBlock.gif
InBlock.gif        movaps        xmm3, xmmword ptr [ebx]e_Ray.src        ;
InBlock.gif        movaps        xmm4, xmmword ptr [ebx]e_Ray.dir        ;
InBlock.gif
InBlock.gif        movaps        xmm5, xmmword ptr [esi]
this.normal        ;
InBlock.gif        movaps        xmm6, xmm5                                ;
InBlock.gif
InBlock.gif        prefetchnta 
byte ptr [esi+TYPE this]                ;
InBlock.gif
InBlock.gif        movaps        xmm7, xmm4                                ;
InBlock.gif        mulps        xmm5, xmm7                                ;
InBlock.gif        movhlps        xmm7, xmm5                                ;
InBlock.gif        addss        xmm7, xmm5                                ;
InBlock.gif        shufps        xmm5, xmm5, 
1                            ;
InBlock.gif        addss        xmm7, xmm5                                ;
InBlock.gif        movaps        xmm5, xmm0                                ;
InBlock.gif        subss        xmm5, xmm7                                ;
InBlock.gif 
InBlock.gif        
//    if( dot_nd <= 0.0f )
InBlock.gif

InBlock.gif        comiss        xmm0, xmm5                                ;
InBlock.gif        movss        dword ptr dot_nd, xmm5                    ;
InBlock.gif
InBlock.gif        
//        return false;
InBlock.gif

InBlock.gif        jae            RETURN_FALSE                            ;
InBlock.gif
InBlock.gif
161  :     t = ray_src.x * normal.x + ray_src.y * normal.y + ray_src.z * normal.z + normal.w;
InBlock.gif
InBlock.gif        movaps        xmm7, xmm3                                ;
InBlock.gif        mulps        xmm7, xmm6                                ;
InBlock.gif        movhlps        xmm6, xmm7                                ;
InBlock.gif        addss        xmm6, xmm7                                ;
InBlock.gif        shufps        xmm7, xmm7, 
253                            ;
InBlock.gif        addss        xmm6, xmm7                                ;
InBlock.gif        movhlps        xmm7, xmm7                                ;
InBlock.gif        addss        xmm6, xmm7                                ;
InBlock.gif
InBlock.gif        
//    if( t <= t_near * dot_nd )
InBlock.gif

InBlock.gif        movss        xmm7, dword ptr [ebx]e_Ray.t_near        ;
InBlock.gif
InBlock.gif        mulss        xmm7, xmm5                                ;
InBlock.gif        comiss        xmm7, xmm6                                ;
InBlock.gif        movss        dword ptr t, xmm6                        ;
InBlock.gif
InBlock.gif        
//        return false;
InBlock.gif

InBlock.gif        jae            RETURN_FALSE                            ;
InBlock.gif 
InBlock.gif        
//    t_far = MIN( ray->t_far, state->t );
InBlock.gif

InBlock.gif        movss        xmm7, dword ptr [edi]e_RayState.t        ;
InBlock.gif        comiss        xmm7, dword ptr [ebx]e_Ray.t_far        ;
InBlock.gif        jbe            CASE_BELOW                                ;
InBlock.gif        movss        xmm7, dword ptr [ebx]e_Ray.t_far        ;
InBlock.gif
InBlock.gifCASE_BELOW:
InBlock.gif
InBlock.gif        
//    if( t >= t_far * dot_nd )
InBlock.gif

InBlock.gif        mulss        xmm7, xmm5                                ;
InBlock.gif        comiss        xmm6, xmm7                                ;
InBlock.gif
InBlock.gif        
//        return false;
InBlock.gif

InBlock.gif        jae            RETURN_FALSE                            ;
InBlock.gif
InBlock.gif        
//    hit.arr[ projX ] = ray_src.arr[ projX ] * dot_nd + ray_dir.arr[ projX ] * t;
InBlock.gif

InBlock.gif        movzx        eax, 
byte ptr [esi]this.projX            ;
InBlock.gif        add            eax, eax                                ;
InBlock.gif        add            eax, eax                                ;
InBlock.gif        movss        xmm1, dword ptr [ebx
+eax]e_Ray.src        ;
InBlock.gif        movss        xmm2, dword ptr [ebx
+eax]e_Ray.dir        ;
InBlock.gif        mulss        xmm1, xmm5                                ;
InBlock.gif        mulss        xmm2, xmm6                                ;
InBlock.gif        addss        xmm1, xmm2                                ;
InBlock.gif        movss        dword ptr [hit
+eax], xmm1                ;
InBlock.gif
InBlock.gif        
//    hit.arr[ projY ] = ray_src.arr[ projY ] * dot_nd + ray_dir.arr[ projY ] * t;
InBlock.gif

InBlock.gif        movzx        ecx, 
byte ptr [esi]this.projY            ;
InBlock.gif        add            ecx, ecx                                ;
InBlock.gif        add            ecx, ecx                                ;
InBlock.gif        movss        xmm1, dword ptr [ebx
+ecx]e_Ray.src        ;
InBlock.gif        movss        xmm2, dword ptr [ebx
+ecx]e_Ray.dir        ;
InBlock.gif        mulss        xmm1, xmm5                                ;
InBlock.gif        mulss        xmm2, xmm6                                ;
InBlock.gif        addss        xmm1, xmm2                                ;
InBlock.gif        movss        dword ptr [hit
+ecx], xmm1                ;
InBlock.gif
InBlock.gif        
//    bary.x = hit.arr[ projX ] * la.x + hit.arr[ projY ] * la.y + la.z * dot_nd;
InBlock.gif

InBlock.gif        movss        xmm7, dword ptr [esi]
this.la.x            ;
InBlock.gif        mulss        xmm7, dword ptr [hit
+eax]                ;
InBlock.gif        movss        xmm1, dword ptr [esi]
this.la.y            ;
InBlock.gif        mulss        xmm1, dword ptr [hit
+ecx]                ;
InBlock.gif        addss        xmm7, xmm1                                ;
InBlock.gif        movss        xmm1, dword ptr [esi]
this.la.z            ;
InBlock.gif        mulss        xmm1, xmm5                                ;
InBlock.gif        addss        xmm7, xmm1                                ;
InBlock.gif 
InBlock.gif        
//    if( bary.x < 0.0f || bary.x > dot_nd )
InBlock.gif

InBlock.gif        comiss        xmm0, xmm7                                ;
InBlock.gif        ja            RETURN_FALSE                            ;
InBlock.gif        comiss        xmm7, xmm5                                ;
InBlock.gif        ja            RETURN_FALSE                            ;
InBlock.gif 
InBlock.gif        
//    bary.y = hit.arr[ projX ] * lb.x + hit.arr[ projY ] * lb.y + lb.z * dot_nd;
InBlock.gif

InBlock.gif        movss        xmm2, dword ptr [esi]
this.lb.x            ;
InBlock.gif        mulss        xmm2, dword ptr [hit
+eax]                ;
InBlock.gif        movss        xmm1, dword ptr [esi]
this.lb.y            ;
InBlock.gif        mulss        xmm1, dword ptr [hit
+ecx]                ;
InBlock.gif        addss        xmm2, xmm1                                ;
InBlock.gif        movss        xmm1, dword ptr [esi]
this.lb.z            ;
InBlock.gif        mulss        xmm1, xmm5                                ;
InBlock.gif        addss        xmm2, xmm1                                ;
InBlock.gif
InBlock.gif        
//    if( bary.y < 0.0f || bary.y > dot_nd )
InBlock.gif

InBlock.gif        comiss        xmm0, xmm2                                ;
InBlock.gif        ja            RETURN_FALSE                            ;
InBlock.gif        comiss        xmm2, xmm5                                ;
InBlock.gif        ja            RETURN_FALSE                            ;
InBlock.gif
InBlock.gif        
//    bary.z = dot_nd - bary.x - bary.y;
InBlock.gif

InBlock.gif        movaps        xmm1, xmm5                                ;
InBlock.gif        subss        xmm1, xmm7                                ;
InBlock.gif        subss        xmm1, xmm2                                ;
InBlock.gif 
InBlock.gif        
//    if( bary.z < 0.0f || bary.z > dot_nd )
InBlock.gif

InBlock.gif        comiss        xmm0, xmm1                                ;
InBlock.gif        ja            RETURN_FALSE                            ;
InBlock.gif        comiss        xmm1, xmm5                                ;
InBlock.gif        ja            RETURN_FALSE                            ;
InBlock.gif
InBlock.gif        movss        dword ptr bary.x, xmm7                    ;
InBlock.gif        movss        dword ptr bary.y, xmm2                    ;
InBlock.gif        movss        dword ptr bary.z, xmm1                    ;
InBlock.gif
ExpandedBlockEnd.gif    }
     //     __asm
posted on 2007-07-14 19:41 Len3d 阅读( ...) 评论( ...) 编辑 收藏

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值