linux编程的108种奇淫巧计-16(如何达到内存最大带宽,复杂指令)【续】

    接上文:http://blog.csdn.net/pennyliang/archive/2011/03/08/6231709.aspx

    按照惯例,首先对代码进行一些解释。

    rdtsc函数是获取机器开机的时间戳。下面这段文字来自intel指令手册:

    Loads the current value of the processor’s time-stamp counter (a 64-bit MSR) into
the EDX:EAX registers and also loads the IA32_TSC_AUX MSR (address
C000_0103H) into the ECX register. The EDX register is loaded with the high-order
32 bits of the IA32_TSC MSR; the EAX register is loaded with the low-order 32 bits of
the IA32_TSC MSR; and the ECX register is loaded with the low-order 32-bits of
IA32_TSC_AUX MSR. On processors that support the Intel 64 architecture, the highorder
32 bits of each of RAX, RDX, and RCX are cleared.

      其中=a是EAX的简写和=d是EDX寄存器的简写,表示该指令的结果EAX寄存器存放在lo中,EDX寄存器存放在hi中。这并不难理解,该系列第二篇博客也介绍过rdtsc指令。

  1.    static __inline__ unsigned long long rdtsc(void)   
  2. {   
  3.   unsigned hi, lo;  
  4.   __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));   
  5.   return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );   
  6. }   

   64位程序参数传递的方法和32位有很大不同,是通过寄存器来传递的,m_b_64(to,from,qdword_cnt);   这段函数在执行前,首先将to指向的地址存放在RDI寄存器中,然后将from指向的地址存放在RSI寄存器中,qdword_cnt存放在RDX寄存器中。而REP MOVSQ的含义是:Move RCX quadwords from[RSI] to [RDI].因此需要将存放在RDX寄存器的qdword_cnt存放在RCX寄存器内。

  

   关于REP MOVSQ/MOVSW/MOVSD/MOVSB命令的详细情况,可查询intel指令手册。

 

   以上内存拷贝方法差距不大,MOVSQ并没有比MOVSB有显著提升,后面还会介绍更多的方法,会大幅度提高内存拷贝的性能,待续。

 

  • 0
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 12
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值