flat assembler
Message board for the users of flat assembler.
Index
> Main > which 2-byte nop goes better |
Author |
|
l4m2 28 Jul 2016, 13:23
mov ax,ax
ds:nop xchg bx,bx xchg eax,eax (66 90) 67 90 rep nop lea bx,[bx] fnop Last edited by l4m2 on 29 Jul 2016, 03:28; edited 1 time in total |
|||
28 Jul 2016, 13:23 |
|
El Tangas 29 Jul 2016, 00:33
Just for completeness, there are also FPU NOPs:
FXCH ST0 FNOP Probably a prefixed NOP would be the best choice in terms of CPU execution resources. But at least one prefixed NOP is a different instruction, REP NOP, aka PAUSE. |
|||
29 Jul 2016, 00:33 |
|
l4m2 29 Jul 2016, 03:22
Besides: Is it a good choice if I use REP REP REP NOP to be a 4-byte nop?
If so the nops macro is easy to write: Code: macro nops n { if n<0 nops n ;Keep the error itself else if n=0 else if n<16 repeat n-1 rep end repeat nop else jmp $+n db n-2 dup ? end if } Last edited by l4m2 on 29 Jul 2016, 03:46; edited 1 time in total |
|||
29 Jul 2016, 03:22 |
|
redsock 29 Jul 2016, 03:45
here is the 1..15 list that I use in descending order (AMD/Intel compat, AMD-only code can be a bit nicer still for x86_64):
Code: if a = 15 db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 db 0x66, 0xf, 0x1f, 0x44, 0x00, 0x00 else if a = 14 db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 db 0xf, 0x1f, 0x44, 0x00, 0x00 else if a = 13 db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 db 0xf, 0x1f, 0x40, 0x00 else if a = 12 db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 db 0xf, 0x1f, 0x00 else if a = 11 db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 db 0x66, 0x90 else if a = 10 db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 db 0x90 else if a = 9 db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 else if a = 8 db 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 else if a = 7 db 0xf, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00 else if a = 6 db 0x66, 0xf, 0x1f, 0x44, 0x00, 0x00 else if a = 5 db 0xf, 0x1f, 0x44, 0x00, 0x00 else if a = 4 db 0xf, 0x1f, 0x40, 0x00 else if a = 3 db 0xf, 0x1f, 0x00 else if a = 2 db 0x66, 0x90 else if a = 1 db 0x90 end if |
|||
29 Jul 2016, 03:45 |
|
l4m2 29 Jul 2016, 03:51
redsock wrote:
That's two commands, isn't it? Code: nop word [esp+999] nop word [esp+3] |
|||
29 Jul 2016, 03:51 |
|
redsock 29 Jul 2016, 03:55
yeah, thats the AMD v. Intel bit of unpleasantness required to get a 15 byte NOP (which ends up being two for Intel). AMD lets you string 0x66's as leading padding bytes (though I am not sure whether there is a decoding penalty for that or not).
|
|||
29 Jul 2016, 03:55 |
|
revolution 29 Jul 2016, 17:26
l4m2 wrote: mov ax,ax None of those will "go better" than any of the others in all (or even some) cases. It depends upon the system it is running on. It depends upon the surrounding code. It depends upon how you measure it. It depends upon how it is aligned. And, perhaps most surprisingly for many, it depends upon what code has just been recently executed (because of the caches and things), and what code it to be executed in the future (because of prediction and whatnot). And these answers have not changed since the last time l4m2 asked "is A better than B". I really wish there were a single known answer to such questions, but there isn't. You just have to realise that it can't be predicted what will happen until you actually run the code in the real context. And also, if you can't measure any difference in your code when comparing two versions then the answer in that situation is: It makes no difference whatsoever. And in the unlikely event that your code does show a real measurable difference with one version then the answer is simply: Use the one that gives you the "best" result. |
|||
29 Jul 2016, 17:26 |
|
DimonSoft 29 Jul 2016, 22:35
I’ll share this link (somewhat related, though it’s for 32-bit protected mode there):
https://blogs.msdn.microsoft.com/oldnewthing/20130102-00/?p=5663 You can follow links there to find out more about the task they solved at Microsoft with a two-byte nop. |
|||
29 Jul 2016, 22:35 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.