Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Karoly Balogh via fpc-pascal
Hi,

On Sun, 7 Jan 2024, Florian Klämpfl via fpc-pascal wrote:

>> Am 07.01.2024 um 13:21 schrieb Ingemar Ragnemalm via fpc-pascal 
>> :
>>
>> Just for comparison, I fired up Think Pascal and made Hello world!
>>
>> Plain Hello world, closes so quickly that you don't have time to see
>> it: 4625 bytes.
>>
>> Including ShowText and while not Button do; 4639 bytes.
>>
>> Yes, less than 5k! Progress?
>
> https://github.com/chainq/amiga-tiny-hello-p
>
> 244 bytes with FPC.

BTW, and while I still stand by the Disclaimer I wrote at the bottom of
that page, this kind of technique can have a real world impact and use.
For example, we made a couple of Windows 4k intros (real time animations
with graphics and music, in less than 4096 bytes!) with Free Pascal using
the same kind of startup-bypass technque - and admittedly, a compressing
linker, called Crinkler. :)

Ampelwürfel:
https://www.pouet.net/prod.php?which=90091
... additional backstory/tech explanation:
- https://www.pouet.net/prod.php?which=90091#c932283
Binary download:
- https://files.scene.org/view/parties/2021/deadline21/pc_intro/rbs-aw.zip
Direct YouTube link:
- https://youtu.be/Tz_dpKQrQE0

Icecold:
https://www.pouet.net/prod.php?which=94741
Binary download:
- https://files.scene.org/view/parties/2023/evoke23/in4k/rbs-icecold.zip
Direct YouTube link:
- https://youtu.be/z5aR2EfqRgI

Sadly the source for these is not available, AFAIR, but it's basically the
same approach as the Amiga Tiny Hello world.

Crinkler, the compressing linker we used:
https://github.com/runestubbe/Crinkler

Charlie___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Karoly Balogh via fpc-pascal
Hi,

On Sun, 7 Jan 2024, Michael Van Canneyt via fpc-pascal wrote:

> > To underline this with some numbers (I assume you mean the
> > demo/text/hello.pp which only contains a mere "Writeln('Hello World')"
> > and no additional units; all tests on x86_64-linux with 3.3.1):
> >
> > - FPC compiled as is: 388976 B
> > - FPC compiled with full smartlinking: 55920 B
> > - FPC compiled with C linkage: 388760 B
> > - FPC compiled with full smartlinking and C linkage: 56792 B
>
> Maybe it is a good idea to add these numbers to the above WIKI page, to
> quantify the discussion and to illustrate what the effect is of various
> options.
>
> I think we should also explain why linking to C has almost no effect on
> actual binary size.

Note that the numbers above don't include stripping, so it's full with
symbols. I get the same numbers with unstriped binares. If I add striping
(-Xs), the Hello, World! FPC with smartlinking binary is 35056 bytes.
(Current FPC Git main, on Debian 12, x86_64) Other binary sizes change by
roughly the same percentage.

Also note that on most platforms, smartlinking is a lot faster and less
invasive than it used to be, and it doesn't need additional .a files,
thanks to section smartlinking and the section garbage collection feature
of modern linkers. Not sure if some documentation needs to be updated for
that, but while we're at it... :)

Charlie
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Karoly Balogh via fpc-pascal
Hi,

On Sun, 7 Jan 2024, Ingemar Ragnemalm via fpc-pascal wrote:

> Just for comparison, I fired up Think Pascal and made Hello world!
>
> Plain Hello world, closes so quickly that you don't have time to see it: 4625 
> bytes.
>
> Including ShowText and while not Button do; 4639 bytes.
>
> Yes, less than 5k! Progress?

This isn't a fair comparison. Think Pascal is a single platform compiler,
which means it can avoid a bunch of abstraction layers, and also it
doesn't support many advanced modern Pascal constructs. Main examples are
AnsiStrings, and exception handling, but also the memory allocator is more
advanced, and thus bigger than the early Pascal compilers. Everything has
a trade off.

