Where did I use a call? #define is not a call.
Printable View
Where did I use a call? #define is not a call.
ASM is not going to be faster than simple bit shifting. If it is, it's minutely so:
#define PACK(a,b) ((a<<8)&b)
result = PAC( somevar, anothervar );
There, now they're packed. With bit shifts and bitwise AND, you really aren't going to get much faster, especially once your compiler optimizes. There really is no point in using ASM for most applications. You're compiler will likely optimize it better than you can with ASM anyway.
Quzah.
"ASM is not going to be faster than simple bit shifting. If it is, it's minutely so:"
I can only answer for my compiler ( MSVC++ ) and having done careful timings I find that if I need to do TWO shifts then asm is almost twice as fast. I am writing a very time critical application - a program that runs for days at a time. The innermost loop boils down to about 50 lines of executed asm code in the disassembler so even saving a couple of lines makes a measurable effect.
In most applications whether the program responds in a hundreth of a second or a tenth does not make much difference but if you are going round a loop hundreds of billions of time it is critical.
Here is the code from the disassembler:
The above is NOT from my supercritical loop and could be further optimised. To take another very simple example:Code:402: dummy >>= 13;
0040279D mov dx,word ptr [ebp-8]
004027A1 shr dx,0Dh
004027A5 mov word ptr [ebp-8],dx
403: dummy <<= 3;
004027A9 mov ax,word ptr [ebp-8]
004027AD shl ax,3
004027B1 mov word ptr [ebp-8],ax
Here is hand coded asm:
_asm{ //Find SECOND variable on "RHS" Bits 4 to 6
mov ax,dummy
shl ax,3 ;Shift 3 "bits" to extreme left
shr ax,13 ;Shift 13 "bits" to extreme right
mov dummy,ax
}
liner++;
My compiler does
mov ax, liner
add ax,1
mov liner,ax
I do
add liner,1
In other words even in the most trivial example the compiler takes three lines to do what can be done in hand coded asm in one line. It is not three times faster but this simple substitituion speeded my program by about 5%. I suspect that it puts the variable into the register because this is not(?) acceptable to older processors but I am the only person likely to run this program so it is OK for me. Plus who is still using 8086 processors?