Re: [Tinycc-devel] Re : Re: Re : Some questions regarding of TCC's optimizations.

2022-04-04 Thread Elijah Stone
A while ago, somebody worked on improving the quality of tcc's code 
generation.  Apparently the resulting code performed similarly to gcc -O0. 
This was specific to the (32-bit) x86 backend, but feasible to port to 
others.  I don't have a pointer handy, but you should be able to find it 
by searching the mailing list archives.


On Mon, 4 Apr 2022, Domingo Alvarez Duarte wrote:


Hello Brian !

I understand what you are saying and based on that TCC basically doesn't 
do basically any optmization and based on the basic idea of search/look 
through the generated assembly (trough objdump) trying recognize easy 
hanging fruits and if finding any and localizing the generating point 
add a similar code to the one you described to alter the generated code 
instead of modify/replace/remove the already generated one.


Thank you so much for your nice and useful blog post !

Cheers !

On 4/4/22 18:15, Brian Callahan wrote:

Hello --

I am on this list, you know :)

There may well be opportunities in tcc for a peephole optimizer
approach, but I'll caution that each compiler is different and that blog
post was examining QBE, so it wouldn't necessarily be a direct 1:1
mapping. QBE does a lot of optimization itself before writing out its
final assembly.

~Brian

On 4/4/2022 10:26 AM, Domingo Alvarez Duarte wrote:

After reading this https://briancallahan.net/blog/20220330.html and
using a citation on this list about dumping the ASM generated by TCC
using objdump maybe we can find patterns on the generated code and
identify where it's produced and update then.

On 31/3/22 20:16, rempas via Tinycc-devel wrote:

31 Μαρ 2022, 19:35 Από david.k...@libertysurf.fr:


Have a look : https://github.com/adorad/tcc and
https://github.com/adorad/adorad

- Mail d'origine -
De: rempas via Tinycc-devel 
À: Tinycc Devel 
Cc: rem...@tutanota.com, Tinycc Devel 
Envoyé: Tue, 29 Mar 2022 21:12:37 +0200 (CEST)
Objet: Re: [Tinycc-devel]  Re :  Some questions regarding of TCC's
optimizations.


Thanks a lot! I will look at it!


___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Re : Re: Re : Some questions regarding of TCC's optimizations.

2022-04-04 Thread Domingo Alvarez Duarte

Hello Brian !

I understand what you are saying and based on that TCC basically doesn't 
do basically any optmization and based on the basic idea of search/look 
through the generated assembly (trough objdump) trying recognize easy 
hanging fruits and if finding any and localizing the generating point 
add a similar code to the one you described to alter the generated code 
instead of modify/replace/remove the already generated one.


Thank you so much for your nice and useful blog post !

Cheers !

On 4/4/22 18:15, Brian Callahan wrote:

Hello --

I am on this list, you know :)

There may well be opportunities in tcc for a peephole optimizer
approach, but I'll caution that each compiler is different and that blog
post was examining QBE, so it wouldn't necessarily be a direct 1:1
mapping. QBE does a lot of optimization itself before writing out its
final assembly.

~Brian

On 4/4/2022 10:26 AM, Domingo Alvarez Duarte wrote:

After reading this https://briancallahan.net/blog/20220330.html and
using a citation on this list about dumping the ASM generated by TCC
using objdump maybe we can find patterns on the generated code and
identify where it's produced and update then.

On 31/3/22 20:16, rempas via Tinycc-devel wrote:

31 Μαρ 2022, 19:35 Από david.k...@libertysurf.fr:


Have a look : https://github.com/adorad/tcc and
https://github.com/adorad/adorad

- Mail d'origine -
De: rempas via Tinycc-devel 
À: Tinycc Devel 
Cc: rem...@tutanota.com, Tinycc Devel 
Envoyé: Tue, 29 Mar 2022 21:12:37 +0200 (CEST)
Objet: Re: [Tinycc-devel]  Re :  Some questions regarding of TCC's
optimizations.


Thanks a lot! I will look at it!


___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Re : Re: Re : Some questions regarding of TCC's optimizations.

2022-04-04 Thread Brian Callahan
Hello --

I am on this list, you know :)

There may well be opportunities in tcc for a peephole optimizer
approach, but I'll caution that each compiler is different and that blog
post was examining QBE, so it wouldn't necessarily be a direct 1:1
mapping. QBE does a lot of optimization itself before writing out its
final assembly.

~Brian

