Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2008-09

generated assembler

28 messages · 11 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

I know it's possible, but I can't remember the exact FPC parameters. How do I see the assembler generated by FPC for my source code?

I need to do some optimisation comparisons looking at the assembler generated.

eg:
Is assembler code generated for a call to a blank (no content) procedure? The content of the procedure might be IFDEF'd out.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Micha Nelissen
Micha Nelissen wrote
Read ppc386 -h.

OK, I meant to say, I already looked at the parameter help, I'm just not sure which one I need to use. I would guess -al is what I am looking for? Is there more information on what all these options do? Sorry, my assembler is rusty!

-a The compiler doesn't delete the generated assembler file -al List sourcecode lines in assembler file -an List node info in assembler file
-ap Use pipes instead of creating temporary assembler files -ar List register allocation/release info in assembler file -at List temp allocation/release info in assembler file

PS:
Sorry, I only realized now, that I posted this thread in the fpc-devel mailing list. I meant for it to go to fpc-pascal.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 12 lines
On 9/3/08, Micha Nelissen wrote: > > Read ppc386 -h. OK, I meant to say, I already looked at the parameter help, I'm just not sure which one I need to use. I would guess -al is what I am looking for? Is there more information on what all these options do? Sorry, my assembler is rusty! -a The compiler doesn't delete the generated assembler file -al List sourcecode lines in assembler file

-al : This is the one you need.

Michael.

Reply by email

Martin Schreiber
to Graeme Geldenhuys: I know it's possible, but I can't remember the exact FPC parameters. How do I see the…
Graeme Geldenhuys wrote 12 lines
Hi, I know it's possible, but I can't remember the exact FPC parameters. How do I see the assembler generated by FPC for my source code? I need to do some optimisation comparisons looking at the assembler generated. eg: Is assembler code generated for a call to a blank (no content) procedure? The content of the procedure might be IFDEF'd out.

You could use breakpoints and the (dis-)assembler window of MSEide, it lists mixed pascal and machine code.
The SVN trunk version has some improvements in (dis-)assembler window, for example the possibility to set breakpoints on machine instructions.

Martin

Reply by email

Graeme Geldenhuys
to Martin Schreiber
Martin Schreiber wrote
You could use breakpoints and the (dis-)assembler window of MSEide, it lists mixed pascal and machine code.

Thanks Martin, I'll take a look.

What I'm trying to find out (with my rusty assembler knowledge) is if a lot of IFDEF's around procedure calls, compared to only one IFDEF inside a procedure would make a difference in performance and the code generated.

I would prefer example 2 (it looks cleaner and would be less work), and from my quick/crude analysis, it seems both options generate pretty much the same code if the gDEBUG define is disabled (does NOT exist).

Example #1...

  procedure Log(AParam1: string);
  begin
    writeln('LOG: ' + AParam1);
  end;
var
  i, j: integer;
  s: string;
begin
  {$IFDEF gDEBUG} Log('Starting...'); {$ENDIF}
  s := '%d + %d = %d';
  i := 5;
  j := 2;
  {$IFDEF gDEBUG} Log('calculating result'); {$ENDIF}
  {$IFDEF gDEBUG} Log(Format(s, [i, j, i+j])); {$ENDIF}
  {$IFDEF gDEBUG} Log('Done.'); {$ENDIF}
end.

versus Example #2...

  procedure Log(AParam1: string);
  begin
    {$IFDEF gDEBUG}
    writeln('LOG: ' + AParam1);
    {$ENDIF}
  end;
var
  i, j: integer;
  s: string;
begin
  Log('Starting...');
  s := '%d + %d = %d';
  i := 5;
  j := 2;
  Log('calculating result');
  Log(Format(s, [i, j, i+j]));
  Log('Done.');
end.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Martin Schreiber
to Graeme Geldenhuys
Graeme Geldenhuys wrote 16 lines
On 9/3/08, Martin Schreiber wrote: > You could use breakpoints and the (dis-)assembler window of MSEide, it > lists mixed pascal and machine code. Thanks Martin, I'll take a look. What I'm trying to find out (with my rusty assembler knowledge) is if a lot of IFDEF's around procedure calls, compared to only one IFDEF inside a procedure would make a difference in performance and the code generated. I would prefer example 2 (it looks cleaner and would be less work), and from my quick/crude analysis, it seems both options generate pretty much the same code if the gDEBUG define is disabled (does NOT exist).

For the people who don't know MSEide attached a screenshot, I hope the file is not too big. It is with -O3. With inline there is still some overhead because of the string variable.

Martin

Reply by email

Nataraj S Narayan
to Graeme Geldenhuys: I know it's possible, but I can't remember the exact FPC parameters. How do I see the…

Hi

Try fpc -sh

regards

Nataraj

