tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Thumb2 codegen ready for review


From: Erlend Sveen
Subject: Re: [Tinycc-devel] Thumb2 codegen ready for review
Date: Sat, 23 May 2020 17:39:24 +0000

Thanks! Good to know I'm getting some things right. Some answers for your questions:

> * use rebase or cherry-pick (don't use merge)
I have not done it this way before but I'll look into it (and hopefully get it right). I'm guessing
you want me to try fixing the other issues here before I try tho? After all, people can test it
using my mirror until then. Hopefully someone will but I'm not expecting it any time soon
since using TCC for embedded is probably a very niche thing to do 🙂

> * note that tests2.114 already exists
Seems like it got added after I started on mine. I can renumber my tests.

> * add the .expect files too
OK

> * you could still combine the commits into one or two if you want
If it is okay I think maybe it is good to keep the separate commits, I think it is "cleaner"
regarding adding float support, the commit messages etc. I just wasn't certain if there
is a preference.

> * 117_cleanup_nofloat.c : INCR_GI7 is really slow and probably wouldn't
>   find bugs that INCR_GI3 for example would not.
I don't understand what you mean here. Note that I just copied the integer parts of test 101
here, and could not get this test to work anyways since it generates a 7MB file before running
into some limits with branching, and my microcontroller does not have enough memory to run
it either. This is actually the only test that totally fails (see spreadsheet I wrote about).

> * 118_float_branches.c : print_double() would print for example 0.299
>   instead of 0.300 in cases.  This version works for me:
>         int s = d < 0 ? -1000 : 1000;
>         int f = d * s + 0.1;
>         int i = f / s;
>         f = f % 1000;
print_double is not meant to be accurate at all. All that matters is that GCC and TCC produces
the same number. The reason that print_double even exists in the first place is that when I
wrote the test, my printf implementation for the MCU did not take doubles. I have since fixed
that but not changed the test since it did not seem important. I can of course add your
suggestion to make it more accurate.

>* lib/Makefile : XFLAGS += -DTCC_TARGET_ARM_THUMB is never used, anyway
>   the library files shouldn't check TCC_TARGET_* but rather the run-time
>   processor symbols (such as __arm__ etc.)
Maybe I can remove it. Actually I need to look into the library a bit since I don't thing I'm using
it much. I'm just linking with my usual GCC stuff. I'm also generating instructions instead of
calling the library in more places, the Thumb2 instruction set differ somewhat here regarding
division and modulo for instance.

> You might want to add some notes somewhere though, about how people can
> build this and how and where they can use it at all. ;)
Absolutely, but where? tcc-doc.texi? The most important thing to document is probably the
limitations (that I hope to solve). But for what I use it for, it kinda "just works" when used as
a regular cross compiler 🙂 . Actually running TCC itself on the MCU is much more complicated
of course, which is why I made that extra repo.

Regards,
Erlend S.


Fra: Tinycc-devel <tinycc-devel-bounces+erlend.sveen=address@hidden> på vegne av grischka <address@hidden>
Sendt: lørdag 23. mai 2020 15:56
Til: address@hidden <address@hidden>
Emne: Re: [Tinycc-devel] Thumb2 codegen ready for review
 
Hi,

I can't say anything about arm but from the generic part I think this
looks very good.

Related to adding it on the 'real' mob branch:
* use rebase or cherry-pick (don't use merge)
* note that tests2.114 already exists
* add the .expect files too
* you could still combine the commits into one or two if you want
* 117_cleanup_nofloat.c : INCR_GI7 is really slow and probably wouldn't
   find bugs that INCR_GI3 for example would not.
* 118_float_branches.c : print_double() would print for example 0.299
   instead of 0.300 in cases.  This version works for me:
         int s = d < 0 ? -1000 : 1000;
         int f = d * s + 0.1;
         int i = f / s;
         f = f % 1000;
* lib/Makefile : XFLAGS += -DTCC_TARGET_ARM_THUMB is never used, anyway
   the library files shouldn't check TCC_TARGET_* but rather the run-time
   processor symbols (such as __arm__ etc.)

You might want to add some notes somewhere though, about how people can
build this and how and where they can use it at all. ;)

--- grischka

Erlend Sveen wrote:
> Hi,
> It's been a while now since I've been working on and off various projects
> for the last few months, but I finally think my TCC additions are ready for
> a second pair of eyes (and more). I hope you have some time to look at it
> before I try getting it into the "real" repo.
>
> Initially I wrote that I would not implement any floating point stuff, but after
> looking over the instruction set I found that it was way easier than I expected.
> I also got TCC to run on the microcontroller itself, which also took a fair bit
> of time. I think this is quite cool, lots of stories about people running
> Linux on their micros but not as many about compilers as far as I can tell! In
> fact I've found no articles at all after some minutes of searching. People have
> done interpreters but I could not find anything for C.
>
> Since I don't want to break the main repo I've put up a temporary one before I
> try committing anything to the mob branch. I hoped to make it in one commit but
> ended up with multiple, so here is an explanation of them and links:
>
> https://git.erlendjs.no/erlendjs/tinycc/commit/9e5ef0bbab28379b1ecbd7c167892e3af5f14a8d
>
>  - This adds the most of the code, please see the commit message for an
>    explanation. The most important bits are of course changes to existing
>    files.
>
> https://git.erlendjs.no/erlendjs/tinycc/commit/8698aa391929c5c5f1ae529bda4f98f1d382545f
>
>  - Once I started compiling "real" code I found some bugs, this fixes some.
>
> https://git.erlendjs.no/erlendjs/tinycc/commit/3f8c5163b4d1fe2582d916a231c5e16bbbebf154
>
>  - Adds float support back in and a new test, please see the commit message. It
>    also cleans up a bunch of stuff, fixes some bugs and adds another test to
>    trigger more branches.
>
> At this point there are some things left that I have not figured out yet.
> I hope maybe someone can help a bit with these, either by code or feedback on
> how to do things:
>
>  * Interwork between ARM state and Thumb state. Probably required to get it
>    working on a Raspberry Pi. But not required for MCU use.
>  * The linker in TCC does not seem to work, so I've used the GNU one.
>  * Adding a flag similar to "-mcpu", "-march", "-vfp?" etc. to keep control of
>    which FPU ISA it uses. I expect that the current code will cause some troble
>    linking with elf files that specify e.g. no FPU despite not actually having
>    generated any FPU instructions.
>  * Using floats requires a Cortex-M7 with double precision, since there are
>    no fallbacks to the library routines. Could be fixed if the previous point
>    is implemented.
>  * There is a branch in the store function that I could not figure out how to
>    test, so it remains unimplemented. It is for vmov i think.
>  * log10 gets the sign wrong and I have no idea why.
>
> So far I've only tested using a Cortex-M7. M3 and M4 should work for integer
> code but I have not gotten around to testing that yet.
>
> There are also plenty of files that I figured does not belong in the TCC
> repository. It mostly contains build scripts, test harness code, various notes
> and so on. For an overview of how testing is going, check "tcc-hacking.ods"
> here:
>
> https://git.erlendjs.no/erlends-os/usr/compiler/tree/master/tinycc
>
> Anyways, I think my code is ready now. It successfully compiles all my projects
> that I have tried compiling, and they run properly although much slower.
>
> Regards,
> Erlend Sveen

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]