flat assembler
Message board for the users of flat assembler.
Index
> Main > will it cause slower if |
Author |
|
l4m2 30 Jul 2016, 04:27
Code: mov eax, edx xor edx, edx Code: xchg eax, edx xor edx, edx |
|||
30 Jul 2016, 04:27 |
|
comrade 30 Jul 2016, 04:46
First seems better: it does not create a write dependency on edx that conflicts with xor edx,edx.
|
|||
30 Jul 2016, 04:46 |
|
shutdownall 30 Jul 2016, 09:19
Well in that case I personally would prefer:
Code: xor eax,eax xchg eax,edx |
|||
30 Jul 2016, 09:19 |
|
JohnFound 31 Jul 2016, 06:40
For me the first is also, more clear as code and this way is still "better".
|
|||
31 Jul 2016, 06:40 |
|
sinsi 31 Jul 2016, 07:09
Small optimisation: XCHG is a one byte opcode, MOV is two.
|
|||
31 Jul 2016, 07:09 |
|
revolution 31 Jul 2016, 08:38
sinsi wrote: Small optimisation: XCHG is a one byte opcode, MOV is two. Code: xchg eax, edx xor edx, edx some_label: ;<--- this might be at 0x1f mod 0x20 and/or cross a page boundary ;code jnz some_label Code: mov eax, edx xor edx, edx some_label: ;<--- now aligned at 0x00 mod 0x20 bcause "mov" is one byte longer ;code jnz some_label Last edited by revolution on 31 Jul 2016, 12:00; edited 1 time in total |
|||
31 Jul 2016, 08:38 |
|
l4m2 31 Jul 2016, 09:44
When I say "which is better", I usually mean "In what case is the first better, the second better, etc.
XCHG saves a byte. If the code rarely executed, it won't make too much bad on speed but a little save on memory |
|||
31 Jul 2016, 09:44 |
|
revolution 31 Jul 2016, 10:14
l4m2 wrote: If the code rarely executed, it won't make too much bad on speed ... Note: "optimise" is of course ambiguous. It will mean different things to different people, and also different things to the same person in different places. |
|||
31 Jul 2016, 10:14 |
|
l4m2 31 Jul 2016, 12:12
revolution wrote: If the code rarely executed then don't worry about it. |
|||
31 Jul 2016, 12:12 |
|
revolution 31 Jul 2016, 12:18
l4m2 wrote: If size cared about, you should shorten it. But your title in this thread asks clearly "will it cause slower if", which is a reference to speed. So now we are not sure what you really want. Last edited by revolution on 31 Jul 2016, 12:56; edited 1 time in total |
|||
31 Jul 2016, 12:18 |
|
l4m2 31 Jul 2016, 12:45
Obviously XCHG is 1 byte shorter. If we only care about size that's an optimize. However, if it makes slower, shouldn't use it as optimize when more attention to speed.
|
|||
31 Jul 2016, 12:45 |
|
El Tangas 31 Jul 2016, 16:14
Obviously, the best way is:
Code: mov eax,1 mul edx |
|||
31 Jul 2016, 16:14 |
|
shutdownall 01 Aug 2016, 15:23
revolution wrote:
And how are you sure that the code has been aligned before reaching this instruction part ? Maybe the single byte opcode creates that desired alignment. |
|||
01 Aug 2016, 15:23 |
|
revolution 01 Aug 2016, 15:25
shutdownall wrote:
|
|||
01 Aug 2016, 15:25 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.