Graeme Geldenhuys wrote 23 lines
Hi, I know it's possible, but I can't remember the exact FPC parameters. How do I see the assembler generated by FPC for my source code? I need to do some optimisation comparisons looking at the assembler generated. eg: Is assembler code generated for a call to a blank (no content) procedure? The content of the procedure might be IFDEF'd out. Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/ _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Graeme Geldenhuys
to Martin Schreiber: For the people who don't know MSEide attached a screenshot, I hope the file is not too…
Martin Schreiber wrote
For the people who don't know MSEide attached a screenshot, I hope the file is not too big. It is with -O3. With inline there is still some overhead because of the string variable.

OK, thanks Martin. Debugging in MSEide seems quite impressive. I can see you put a lot of effort into writing it.

PS:
The image was received fine. I noticed with my own experimentation that small screenshots (not photos) work better as GIF images. It's a much better option for size reduction with no visual loss. Your image as PNG is 28K. As a GIF it's only 17.5K
:-) Don't use JPG's, they are useless and look damn ugly!

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Martin Schreiber
to Graeme Geldenhuys
Graeme Geldenhuys wrote 8 lines
On 9/3/08, Martin Schreiber wrote: > For the people who don't know MSEide attached a screenshot, I hope the > file is not too big. It is with -O3. With inline there is still some > overhead because of the string variable. OK, thanks Martin. Debugging in MSEide seems quite impressive. I can see you put a lot of effort into writing it.

Because I implement so many bugs, I need an excellent IDE. ;-)

Martin

Reply by email

David Pethes
to Graeme Geldenhuys: OK, thanks Martin. Debugging in MSEide seems quite impressive. I can see you put a lot…
Graeme Geldenhuys wrote 6 lines
PS: The image was received fine. I noticed with my own experimentation that small screenshots (not photos) work better as GIF images. It's a much better option for size reduction with no visual loss. Your image as PNG is 28K. As a GIF it's only 17.5K :-) Don't use JPG's, they are useless and look damn ugly!

It's 9K in PNG if you use a palette/256 colors, much like GIF does ;)

David

Reply by email

Graeme Geldenhuys
to David Pethes
David Pethes wrote
> as PNG is 28K. As a GIF it's only 17.5K > :-) Don't use JPG's, they are useless and look damn ugly! It's 9K in PNG if you use a palette/256 colors, much like GIF does ;)

Cool! I never thought to look at the colour palette information.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Michael Schnell
Michael Schnell wrote
Firefox shows PNGs (and JPGs) within the message, while you would need to open an external viewer for GIFs. So PNG is really nice here !

Huh?? Many sites use gif images!
Firefox supports PNG, GIF, JPG etc.. all natively. At least my version does (Firefox v3). I just tested this as well. I could view a website and my gmail with uses both gif and png files in the content.

Ah, I see your problem:
User-Agent: Thunderbird 2.0.0.16 (Windows/20080708)

Please upgrade to a working OS - something like Linux. ;-) Actually my wife's computer uses Firefox 2 under Windows, and she as no issues with viewing gif images either.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Michael Schnell
to Graeme Geldenhuys
Graeme Geldenhuys wrote 7 lines
On 9/4/08, Michael Schnell wrote: > Firefox shows PNGs (and JPGs) within the message, while you would need to > open an external viewer for GIFs. So PNG is really nice here ! > Huh??

Sorry Typo: Thunderbird !

-Michael

Reply by email

Graeme Geldenhuys
to Michael Schnell
Michael Schnell wrote
Huh?? Sorry Typo: Thunderbird !

Makes no difference, that test email I mentioned was from one account to my work account. HTML email (which I hate) or plain text emails... Thunderbird shows png, gif and jpg inline, without issues. In the case of plain text, the images are inline at the end of the email - one image after another.

Anyway, we are way off-topic here...

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Peter Popov
to Michael Schnell

As I was porting things from delphi to fp today I noticed the following difference:

Delphi (2,5) : GetMem(p, 0) will set p to nil. FPC (2.2.2, 2.3.1) : GetMem(p, 0) will assign something to p

Clearly, the above calls are bad karma (which I have been practicing, apparently). Delphi's help does not say what GetMem should do when the size is 0 (realloc does). On the other hand, assigning something is a bad idea too, as it suggests at least Size(pointer) amount of storage, unless that memory spot is somehow marked as "empty", etc.

Do you think this should be reported as a feature, or should the definition of GetMem be changed to cover this case. Note that it is desirable to specify explictly what GetMem(p, 0) should do, since one can in principle provide a separate heap manager. Therefore, behavior of use-supplied getmem should be unniform.

Peter Popov

Reply by email

