EmbeddedRelated.com
Forums

Optimize C++ for a microcontroller

Started by deel...@googlemail.com March 17, 2008
Hello,

I am trying to optimize C++ code for an 16 Bit Microcontroller from
renesas, does someone have any idea, how can I approach this Problem.
for any help i will be very grateful

best regards
"deel007@googlemail.com" <deel007@googlemail.com> writes:
> I am trying to optimize C++ code for an 16 Bit Microcontroller from > renesas, does someone have any idea, how can I approach this Problem.
It would help if you gave us more information, like which Renesas microcontroller you're using, which C++ compiler you're using, and what kinds of optimizations you're expecting.
On 2008-03-17, deel007@googlemail.com <deel007@googlemail.com> wrote:

> I am trying to optimize C++ code for an 16 Bit Microcontroller > from renesas, does someone have any idea, how can I approach > this Problem. for any help i will be very grateful
1) Measure the performance/size/whatever of various functions or modules. 2) Using the results of 1), figure out which functions/modules are the biggest resource hogs. 3) Fix them. -- Grant Edwards grante Yow! Here I am at the flea at market but nobody is buying visi.com my urine sample bottles...
On Mar 17, 7:53 pm, Grant Edwards <gra...@visi.com> wrote:

> 1) Measure the performance/size/whatever of various functions > 2) Using the results of 1), figure out which functions/modules > 3) Fix them.
In summary: Lather. Rinse. Repeat.
Grant Edwards wrote:
> On 2008-03-17, deel007@googlemail.com <deel007@googlemail.com> wrote: > >> I am trying to optimize C++ code for an 16 Bit Microcontroller >> from renesas, does someone have any idea, how can I approach >> this Problem. for any help i will be very grateful > > 1) Measure the performance/size/whatever of various functions > or modules. > > 2) Using the results of 1), figure out which functions/modules > are the biggest resource hogs. > > 3) Fix them. >
1a) compile to assembly and look at the assembly. This will help you understand what the compiler is doing. I would do this with any new serious* language I was learning. 2a) The C++ libraries are phenomenally capable -- and phenomenally big. Avoid them unless you have phenomenal resources. Being aware of what features of C++ (like 'new', and 'try') will cause you to pull in large swaths of library (or screw the RTOS) is a good thing, so that you can make intelligent decisions about what resources you _want_ pulled in. * Don't take me to task about the chances of doing this with Java or Basic -- I'm being purposely chauvinistic against interpreted languages. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" gives you just what it says. See details at http://www.wescottdesign.com/actfes/actfes.html

deel007@googlemail.com wrote:
> Hello, > > I am trying to optimize C++ code for an 16 Bit Microcontroller from > renesas, does someone have any idea, how can I approach this Problem.
If you have to optimize the C++ code, then something is apparently wrong. Either the task is wrong for this microcontroller, or you are wrong for this task.
> for any help i will be very grateful
And how much exactly is "very grateful" ? VLV
Op Tue, 18 Mar 2008 06:06:36 +0100 schreef Tim Wescott  
<tim@seemywebsite.com>:
> Grant Edwards wrote: >> On 2008-03-17, deel007@googlemail.com <deel007@googlemail.com> wrote: >> >>> I am trying to optimize C++ code for an 16 Bit Microcontroller >>> from renesas, does someone have any idea, how can I approach >>> this Problem. for any help i will be very grateful >> 1) Measure the performance/size/whatever of various functions >> or modules.
> 1a) compile to assembly and look at the assembly. This will help you > understand what the compiler is doing. I would do this with any new > serious* language I was learning. > > * Don't take me to task about the chances of doing this with Java or > Basic -- I'm being purposely chauvinistic against interpreted languages.
Java is not an interpreted language. Granted, most JVM's choose to interpret a large portion of the bytecode. But indeed looking at the output of either compiler (src & JIT) will most likely not be worth your time. -- Gemaakt met Opera's revolutionaire e-mailprogramma: http://www.opera.com/mail/



Boudewijn Dijkstra wrote:
> >schreef Tim Wescott: > >> Grant Edwards wrote:
>>>deel007@googlemail.com wrote: >>> >>>> I am trying to optimize C++ code for an 16 Bit Microcontroller >>>> from renesas, does someone have any idea, how can I approach >>>> this Problem. for any help i will be very grateful >>> >>> 1) Measure the performance/size/whatever of various functions >>> or modules. > >> 1a) compile to assembly and look at the assembly. This will help you >> understand what the compiler is doing. I would do this with any new >> serious* language I was learning. >> >> * Don't take me to task about the chances of doing this with Java or >> Basic -- I'm being purposely chauvinistic against interpreted languages. > >Java is not an interpreted language. Granted, most JVM's choose to >interpret a large portion of the bytecode. But indeed looking at the >output of either compiler (src & JIT) will most likely not be worth your >time.
BASIC also has both compilers and interpeters. FreeBASIC uses AS/GAS (the Gnu assembler) to create executable code, and is on track to becoming a front end for GCC. That being said, I have never heard of anything other than Assembly Language, C and Forth ( cir30 / ciforth ) being used with the Renesas 16-bitters. I am not a big fan of C++ for microcontrollers, but some folks seem to like it. C seems to be a better choice to me, but this may say more about my limitations than it does about C or C++. :) -- misc.business.product-dev: a Usenet newsgroup about the Business of Product Development. -- Guy Macon <http://www.guymacon.com/>
Guy Macon <http://www.guymacon.com/> writes:
> That being said, I have never heard of anything other than Assembly > Language, C and Forth ( cir30 / ciforth ) being used with the > Renesas 16-bitters.
The Renesas m32c line uses gcc, so any of the gcc front-ends would work. C, C++, FORTRAN, ObjC, etc. Assuming someone takes the time to port the runtime bits. I know C and C++ are there; I think someone had FORTRAN working at one point, or at least tried.
DJ Delorie schrieb:
> Guy Macon <http://www.guymacon.com/> writes: >> That being said, I have never heard of anything other than Assembly >> Language, C and Forth ( cir30 / ciforth ) being used with the >> Renesas 16-bitters. > > The Renesas m32c line uses gcc, so any of the gcc front-ends would > work. C, C++, FORTRAN, ObjC, etc. Assuming someone takes the time to > port the runtime bits. I know C and C++ are there; I think someone > had FORTRAN working at one point, or at least tried.
The IAR compiler for the Renesas M16C is able to compile C as well as C++. But I did not use C++ on this platform, so I cannot judge the quality. Greetings -- Dirk