Variables 2 variables in C ++ with asm code

I have a huge function that sorts a very large amount of data int. The code works fine except that it is slower than it should be. My first step in resolving this issue is to place the code asminside C++. How can I exchange 2 variables with asm? I tried this:

_asm{ push a[x]; push a[y]; pop a[x]; pop a[y];}

and this:

_asm(mov eax, a[x];mov ebx,a[y]; mov a[x],ebx; mov a[y],eax;}

but both fail. How can I save time on these exchanges? I am using VS_2010

+3
source share
4 answers

In general, it is very difficult to do better than your compiler with simple code like this.

The compiler, faced with the swap operation for integers, will usually output the code as follows:

mov eax, [x]
mov ebx, [y]
mov [x], ebx
mov [y], eax

, , . - , ; . , , , , /. ; , asm.

, push/push/pop/pop, , ; , , . mov , , .. .

, - ; . , . , ( ) , .

+4

, , ?
, , , , , - .

+2

, . , , a[x], .

, asm .

, , , .

+1

, , , , . EAX , EAX , clobbered EBX , . EBX , , .

+1

All Articles