[sdiy] Quick C query

Tom Wiltshire tom at electricdruid.net
Mon Nov 22 16:16:59 CET 2010


On 22 Nov 2010, at 14:44, Eric Brombaugh wrote:

> The C compiler for the dsPIC (Tom's MCU in this case) is based on GCC with some proprietary optimizations added on. Unfortunately, MCHP has intertwined GCC with their own non-free material to such an extent that it's very difficult to create an OSS/Free distribution of dsPIC GCC. Tom Sailer did this a few years ago and posted the build instructions here:
> 
> http://www.baycom.org/~tom/dspic/
> 
> but it's a fairly complex process, and extremely dated at this point. The upshot of course is that unless you're willing to fork out ~$1k for MCHP's version you won't have access to the highest levels of optimization (they do allow -O1 for free), and the optimizations that are available in the OSS/Free versions of GCC are out of the question unless you're a compiler geek and capable of updating the dsPIC GCC sources yourself.
> 
> The good news is that for most stuff the free 1st-level optimization is fairly good. I've tried the higher levels during the 60-day trial period and they haven't provided a significant reduction in code size or speed on my test cases.
> 
> Eric


Further good news (from my point of view) is that having tested various methods of dealing with booleans, it looks like Microchip have optimized the compiler for their preferred "struct" bitfield way of doing things.

Doing something like this:

 struct MainFlags {
               unsigned        EditMode :1;
               unsigned        ReleaseDelay :1;
               unsigned        ButtonPressed:1;

       } MainFlags;

..gives you three flags in sequential bits in one byte, and setting the flags:

       // I can then set these up
       MainFlags.EditMode = 0;
       MainFlags.ReleaseDelay = 0;
       MainFlags.ButtonPressed = 0;

..is done using the bclr (bit clear) instruction, which is exactly what I've have done in assembly. So I'm a happy bunny.

Thanks,
Tom






More information about the Synth-diy mailing list