----- Original Message ----- From: To: Microcontroller discussion list - Public. Sent: Thursday, October 07, 2004 7:34 AM Subject: Re: [PIC] new optimisation in XCSB > On Wed, 6 Oct 2004, William Chops Westfield wrote: > > > Not exactly a fair comparison; He's bragging about the optimizer, > > not the quality of the original code. > > I don't see anything in that code that requires optimization. It's > purely constant expressions that can be evaluated at compile time. > > > Does the C compiler still only generate 2 instructions when you add > > an equivalently convoluted "abstraction" of io port bits? > > They're almost identically "abstracted" in the compiler's header file: > > > hwreg PORTA = 5 > > const RA3 = (&PORTA << 3) + 3 > > static volatile unsigned char PORTA @ 0x05; > static volatile bit RA3 @ (unsigned)&PORTA * 8 + 3; > > > and define functions? It's a substantial accomplishment, IMO... > > The functions were "inline", so they're probably interpreted more like > C macros than functions. But something like this: > > #define TEST_BIT(port, bit) (((port) & (1 << ((bit) & 7))) != 0) > #define SET_BIT(port, bit) ((port) |= (1 << ((bit) & 7))) > > void main(void) > { > if (TEST_BIT(PORTA, 3)) > SET_BIT(PORTB, 4); > } > > still generates two instructions. > > -- > John W. Temples, III Ok John, the following still generates only 3 instructions. proc inline set_bit(uint id) *(id >> 3) |= (1 << (id & 7)) endproc proc inline ubyte test_bit(uint id) return (*(id >> 3) & (1 << (id & 7))) != 0 endproc proc fred() byte flags if test_bit((&flags * 8) + 0) == 1 then set_bit((&flags * 8) + 1) endif endproc I would be grateful if you could tell me how this compares with the Hi-Tech PICC you are using. 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