flat assembler
Message board for the users of flat assembler.
Index
> Compiler Internals > incorrect "optimization" |
Author |
|
JohnFound 18 Oct 2012, 05:53
ebp works by default on ss, not on ds. This is not because of FASM optimizations.
|
|||
18 Oct 2012, 05:53 |
|
revolution 18 Oct 2012, 07:00
fasm does not track the contents of the segment registers. fasm does not know that the SS register is not initialised to point to the data segment. Use this:
Code: mov dx,[ds:table+ebp*2] |
|||
18 Oct 2012, 07:00 |
|
sinsi 18 Oct 2012, 07:43
The original "problem" was that FASM will take LEA EAX,[6+EBX*2] and change it to the shorter version of LEA EAX,[6+EBX+EBX].
Fine by me, since it works out the same. Then there was a gotcha about using EBP. MASM will encode LEA EAX,[6+EBP+EBP] with a DS override, FASM doesn't. I've looked briefly through the intel docs but can't find anything. Anyone? |
|||
18 Oct 2012, 07:43 |
|
revolution 18 Oct 2012, 07:55
sinsi wrote: The original "problem" was that FASM will take LEA EAX,[6+EBX*2] and change it to the shorter version of LEA EAX,[6+EBX+EBX]. |
|||
18 Oct 2012, 07:55 |
|
JohnFound 18 Oct 2012, 08:00
AFAIK, EBP based addressing always works on SS by default. That is because EBP is designed to be used for stack access.
So, [2*ebp+6] or [ebp+ebp+6], both should work on SS. P.S. I mean in memory accessing instructions. LEA of course will not use any segments at all. |
|||
18 Oct 2012, 08:00 |
|
Japheth 18 Oct 2012, 08:12
I quite intentionally didn't provide a link to the masm32 forum thread because it's mainly about LEA and LEA is ABSOLUTELY irrelevant for this issue.
Masm and assumed behavior of Masm is also irrelevant. This problem is not because Fasm doesn't ASSUME segment register contents. I agree that adding a DS segment prefix makes the test case "work" - but this is not the point. The point is that the test case is to work WITHOUT any segment prefix. |
|||
18 Oct 2012, 08:12 |
|
JohnFound 18 Oct 2012, 08:21
Japheth wrote: The point is that the test case is to work WITHOUT any segment prefix. Explain this more detailed. Why it should work? IMHO, in both cases [ebp+ebp+const] or [ebp*2+const] the CPU will try to access SS. _________________ Tox ID: 48C0321ADDB2FE5F644BB5E3D58B0D58C35E5BCBC81D7CD333633FEDF1047914A534256478D9 |
|||
18 Oct 2012, 08:21 |
|
sinsi 18 Oct 2012, 08:24
>MASM will encode LEA EAX,[6+EBP+EBP] with a DS override, FASM doesn't.
That should be MOV, not LEA. Sorry. >Masm and assumed behavior of Masm is also irrelevant. Relevant, because FASM does differently. Japheth, do you know if it says anything in the intel docs? Also, what does jwasm do? |
|||
18 Oct 2012, 08:24 |
|
Japheth 18 Oct 2012, 08:33
JohnFound wrote: IMHO, in both cases [ebp+ebp+const] or [ebp*2+const] the CPU will try to access SS. That's the point. SS is only the default segment register if the base register is EBP (or ESP or BP). The index register doesn't matter. |
|||
18 Oct 2012, 08:33 |
|
JohnFound 18 Oct 2012, 08:49
Ah, I got it now, after some tests ( )
It is a bug and has to be fixed. Tomasz probably already thinks about it. |
|||
18 Oct 2012, 08:49 |
|
Tomasz Grysztar 18 Oct 2012, 09:20
No, it is not a bug. It was already discussed on this board, see my stance here: http://board.flatassembler.net/topic.php?p=116138#116138 (starting with "As for the EBP*2 problem" words).
In short: by default fasm optimizes as for flat mode, where segments do not matter (and so addresses containing EBP can be most agressively optimized). When working in segmented environment and unsure about the base segment that will get used, just use segment prefix in the address expression and fasm will happily optimize instruction that does exactly what it is told to. You can also find some related release notes about rare optimization cases here: http://board.flatassembler.net/topic.php?p=118691#118691 |
|||
18 Oct 2012, 09:20 |
|
JohnFound 18 Oct 2012, 09:31
I missed this discussion. But your arguments looks reasonable.
|
|||
18 Oct 2012, 09:31 |
|
Japheth 18 Oct 2012, 12:52
JohnFound wrote: I missed this discussion. But your arguments looks reasonable. I also missed this. Personally, I find the argumentation a bit "borderline" ( somewhat similiar to the SSSO "arguments" ), but never mind! |
|||
18 Oct 2012, 12:52 |
|
shutdownall 18 Oct 2012, 19:46
Tomasz Grysztar wrote: When working in segmented environment and unsure about the base segment that will get used, just use segment prefix in the address expression and fasm will happily optimize instruction that does exactly what it is told to. Or simply use EDI instead of EBP because EDI has DS as default segment. |
|||
18 Oct 2012, 19:46 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.