i remember a post how to realize swap(int x,int y) the fastest way, and without a buffer-value
means:
no
swap(int& x,int& y)
{
int buffer=x;
x=y;
y=buffer;
}
,thats not allowed
after learning alittle bout asm and so, i wrote now 3 nice makros everyone could use:
#define swap32(a,b) __asm{mov eax,(a)}__asm{xchg eax,(b)}__asm{mov (a),eax}
#define swap16(a,b) __asm{mov ax,(a)}__asm{xchg ax,(b)}__asm{mov (a),ax}
#define swap8(a,b) __asm{mov al,(a)}__asm{xchg al,(b)}__asm{mov (a),al}
with them you can swap two chars,short/long ints,floats with just 3 asm calls, u just have to use the right version:
char x=23,y=34;
swap8(x,y);
or float x=24.34f,y=3254.21f;
swap32(x,y);
hope this helps alittle
we wanna play, not watch the pictures
swap8 swap16 swap32
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia
My Page davepermen.net | My Music on Bandcamp and on Soundcloud
nice one mate you could also use this in c
a ^= b ^= a ^= b;
http://members.xoom.com/myBollux
a ^= b ^= a ^= b;
http://members.xoom.com/myBollux
look at the asm code of your ^=^=^=, bout 6 asm statements, i think.. mine has just 3
but yours is a nice fast way in c/c++
btw, my statement also works for floats, how bout yours?
we wanna play, not watch the pictures
but yours is a nice fast way in c/c++
btw, my statement also works for floats, how bout yours?
we wanna play, not watch the pictures
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia
My Page davepermen.net | My Music on Bandcamp and on Soundcloud
Those two statement will probably run as equivalent code since xchg will be broken down when compiled, into move than other statements
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia
My Page davepermen.net | My Music on Bandcamp and on Soundcloud
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement