Very Very Inefficient !!

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
iain wilkie
Posts: 97
Joined: Tue Jul 14, 2009 4:37 pm
Has thanked: 13 times
Been thanked: 9 times
Contact:

Very Very Inefficient !!

Post by iain wilkie »

Just revisiting a particular problem covered previously where it was discovered that the AVR compiler in V8 is very in-efficient compared to that which is used in V4 in particular when calling a timer 0 interrupt.

I am using the ATTiny25 and the interrupt is set at every 32uS giving me approx 200 potential cycles for program within the routine. However on entry and exit to the routine approx 70 cycles are lost due to the push/pop of a pile of registers most of which not affected by the routine and are therefore redundant and simply wasting very precious cycles in what is a very tight time conscious interrupt.

This is not quite as bad in V4.

Can this not be controlled in much more efficient way ? There were a few ideas put forward in the other thread but there was little response to this by MM. One was that there appeared there were 3 possible variants of the compliler and maybe an easy way to pre-select which one to use would really help.

Iain

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Very Very Inefficient !!

Post by mnf »

Hi Iain,

Is this with the optimization set to -03 as in other thread??

Martin

iain wilkie
Posts: 97
Joined: Tue Jul 14, 2009 4:37 pm
Has thanked: 13 times
Been thanked: 9 times
Contact:

Re: Very Very Inefficient !!

Post by iain wilkie »

Martin,

Yup the very same ..... I just thought there must be an easy way for this to be implemented instead of editing the compiler details.

Surely this could be a good added feature.

Iain

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Very Very Inefficient !!

Post by mnf »

GCC shouldn't generate the extra and unnecessary push/pop code with optimisation set to -O3, have you checked it? An update might have put it back to -Os.

And yes it would be excellent to have an easy way to change this setting easily...

I just leave it at this setting and haven't encountered any problems (yet)

Martin

iain wilkie
Posts: 97
Joined: Tue Jul 14, 2009 4:37 pm
Has thanked: 13 times
Been thanked: 9 times
Contact:

Re: Very Very Inefficient !!

Post by iain wilkie »

Martin,

The -03 is ok !! .... Its just a bit of a worry that for some reason why had MM decided to use a different optimization level that what they have used in the past ? .... Is there a reason ?? Perhaps Benj or some of the other guys can give us a heads up on this ......

Iain

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Very Very Inefficient !!

Post by mnf »

As another thought:

The C compiler used by FC for PIC processors can be upgraded (for a fee!) to the 'Pro' version - which generates substantially better code.
Can the Arduino tool chain be upgraded from (it's amazing and it's free) gcc to a different toolchain for uses where the quality of the code is paramount.
The best C compiler to my knowledge is CrossWorks C (from Rowley Associates) - which can target a large range of MCUs. I'm maybe biased because I was lucky enough to work with Paul Curtis (who was the principle author of Rowley C) for several years (a long time ago now) - but his dedication (and ability) to produce good quality code was astounding then - and I would bet that he hasn't changed over the years....

The problem of course - is money - although you can get a personal version for a reasonable sum - commercial versions are more expensive (and, no, I'm not suggesting that it should be free - a lot of work has gone into the code) - but how easy would it be to allow FC to use a different toolchain like this? Looking at the Rowley site - it supports AVR and ARM chips (amongst others).

Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Very Very Inefficient !!

Post by Benj »

Hello,

I remember conversations with a previous colleague Sean regarding the AVR's internal architecture and interrupts, he preferred them over PICs whereas I'm generally a PIC man. We both agreed the 16-bit 24/33 PICs is the best of both worlds in the end and mostly use these.

An AVR device will run a lot faster than a PIC but has several pitfalls such as incomprehensible assembler and much larger latency for interrupts. The large latency is due to the AVR architecture and means you have to end up saving a lot of information to avoid corruption. The compiler will do a worst case context save but it looks like it may be possible to dive in and at your own risk edit things to get better results.

There is a topic on AVR freaks regarding the problem but not sure there is a solution posted there.
https://www.avrfreaks.net/forum/interrupt-latency-time

I'll do a bit more digging and see if anything more useful comes up.

As for third party compilers there is always a way but this might be a can of worms in terms of getting Flowcode to play nicely with it. The nice things about the XC compilers is the free version and pro versions have the same code syntax. Never heard of the CrossWorks compilers so will have a look at those.

Post Reply