Also while this means the initial "bloat" is bigger, there's a lot less
added, as one progresses. I have a fully localized, multithreaded GUI
Amiga application written in Free Pascal, that is around 64KiB. I'm sure
it could be a lot smaller too, but it isn't unreasonable.
(Here: http://viaduct.amigaspirit.hu )

If anyone is curious what gets into a "Hello, World!" binary, feel free to
look into a linker map, by using command line argument -Xm. (Note on Linux
& systems using GNU LD, the linker map file starts with the _discarded_
sections, the ones which did not get into the binary, so look at the
bottom of the file.)

Charlie
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Rainer Stratmann via fpc-pascal
Am Sonntag, 7. Januar 2024, 14:09:24 CET schrieb Florian Klämpfl via fpc-
pascal:
> > Am 07.01.2024 um 13:21 schrieb Ingemar Ragnemalm via fpc-pascal
> > :
> > 
> > Just for comparison, I fired up Think Pascal and made Hello world!
> > 
> > Plain Hello world, closes so quickly that you don't have time to see it:
> > 4625 bytes.
> > 
> > Including ShowText and while not Button do; 4639 bytes.
> > 
> > Yes, less than 5k! Progress?
> 
> https://github.com/chainq/amiga-tiny-hello-p
> 
> 244 bytes with FPC.

Is the size of AVR programs reasonable small?
Is the AVR code stable?
I would like to switch to freepascal.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Quiz

2024-01-07 Thread Tomas Hajny via fpc-pascal

On 2024-01-07 20:47, Michael Van Canneyt via fpc-pascal wrote:

On Sun, 7 Jan 2024, Adriaan van Os via fpc-pascal wrote:

 .
 .

There is some special handling for 1. (ending with a dot) due to
Delphi/TP compatibility, they accept it.

 .
 .

   kr5   = 1 . e + 2;


Same as kr1, but not accepted by Delphi.


Personally, I don't think that a dot directly following a number is the 
same as a dot separated from the number by a space. TP/BP doesn't accept 
the latter (i.e. kr5).




   kr6   = 1 . 0 e + 2;


kr6 does not compile, although I don't see why if kr5 is accepted..


Well, I'm not sure whether kr5 should be accepted, but anyway, there are 
IMHO two problems here - the second one being the space before the 
exponent marker.




   kr8   = 1.0 e + 2;


kr8 Does not compile, probably same reason as kr6. Delphi does not 
accept it.


TP/BP requires the exponent marker (i.e. "e") to follow the number 
directly. Spaces in the exponent part are allowed, but not before "e".


Tomas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Marco van de Voort via fpc-pascal



Op 7-1-2024 om 11:23 schreef Sven Barth via fpc-pascal:
To underline this with some numbers (I assume you mean the 
demo/text/hello.pp which only contains a mere "Writeln('Hello World')" 
and no additional units; all tests on x86_64-linux with 3.3.1):


- FPC compiled as is: 388976 B
- FPC compiled with full smartlinking: 55920 B
- FPC compiled with C linkage: 388760 B
- FPC compiled with full smartlinking and C linkage: 56792 B

(gotta admit, the last one surprised me though ^^')

I noticed that when I implemented -dFPC_USE_LIBC. The dynamic library 
overhead is bigger than the 15-20kb worth of routines saved in fairly 
simple programs. In the past is was even more pronounced because readdir 
was kernel.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Quiz

2024-01-07 Thread Michael Van Canneyt via fpc-pascal




On Sun, 7 Jan 2024, Adriaan van Os via fpc-pascal wrote:



Quiz.

Which of below constant declarations are accepted by the compiler and what is 
their value ?


 const
   ki1   = + 2;
   ki2   = +2;


+x is a unary expression.


   ki3   = 2+;


Does not compile, the binary expression is not complete.


   kr1   = 1.;


There is some special handling for 1. 
(ending with a dot) due to Delphi/TP compatibility, they accept it.




   kr2   = 1e-2;
   kr3   = 1e+2;
   kr4   = 1.e+2;


kr4: Same as kr1 in FPC, but Delphi does not accept it.


   kr5   = 1 . e + 2;


Same as kr1, but not accepted by Delphi.


   kr6   = 1 . 0 e + 2;


kr6 does not compile, although I don't see why if kr5 is accepted..

Delph does not accept it.


   kr7   = 1.0e+2;
   kr8   = 1.0 e + 2;


kr8 Does not compile, probably same reason as kr6. Delphi does not accept it.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Michael Van Canneyt via fpc-pascal



On Sun, 7 Jan 2024, Sven Barth via fpc-pascal wrote:



- FPC compiled as is: 388976 B
- FPC compiled with full smartlinking: 55920 B
- FPC compiled with C linkage: 388760 B
- FPC compiled with full smartlinking and C linkage: 56792 B


Maybe it is a good idea to add these numbers to the above WIKI page, 
to quantify

the discussion and to illustrate what the effect is of various options.


Probably... 路‍♀️

And just for the fun of it, the size if the RTL is compiled into a 
dynamic package and that is used:


- no smartlinking: 15784 B
- with smartlinking: 15608 B

With the librtl.so having a size of 649912 B which will ammortize itself 
if multiple applications use dynamic packages.


Nice result. Smaller than a C program :-)



I think we should also explain why linking to C has almost no effect 
on actual binary size.


That's mainly because the functions that differ between FPC_USE_LIBC and 
not are rather slim syscalls anyway, so the main bunch of Pascal code is 
still the same in both cases.


I know this, but most likely users will not realize this... :-)