On 4/4/2022 10:26 AM, Domingo Alvarez Duarte wrote:
> After reading this https://briancallahan.net/blog/20220330.html and
> using a citation on this list about dumping the ASM generated by TCC
> using objdump maybe we can find patterns on the generated code and
> identify where it's produced and update then.
> 
> On 31/3/22 20:16, rempas via Tinycc-devel wrote:
>> 31 Μαρ 2022, 19:35 Από david.k...@libertysurf.fr:
>>
>>> Have a look : https://github.com/adorad/tcc and
>>> https://github.com/adorad/adorad
>>>
>>> - Mail d'origine -
>>> De: rempas via Tinycc-devel 
>>> À: Tinycc Devel 
>>> Cc: rem...@tutanota.com, Tinycc Devel 
>>> Envoyé: Tue, 29 Mar 2022 21:12:37 +0200 (CEST)
>>> Objet: Re: [Tinycc-devel]  Re :  Some questions regarding of TCC's
>>> optimizations.
>>>
>> Thanks a lot! I will look at it!
>>
>>
>> ___
>> Tinycc-devel mailing list
>> Tinycc-devel@nongnu.org
>> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
> 
> ___
> Tinycc-devel mailing list
> Tinycc-devel@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel


___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Re : Re: Re : Some questions regarding of TCC's optimizations.

2022-04-04 Thread Domingo Alvarez Duarte
After reading this https://briancallahan.net/blog/20220330.html and 
using a citation on this list about dumping the ASM generated by TCC 
using objdump maybe we can find patterns on the generated code and 
identify where it's produced and update then.


On 31/3/22 20:16, rempas via Tinycc-devel wrote:

31 Μαρ 2022, 19:35 Από david.k...@libertysurf.fr:


Have a look : https://github.com/adorad/tcc and https://github.com/adorad/adorad

- Mail d'origine -
De: rempas via Tinycc-devel 
À: Tinycc Devel 
Cc: rem...@tutanota.com, Tinycc Devel 
Envoyé: Tue, 29 Mar 2022 21:12:37 +0200 (CEST)
Objet: Re: [Tinycc-devel]  Re :  Some questions regarding of TCC's 
optimizations.


Thanks a lot! I will look at it!


___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Enabling TinyCC to Create Empty Archives

2022-04-04 Thread Christian Jullien
Hi,

As you need to update your Makefile to replace ar by 'tcc ar' you can as well 
replace the command that produce an empty archive by:
echo '!' > libempty.a.
This works even in the case you use gcc.

Your patch is small and looks good too. Maybe maintainer will want to accept it.
It's a good thing for tcc to mimic gcc/ar/... behaviors

M2c 

-Original Message-
From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=orange...@nongnu.org] On 
Behalf Of Ziyao
Sent: Monday, April 04, 2022 05:03
To: tinycc-devel@nongnu.org
Subject: [Tinycc-devel] Enabling TinyCC to Create Empty Archives

Hi list,

On my machine (x86_64 Ubuntu 18.04LTS,GNU ar 2.30),it is OK to create an
empty archive with
ar rc libempty.a
This will create libempty.a which only contains an ar archive header.

But TinyCC refuses to do that:
tcc -ar rc libempty.a   # This will print the usage
I made a patch for that.

musl libc uses this feature to create dummy libraries(it combines all
libraries into a single file,rather than many libraries like libc.a,libm.a
etc.Dummy libraries are used to avoid linking errors when using common
linking flags like -lm).

I do not know whether there are other projects using this feature.But I
think it is a good idea to keep compatible with GNU ar.

Best wishes,
Ziyao

-

diff --git a/tcctools.c b/tcctools.c
index 4567b81..7c643dc 100644
--- a/tcctools.c
+++ b/tcctools.c
@@ -61,7 +61,7 @@ static int contains_any(const char *s, const char *list) {
 }

 static int ar_usage(int ret) {
-fprintf(stderr, "usage: tcc -ar [rcsv] lib file...\n");
+fprintf(stderr, "usage: tcc -ar [rcsv] lib [file...]\n");
 fprintf(stderr, "create library ([abdioptxN] not supported).\n");
 return ret;
 }
@@ -115,8 +115,9 @@ ST_FUNC int tcc_tool_ar(TCCState *s1, int argc, char **argv)
 }
 }

-if (!i_obj)  // i_obj implies also i_lib. we require both.
+if (!i_lib)  // i_obj implies also i_lib.
 ret = 1;
+i_obj = i_obj ? i_obj : argc;  // An empty archive will be generated if no 
input file is given

 if (ret == 1)
 return ar_usage(ret);
@@ -242,6 +243,9 @@ ST_FUNC int tcc_tool_ar(TCCState *s1, int argc, char **argv)
 hofs++, fpos = 1;
 // write header
 fwrite("!\n", 8, 1, fh);
+// create an empty archive
+if (!funccnt)
+goto the_end;
 sprintf(stmp, "%-10d", (int)(strpos + (funccnt+1) * sizeof(int)));
 memcpy(_size, stmp, 10);
 fwrite(, sizeof(arhdr), 1, fh);


___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel