flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
ronware 05 Jul 2005, 20:51
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 05 Jul 2005, 20:54
Might be some alignment issue.
|
|||
![]() |
|
f0dder 05 Jul 2005, 21:43
instruction cache / branch prediction thingy perhaps?
Do you modify .jmp often, or right before reaching the code? |
|||
![]() |
|
ronware 05 Jul 2005, 22:05
.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 06 Jul 2005, 12:30
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 06 Jul 2005, 14:46
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 06 Jul 2005, 17:08
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 06 Jul 2005, 17:10
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 06 Jul 2005, 17:39
But we are talking about short/near conditional jmp, no indirect jmp...
|
|||
![]() |
|
ronware 06 Jul 2005, 17:53
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 06 Jul 2005, 19:23
Hm, I wonder how I got the impression that the first jump was indirect and conditionless
![]() |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.