Micha Nelissen
to Peter Popov
Peter Popov wrote
size is 0 (realloc does). On the other hand, assigning something is a bad idea too, as it suggests at least Size(pointer) amount of storage, unless that memory spot is somehow marked as "empty", etc.

How does it suggest a storage space with size > 0 ?

Micha

Reply by email

Peter Popov
to Micha Nelissen

Well, if it points to something, then there is space, isn't it? Unless it is clearly mentioned in the documentation that GetMem(p,0) results in p being undefined and it is put as a requirement for any custom implementation of a heap manager.
Either way would work.

Peter

Micha Nelissen wrote 9 lines
Peter Popov wrote: > size is 0 (realloc does). On the other hand, assigning something is a > bad idea too, as it suggests at least Size(pointer) amount of storage, > unless that memory spot is somehow marked as "empty", etc. How does it suggest a storage space with size > 0 ? Micha _______________________________________________

Reply by email

Micha Nelissen
to Peter Popov: Well, if it points to something, then there is space, isn't it? Unless it is clearly…
Peter Popov wrote
Well, if it points to something, then there is space, isn't it? Unless it is clearly mentioned in the documentation that GetMem(p,0) results in

You get a pointer to some place where you may store 0 bytes, so nothing :-).

This can be useful because otherwise you may think the allocation failed if you get nil back. (And you've disabled heap exception).

Micha

Reply by email

Peter Vreman
Show quoted text 8 lines
Peter Popov wrote: > Well, if it points to something, then there is space, isn't it? Unless > it is clearly mentioned in the documentation that GetMem(p,0) results in You get a pointer to some place where you may store 0 bytes, so nothing :-). This can be useful because otherwise you may think the allocation failed if you get nil back. (And you've disabled heap exception).

In FPC it is done by design. If 0 bytes are asked we allocate at least the minimum alignment to get a valid pointer. This is done for compatibility with TP7.0 that returns the value of heapptr which is also a valid pointer.

Peter

Reply by email

Peter Popov
to Peter Vreman
Show quoted text 5 lines
> You get a pointer to some place where you may store 0 bytes, so nothing > :-). > > This can be useful because otherwise you may think the allocation failed > if you get nil back. (And you've disabled heap exception).

you have a point

Show quoted text 7 lines
In FPC it is done by design. If 0 bytes are asked we allocate at least the minimum alignment to get a valid pointer. This is done for compatibility with TP7.0 that returns the value of heapptr which is also a valid pointer.

Thanks for the clarification!
I guess if you switch to reallocmem entirely, there will be delphi compatibility, yes?

Peter

Reply by email

Jonas Maebe
to Peter Popov
Peter Popov wrote 9 lines
> In FPC it is done by design. If 0 bytes are asked we allocate at > least the minimum alignment to > get a valid pointer. This is done for compatibility with TP7.0 that > returns the value of heapptr > which is also a valid pointer. Thanks for the clarification! I guess if you switch to reallocmem entirely, there will be delphi compatibility, yes?

reallocmem indeed frees the memory and sets the pointer to nil if you specify "0" as the memory size.

Jonas

Reply by email

Unknown author
to Jonas Maebe
Jonas Maebe wrote 15 lines
On 05 Sep 2008, at 17:25, Peter Popov wrote: >>In FPC it is done by design. If 0 bytes are asked we allocate at >>least the minimum alignment to >>get a valid pointer. This is done for compatibility with TP7.0 that >>returns the value of heapptr >>which is also a valid pointer. > >Thanks for the clarification! >I guess if you switch to reallocmem entirely, there will be delphi >compatibility, yes? reallocmem indeed frees the memory and sets the pointer to nil if you specify "0" as the memory size.

Look at thread "AllocMem(0)nil" at 25.03.08. I had the same problem.

Petr

Ing. Petr Kristan . EPOS PRO s.r.o., Bozeny Nemcove 2625, 530 02 Pardubice tel: +420 466335223 Czech Republic (Eastern Europe) fax: +420 466510709

Reply by email

Peter Vreman
Show quoted text 18 lines
On Sat, Sep 06, 2008 at 11:25:19AM +0100, Jonas Maebe wrote: > > On 05 Sep 2008, at 17:25, Peter Popov wrote: > > >>In FPC it is done by design. If 0 bytes are asked we allocate at > >>least the minimum alignment to > >>get a valid pointer. This is done for compatibility with TP7.0 that > >>returns the value of heapptr > >>which is also a valid pointer. > > > >Thanks for the clarification! > >I guess if you switch to reallocmem entirely, there will be delphi > >compatibility, yes? > > reallocmem indeed frees the memory and sets the pointer to nil if you > specify "0" as the memory size. Look at thread "AllocMem(0)nil" at 25.03.08. I had the same problem.

AllocMem uses internally the same memory allocation as GetMem. So the behaviour of FPC is by design.

Peter

Reply by email