----- Original Message ----- From: Stephen R Phillips To: Microcontroller discussion list - Public. Sent: Thursday, October 07, 2004 4:01 PM Subject: Re: [PIC] new optimisation in XCSB > > --- Sergio Masci wrote: > > It would be interesting to see how many C compilers can do better ;-) > > > > In hind sight the "bit" example was probably a bad one to choose > > since C > > supports bit fields and XCSB does not. Also given the nature of the > > PIC I would > > expect that a fair amount of effort has gone into optimising single > > bit access > > through C bit fields. > > C support for bit fields however is 'undefined'. By that I mean YES it > supports bit fields but the actual arrangement of the bits within > memory is completely undefined. Only through non ANSI extensions can a > deterministic bit field behavior be realized. It would have been nice > to have some standard, but I understand there rational for not having > such a standard (because the underlying hardware could be negatively > affected with weird bit ordering). However I think it was still short > sighted. If you use bit fields in C you are cursed with this problem. > So if you plan on storing bit fields or use them, you can't use them > with hardware addressed registers for example (like in the PIC's case), > without having it become non portable as a result. Regardless of this, the fact that you can easily identify an operation in C as a bit operation makes it much easier to generate special optimisations for it. struct { unsigned int RA0 : 1; unsigned int RA1 : 1; unsigned int RA2 : 1; unsigned int RA3 : 1; unsigned int RA4 : 1; unsigned int RA5 : 1; unsigned int RA6 : 1; } PORTA; PORTA.RA1 = 1; is easily identified as a bit operation. PORTA = PORTA | (1 << n) is much harder. Likewise if (PORTA.RA0 != 0) is much easier than if ((PORTA & (1 << n)) != 0) > > > > I really don't want to get into a C vs. XCSB debate, all I am trying > > to show is > > that the compiler does in fact generate highly optimised code and is > > worth > > looking at. > > > Are you using and intermediate code and performing transformation > optimization on that? (That's what GNU C does at least). Yes this is part of the process.. > > Stephen Regards Sergio Masci http://www.xcprod.com/titan/XCSB - optimising PIC compiler _______________________________________________ http://www.piclist.com View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist