flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > What such of optimization have FASM compiler?

Author
Thread Post new topic Reply to topic
jorge



Joined: 09 Apr 2008
Posts: 9
jorge 09 Apr 2008, 17:24
I’m student of the science of computer. I’m making my thesis that consists in the creation of a compiler. This compiler has as a back-end the FASM compiler. That’s why I need to know about the optimizations of FASM compiler. In fact I need to know those optimizations that doesn’t have because those I would like to create in my compiler.If any body can help me with that I would be very pleasure.
Post 09 Apr 2008, 17:24
View user's profile Send private message Reply with quote
sakeniwefu



Joined: 23 Mar 2008
Posts: 29
sakeniwefu 09 Apr 2008, 19:32
FASM optimizes for opcode size automagically. The code will always be the smallest possible. In fact, that could cause you problems if you are trying to do alignation using opcode size. Other than that it is all up to you. Of course, if you learn fasm syntax and macros that will help you implement your compiler optimizations more easily.
Post 09 Apr 2008, 19:32
View user's profile Send private message Reply with quote
jorge



Joined: 09 Apr 2008
Posts: 9
jorge 09 Apr 2008, 21:09
thank sakeniwefu, I have another question.FASM have a 'proc' macro. Do you know if FASM do some Interprocedural Optimization or inline procedures.If not, if you know some tecnique,important reference or serious literature please help me with that.In general tell me if you know the theme of Compiler Optimization and how can you help me with that.
Post 09 Apr 2008, 21:09
View user's profile Send private message Reply with quote
sakeniwefu



Joined: 23 Mar 2008
Posts: 29
sakeniwefu 10 Apr 2008, 00:04
About macros, you should read the manual and specific macros' code. You can also ask in the macro forum.
About code: TRY THIS(I recently rediscovered it and solved all my doubts about modern CPU optimization).
Post 10 Apr 2008, 00:04
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20454
Location: In your JS exploiting you and your system
revolution 10 Apr 2008, 00:24
jorge wrote:
thank sakeniwefu, I have another question.FASM have a 'proc' macro. Do you know if FASM do some Interprocedural Optimization or inline procedures.If not, if you know some tecnique,important reference or serious literature please help me with that.In general tell me if you know the theme of Compiler Optimization and how can you help me with that.
fasm won't change your code in any way, nor does any assembler that I am aware of. The optimisation available to an assembler is just to make each individual instruction the smallest size. fasm doesn't guarantee the smallest possible size, there are some counter examples I have come across, but for most programs (maybe 99%+) it will generate the smallest possible code size.

So what does it optimise: 1) jmp and jcc use the two byte form where possible. 2) immediate values use the signed byte form where possible and the zero byte form for zero values. 3) no spurious generation of nops in the code stream, like some older assemblers would do. 4) optimal PE header size based upon the number of sections. 5) probably a few more things that are generally based upon single instructions or output file shrinking.
Post 10 Apr 2008, 00:24
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 10 Apr 2008, 06:04
Quote:
The code will always be the smallest possible

This is not true, this would require "exhaustive search" of all possibilities. FASM just tends to create small code, but doesn't always produce smallest possible code.
Post 10 Apr 2008, 06:04
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
sakeniwefu



Joined: 23 Mar 2008
Posts: 29
sakeniwefu 10 Apr 2008, 09:29
For a single instruction it generates the shortest equivalent opcode, or have I got it wrong?
Post 10 Apr 2008, 09:29
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 10 Apr 2008, 09:39
Well, for single instruction input it does. But it doesn't always find shortest possible solution for some complex cases
Post 10 Apr 2008, 09:39
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20454
Location: In your JS exploiting you and your system
revolution 10 Apr 2008, 09:45
sakeniwefu wrote:
For a single instruction it generates the shortest equivalent opcode, or have I got it wrong?
If your entire program is just the one instruction then yes. But otherwise, for a more typical program, not always, just most of the time. Sometimes the solution to the shortest instruction is hard to find when sizing of one instruction can affect the sizing of another which in turn affect the sizing of the first instruction. See here for a demonstration of what I mean.
Post 10 Apr 2008, 09:45
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4075
Location: vpcmpistri
bitRAKE 10 Apr 2008, 14:40
revolution wrote:
So what does it optimise: 1) jmp and jcc use the two byte form where possible. 2) immediate values use the signed byte form where possible and the zero byte form for zero values. 3) no spurious generation of nops in the code stream, like some older assemblers would do. 4) optimal PE header size based upon the number of sections. 5) probably a few more things that are generally based upon single instructions or output file shrinking.
6) optimal size address modes [eax+eax] encoding instead of [00+eax*2]

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 10 Apr 2008, 14:40
View user's profile Send private message Visit poster's website Reply with quote
jorge



Joined: 09 Apr 2008
Posts: 9
jorge 14 Apr 2008, 15:52
Can any body help me with the theme of Compiler Optimization in the sense of the code that this compiler take as front-end, not only the optimizations of the intruccions that it give as back-end. If any body can tell me any literature that can help me I'm would be very pleasure. sakeniwefu I'm very happy with your help, thank for all.
Post 14 Apr 2008, 15:52
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 14 Apr 2008, 16:01
Post 14 Apr 2008, 16:01
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4075
Location: vpcmpistri
bitRAKE 14 Apr 2008, 16:58
Google Scholar is pretty good.
CiteSeerX (alpha)

Modern compilers generate an intermediate code (between front and back end) and then most optimization algorithms are applied to this middle code. Reason being that the front end language becomes more flexible (even multiple languages).

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 14 Apr 2008, 16:58
View user's profile Send private message Visit poster's website Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 14 Apr 2008, 17:03
Oh, and be sure to throw this one into the mix: http://llvm.org/
Post 14 Apr 2008, 17:03
View user's profile Send private message Visit poster's website Reply with quote
jorge



Joined: 09 Apr 2008
Posts: 9
jorge 14 Apr 2008, 19:21
Thank for your help(f0dder,bitRAKE) but the my problem is more dificult than download those books or paper, I'm cuban student and if some of you know the situacion of my country you will know that is imposible for me to pay those excellent books, I implement all about parising and chek semantic, also I implement a program generator that generate the fasm code, of any program that is ok with the gramar and semantic of my language, but the most important fase of my thesis is the theme of optimization and I'm a baby with that theme, only I know the basic element. You know my real problem, again if any body can help me, tell me how
Post 14 Apr 2008, 19:21
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4075
Location: vpcmpistri
bitRAKE 14 Apr 2008, 20:24
There is a lot of active research in the area of optimization - no need to buy books on the topic. Through Google Scholar I'm often able to find costly IEEE papers availible from the author for free. I've read some about the topic, but do not understand completely.

At the highly abstract level optimizations are transformations to compact a DAG representation of the program. Graph nodes expand with more detail, and contracts through different phases of optimization.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 14 Apr 2008, 20:24
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.