Michael.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Quiz

2024-01-07 Thread Adriaan van Os via fpc-pascal



Quiz.

Which of below constant declarations are accepted by the compiler and what is 
their value ?

  const
ki1   = + 2;
ki2   = +2;
ki3   = 2+;
kr1   = 1.;
kr2   = 1e-2;
kr3   = 1e+2;
kr4   = 1.e+2;
kr5   = 1 . e + 2;
kr6   = 1 . 0 e + 2;
kr7   = 1.0e+2;
kr8   = 1.0 e + 2;

The more difficult question is, why ?

Regards,

Adriaan van Os
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread James Richters via fpc-pascal
>Try building with smartlinking, -XX

I never knew there was an option for smartlinking.   I'm using the FPC text
IDE, I see various options like 
Generate Smaller Code, and level 1, 2, and 3 optimizations, but I don't see
anything specifically called smartlinking. 
Is it the same as Generate Smaller Code?  or if not, is there another way to
turn it on in the textmode IDE?

James


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Florian Klämpfl via fpc-pascal


> Am 07.01.2024 um 13:21 schrieb Ingemar Ragnemalm via fpc-pascal 
> :
> 
> Just for comparison, I fired up Think Pascal and made Hello world!
> 
> Plain Hello world, closes so quickly that you don't have time to see it: 4625 
> bytes.
> 
> Including ShowText and while not Button do; 4639 bytes.
> 
> Yes, less than 5k! Progress?
> 
https://github.com/chainq/amiga-tiny-hello-p

244 bytes with FPC.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Sven Barth via fpc-pascal

Am 07.01.2024 um 11:39 schrieb Michael Van Canneyt via fpc-pascal:



On Sun, 7 Jan 2024, Sven Barth via fpc-pascal wrote:


Am 07.01.2024 um 10:01 schrieb Florian Klämpfl via fpc-pascal:



Am 06.01.2024 um 20:05 schrieb Matthew Phillips via fpc-pascal 
:


I compiled the Hello World program from the docs and noticed that it's
435k. Compared to a lot of newer languages, like Golang, that's not 
bad

at all.

I then compiled the equivalent C program with gcc which came out at
33k. So I'm just curious, where does the difference comes from?
Could it be that fpc is including some parts that are not being 
used in

this simple of a program or is more going on?


https://wiki.freepascal.org/Size_Matters

To underline this with some numbers (I assume you mean the 
demo/text/hello.pp which only contains a mere "Writeln('Hello 
World')" and no additional units; all tests on x86_64-linux with 3.3.1):


- FPC compiled as is: 388976 B
- FPC compiled with full smartlinking: 55920 B
- FPC compiled with C linkage: 388760 B
- FPC compiled with full smartlinking and C linkage: 56792 B


Maybe it is a good idea to add these numbers to the above WIKI page, 
to quantify

the discussion and to illustrate what the effect is of various options.


Probably... 路‍♀️

And just for the fun of it, the size if the RTL is compiled into a 
dynamic package and that is used:


- no smartlinking: 15784 B
- with smartlinking: 15608 B

With the librtl.so having a size of 649912 B which will ammortize itself 
if multiple applications use dynamic packages.


I think we should also explain why linking to C has almost no effect 
on actual binary size.


That's mainly because the functions that differ between FPC_USE_LIBC and 
not are rather slim syscalls anyway, so the main bunch of Pascal code is 
still the same in both cases.


Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Jonas Maebe via fpc-pascal

On 07/01/2024 13:21, Ingemar Ragnemalm via fpc-pascal wrote:

Just for comparison, I fired up Think Pascal and made Hello world!

Plain Hello world, closes so quickly that you don't have time to see it: 
4625 bytes.


Including ShowText and while not Button do; 4639 bytes.

Yes, less than 5k! Progress?


You forgot the 1MB Mac ROM :)

That's also the main difference between C and FPC: C programs by default 
are dynamically linked, so all of the standard RTL functionality that 
gets linked into an FPC program is not there in a C program most of the 
time.


It's also why golang programs are larger: those are statically linked as 
well.



Jonas

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Ingemar Ragnemalm via fpc-pascal

Just for comparison, I fired up Think Pascal and made Hello world!

Plain Hello world, closes so quickly that you don't have time to see it: 
4625 bytes.


Including ShowText and while not Button do; 4639 bytes.

