flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > fasmx - .while with .break .and .continue |
Author |
|
typedef 24 Dec 2011, 23:41
But why ? Feeling smart ?
|
|||
24 Dec 2011, 23:41 |
|
AsmGuru62 25 Dec 2011, 13:48
Cool! But I never use these things.
Here is a reason: in a lot of cases I want to see if code falls down or branches to a label. It is good to know for optimizing reasons, because when code falls down - CPU does it faster than a branch, because fall down is predicted by CPU. Here is a code example(s): Code: proc1: cmp ecx, [glb_VectorCount] jae .ret_null ; ; Get vector value and return ; mov ebx, [glb_VectorBuf] mov eax, [ebx + ecx*4] ret .ret_null xor eax, eax ret ; ; ----------------------------------------------- ; proc2: cmp ecx, [glb_VectorCount] jb .idx_good xor eax, eax ret .idx_good: mov ebx, [glb_VectorBuf] mov eax, [ebx + ecx*4] ret Now, if you look closely at these two functions - they both do same thing: they VALIDATE the index into a vector of 32-bit values and if index is in range of [0 .. glb_VectorCount-1] - the value at that index is returned in EAX. However, notice how the code flow changes in proc2 vs. proc1. I always look at my code flow in a statistical point of view. How many times the index will be CORRECT vs. INCORRECT? I assume that it will be CORRECT most of the time, so code flow in proc1 is much better than flow in proc2, because in proc2 code in MOST CASES will jump forward and the CPU can't predict these jumps. So, back to the topic - using these macros hides the real code flow - it show the logic very nicely, however, but I value the performance -- we're talking about Assembler, not C. |
|||
25 Dec 2011, 13:48 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.