Serial_Lcd C / C++ Code Comparison

Go To Last Post
63 posts / 0 new

Pages

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

For IAR and GCC, that has been achieved. My goal is to achieve that for ImageCraft and CVAVR as well.

Exactly--just as you have nop() and sei() and cli() in the .h file, you should be able to put the #defines as in my example program into the CV section of the .h file.

This one confuses me a bit.

#if __CODEVISIONAVR__ >= 2
#include 
#else
#include 
#endif

I haven't used the version number this way, but I think >= 2 will always be true. For example, v. 1.24.3 gives 1243 as the value.

(according to the revision history, 1.24.3 is the version that added the io.h functionality)

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

With Lee's mention of a work-around for emitting #asm and also my writing of an ISR macro for CVAVR, there are now only two #ifdef's for CVAVR in serial_lcd.c file.

Edit: maybe Lee's work-around for #asm will also work for emitting #pragma which would then eliminate the need for the _Pragma operator. Still, I think there is merit in supporting standards so maybe Pavel will add _Pragma().

Last Edited: Thu. Mar 20, 2008 - 07:14 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
This one confuses me a bit.
That's because it's wrong ;) I'll just move to io.h as this project is not about having backward compatibility.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you talking about #pragma regalloc-/+ ? If so, then you might want to just try unchecking the Automatic Register Allocation in the project options, or edit the .PRJ

AutomaticRegisterAllocation=1
SmartRegisterAllocation=1

and change to 0. I usually use manual, but I think you can change Automatic to 0 and leave Smart at 1 and still get decent results.

[I thought #pragma WAS the way to do things like compiler options.]
[[As time goes on, I find myself using the #pragmas more and more in apps that need to "push the envelope" in some way. For example, I've got a tight timing app that I want "Speed" code generation. But there is a space crunch as well, so I jump into "Size" for non-time-critical sections that have repeated sequences.]]

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the info, Lee. I had already done that experimentation with automatic register allocation and it is working fine.

#pragma is the intended way to do compiler options. _Pragma() is just a standardized work-around for the inability to emit the sharp character from the C preprocessor.

So now, CVAVR has only one #ifdef and that is about related to inline functions. I don't expect that to get changed at anytime in the near future. So, the CVAVR port of serial_lcd is in great shape. I'm make a new release today or tomorrow.

Thanks for your help with it, Lee!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I'm make a new release today or tomorrow.

THEN I'll have to work it over to see how small I can get it. ;) IIRC CV came out OK, even with the lack of inline functions. (hmmmm--the Size optimizer would probably make them real functions anyway.)

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Very good, Lee. I'd be glad to see you efforts with the code. Eric spent time working on the code to see if he could make the GCC output smaller to reduce the difference between GCC and the small size of the IAR code -- but he was unable to shrink the GCC output size.

The inline functions are only single bit changes so it reasonable to have them as C macros. OTOH, for IAR and GCC I use inline functions as both a test of those compilers and my compatibility layer to correctly optimize those inline functions.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lee: I posted version 20080320 -- I'd welcome any improvements that you can make for CV's code size.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A first pass doesn't see much fat. I'll have to examine the impressive IAR results to see where the >10% comes from.

1) CV won't work correctly with your code under Size optimizations, since the repeated watchdog setup work gets turned into subroutines and won't meet the cycle limit. In practice, CV users would surround those sequences with #pragmas as is shown by a Wizard-generated template. Luckily there are so few bytes saved (9 words total) that going for Speed doesn't make a significant difference.

2) There is a typo in "#define BACKLIGHT_OFF() GPIOR1 &=~ ~0x01" that should probably be "#define BACKLIGHT_OFF() GPIOR1 &= ~0x01" ? That saves 4 words.

3) There are no LDS or STS in the whole program, and many registers available for global register variables in CV are unused. [That's why it doesn't make any difference how we set Automatic Register.] In practice if this came up, and ESPECIALLY if ISRs need to be as lean as possible, I'd hoist out to global register variables. This saves 7 words. Same could be said for other local variables; can skinny up those functions a hair.

4) Coding style comment, not really related to the size battle: For any real work, including a serial backpack, you've gotta check the status in the Rx ISR and discard or otherwise handle "bad" characters.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
1) CV won't work correctly with your code under Size optimizations, since the repeated watchdog setup work gets turned into subroutines
[...]
2) There is a typo in "#define BACKLIGHT_OFF() GPIOR1 &=~ ~0x01"
Thanks for the review, Lee. Those have been fixed.
Quote:
3) There are no LDS or STS in the whole program, and many registers available for global register variables in CV are unused.
Thanks a good optimization tip.
Quote:
4) Coding style comment, not really related to the size battle: For any real work, including a serial backpack, you've gotta check the status in the Rx ISR and discard or otherwise handle "bad" characters.
Thanks for noticing. I added a line of code to ignore RX bytes with framing errors.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I added a line of code to ignore RX bytes with framing errors.

My normal check is for framing error and data overrun. YMMV.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lee, it's a good idea to put a stub in their for data overrun to remind users they may wish to handle that error in some way.

I've released a new version on http://www.avrcode.com/serial_lcd/ with your previous suggestions.

Pages