Yes, less than 5k! Progress?

/Ingemar
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Adriaan van Os via fpc-pascal

Peter B via fpc-pascal wrote:


Try building with smartlinking, -XX
I get 35k


You can also experiment with ld linker options like --strip-all and --strip-debug or run the 
produced code through strip  with various 
options (e.g. -u -r on OSX).


Regards,

Adriaan van Os

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Peter B via fpc-pascal




Try building with smartlinking, -XX
I get 35k


Thats with 3.2.2 on linux

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Michael Van Canneyt via fpc-pascal



On Sun, 7 Jan 2024, Sven Barth via fpc-pascal wrote:


Am 07.01.2024 um 10:01 schrieb Florian Klämpfl via fpc-pascal:



Am 06.01.2024 um 20:05 schrieb Matthew Phillips via fpc-pascal 
:


I compiled the Hello World program from the docs and noticed that it's
435k. Compared to a lot of newer languages, like Golang, that's not bad
at all.

I then compiled the equivalent C program with gcc which came out at
33k. So I'm just curious, where does the difference comes from?
Could it be that fpc is including some parts that are not being used in
this simple of a program or is more going on?


https://wiki.freepascal.org/Size_Matters

To underline this with some numbers (I assume you mean the demo/text/hello.pp 
which only contains a mere "Writeln('Hello World')" and no additional units; 
all tests on x86_64-linux with 3.3.1):


- FPC compiled as is: 388976 B
- FPC compiled with full smartlinking: 55920 B
- FPC compiled with C linkage: 388760 B
- FPC compiled with full smartlinking and C linkage: 56792 B


Maybe it is a good idea to add these numbers to the above WIKI page, to quantify
the discussion and to illustrate what the effect is of various options.

I think we should also explain why linking to C has almost no effect on actual 
binary size.

Michael.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Sven Barth via fpc-pascal

Am 07.01.2024 um 10:01 schrieb Florian Klämpfl via fpc-pascal:



Am 06.01.2024 um 20:05 schrieb Matthew Phillips via fpc-pascal 
:


I compiled the Hello World program from the docs and noticed that it's
435k. Compared to a lot of newer languages, like Golang, that's not bad
at all.

I then compiled the equivalent C program with gcc which came out at
33k. So I'm just curious, where does the difference comes from?
Could it be that fpc is including some parts that are not being used in
this simple of a program or is more going on?


https://wiki.freepascal.org/Size_Matters

To underline this with some numbers (I assume you mean the 
demo/text/hello.pp which only contains a mere "Writeln('Hello World')" 
and no additional units; all tests on x86_64-linux with 3.3.1):


- FPC compiled as is: 388976 B
- FPC compiled with full smartlinking: 55920 B
- FPC compiled with C linkage: 388760 B
- FPC compiled with full smartlinking and C linkage: 56792 B

(gotta admit, the last one surprised me though ^^')

Regards,
Sven___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Peter B via fpc-pascal

On 06/01/2024 19:05, Matthew Phillips via fpc-pascal wrote:

I compiled the Hello World program from the docs and noticed that it's
435k. Compared to a lot of newer languages, like Golang, that's not bad
at all.

I then compiled the equivalent C program with gcc which came out at
33k. So I'm just curious, where does the difference comes from?
Could it be that fpc is including some parts that are not being used in
this simple of a program or is more going on?

Like I said, purely a curiosity, not intended as a criticism. Cheers.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Try building with smartlinking, -XX
I get 35k


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Florian Klämpfl via fpc-pascal


> Am 06.01.2024 um 20:05 schrieb Matthew Phillips via fpc-pascal 
> :
> 
> I compiled the Hello World program from the docs and noticed that it's
> 435k. Compared to a lot of newer languages, like Golang, that's not bad
> at all.
> 
> I then compiled the equivalent C program with gcc which came out at
> 33k. So I'm just curious, where does the difference comes from?
> Could it be that fpc is including some parts that are not being used in
> this simple of a program or is more going on?

https://wiki.freepascal.org/Size_Matters

> 
> Like I said, purely a curiosity, not intended as a criticism. Cheers.
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
> 

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] What's in Hello World

2024-01-07 Thread Matthew Phillips via fpc-pascal
I compiled the Hello World program from the docs and noticed that it's
435k. Compared to a lot of newer languages, like Golang, that's not bad
at all.

I then compiled the equivalent C program with gcc which came out at
33k. So I'm just curious, where does the difference comes from?
Could it be that fpc is including some parts that are not being used in
this simple of a program or is more going on?

Like I said, purely a curiosity, not intended as a criticism. Cheers.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal