Linux programming's 108 odd tricks-16 (how to achieve the maximum memory bandwidth, complex instructions) [continued]

Source: Internet
Author: User

Link: http://blog.csdn.net/pennyliang/archive/2011/03/08/6231709.aspx

According to the Convention, first explain the code.

The rdtsc function is used to obtain the machine startup timestamp. The following text comes from Intel instruction manual:

Loads the current value of the processor's time-stamp counter (a 64-bit MSR)
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
The ia32_tsc MSR; and The ECX register is loaded with the low-order 32-bits
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.

Where = A is short for eax and = D is short for the edX register, indicating that the eax register of the command is stored in Lo, and the edx register is stored in HI. This is not hard to understand. The second blog in this series also introduced the rdtsc command.

  1. Static_ Inline _ unsignedLong LongRdtsc (Void)
  2. {
  3. Unsigned hi, lo;
  4. _ ASM _ volatile _ ("rdtsc": "= A" (LO), "= D" (HI ));
  5. Return(UnsignedLong Long) LO) | (unsignedLong Long) HI) <32 );
  6. }

The method for passing 64-bit program parameters is very different from that for 32-bit programs. It is passed through registers, m_ B _64 (to, from, qdword_cnt). Before executing this function, first, store the address pointed to by to in the RDI register, then store the address pointed to by from in the RSI register, and the qdword_cnt is stored in the RDX register. The meaning of rep movsq is: Move rcX quadwords from [RSI] to [RDI]. Therefore, you need to store qdword_cnt in the rcX register.

For details about the rep movsq/movsw/movsd/movsb command, see the Intel instruction manual.

 

The above memory copy method is not much different. movsq has not significantly improved compared with movsb. More methods will be introduced later, which will greatly improve the performance of memory copy, to be continued.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.