What C ++ code compiles before the x86 REP statement?

I copy elements from one array to another in C ++. I found an instruction rep movsin x86 that seems to copy an array in ESI to an array in ECX size EDI. However, neither the loops fornor the whileones I tried to compile into a command rep movsin VS 2008 (on an Intel Xeon x64 processor). How to write code to be compiled for this instruction?

+5
source share
6 answers

If you need exactly this instruction, use the built-in assembler and write this instruction manually. You cannot rely on the compiler to create any specific machine code - even if it emits it in one compilation, it may decide to emit some other equivalent during the next compilation.

+3
source

Honestly, you should not. REP is a kind of obsolete retention in the instruction set and is actually quite slow since it must call a micro-encoded subroutine inside the CPU that has a ROM search delay and is also unpipulated.

In almost every implementation, you will find that the built-in compiler memcpy()is easier to use and faster.

+10

MSVC __movsxxx __stosxxx, REP.

"", memset aka REP STOS vc9 +, - sse2 crt. , __stosxxx - , .

#define memset(mem,fill,size) memset((DWORD*)mem,((fill) << 24|(fill) << 16|(fill) << 8|(fill)),size)
__forceinline void memset(DWORD* pStart, unsigned long dwFill, size_t nSize)
{
    //credits to Nepharius for finding this
    DWORD* pLast = pStart + (nSize >> 2);
    while(pStart < pLast)
        *pStart++ = dwFill;

    if((nSize &= 3) == 0)
        return;

    if(nSize == 3)
    {
        (((WORD*)pStart))[0]   = WORD(dwFill);
        (((BYTE*)pStart))[2]   = BYTE(dwFill);
    }
    else if(nSize == 2)
        (((WORD*)pStart))[0]   = WORD(dwFill);
    else
        (((BYTE*)pStart))[0]   = BYTE(dwFill);
}

REP , memcpy, sse2, REPS MOV ( msvc), , "" ...

+5

rep * cmps *, movs *, scas * stos * , , / , . memset memcpy - , , , 10-20 rep (, , , ).

/ , , .

0

- - , "rep movs *" ( ..) . , Pentium/Pentium MMX. ( , ), , (< = / ), rep, , , .

, rep , / .

0

REP -, x86 CISC- .

. , - , , , (VLIW- ) ( , , single-write, et.c.). , , VLIW, , . Loop- , , .

, , - , , !

, . REP , , -muppet, , , , , , .

( , , . , . 100% x86 , ..)

0
source

All Articles