Optimize C++ for a microcontroller

Mar 17, 2008 9 Replies

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


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.

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...

In summary: Lather. Rinse. Repeat.

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

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.

And how much exactly is "very grateful" ?

VLV

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/

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

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

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required