flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
ronware
I recently modified a loop construct in Reva so that rather than using a 'long' jump, it used a short one. Specifically, the original had code like :
Code: db 0fh, 82h .jmp: dd 0 And the new code is: Code: db 72h .jmp: db 0 The '.jmp' is filled in at interpretation time, with the values which will be used. To my surprise, the long jump form executes much faster -- almost twice as fast (!) and I cannot for the life of me understand why this should be. Both routines appear to work correctly. Any ideas? |
|||
![]() |
|
Tomasz Grysztar
Might be some alignment issue.
|
|||
![]() |
|
f0dder
instruction cache / branch prediction thingy perhaps?
Do you modify .jmp often, or right before reaching the code? |
|||
![]() |
|
ronware
.jmp is modified once, then that code is copied to a different place (where it is executed). The snipped of code is just a template used to generate the final code.
|
|||
![]() |
|
Matrix
Hy ronware,
on newer CPUs, when you modify your code what you execute it causes many ticks of penalties. because code has to be reloaded in instruction cache. |
|||
![]() |
|
ronware
Hmm. It's interesting - I tried the same code on my PentiumM laptop and it was faster. Goes to show, it's hard to predict code performance!
|
|||
![]() |
|
r22
My 2cents.
A long jmp is like MOV EIP, JMP_LOCATION while a short jmp is like ADD EIP, (SIGN EXTENDED) JMP_LOCATION if not sign extended than the processor checks the sign and then adds or subtracts from EIP. In any case the shorter instruction does more work than the longer instruction. Just like how DEC ECX; JNZ LABEL runs faster than LOOP LABEL. If I'm totally off feel free to enlighten me. |
|||
![]() |
|
f0dder
I would still think it has to do with branch prediction... with the indirect jmp, no branch prediction can be done. With the short jump, branch prediction is being done, and it might be that a mispredicted branch is more expensive than no branch prediction at all?
|
|||
![]() |
|
MazeGen
But we are talking about short/near conditional jmp, no indirect jmp...
|
|||
![]() |
|
ronware
Both JMPs are conditional, relative jumps. The first is a 'long form' that takes a 32bit offset, the second is the short form which can only jump +- 127 bytes.
|
|||
![]() |
|
f0dder
Hm, I wonder how I got the impression that the first jump was indirect and conditionless
![]() |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.