avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] inline'ing sbi/cbi...


From: Herb Peyerl
Subject: [avr-gcc-list] inline'ing sbi/cbi...
Date: Mon, 12 Jan 2004 09:54:28 -0700

I think my brain is broken.  I might be trying to do something stupid.

My current project (the one using a nice state machine) has lots of
I/O port usage.  To make the code readable, I was hoping to do something
like:

        // from sfr_defs.h
        #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
        #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))

        #define FOO (PORTB,4)
        sbi(FOO);
        cbi(FOO);

Obviously I can't do that.  So to work around that, I did:

        static inline void inline_sbi(sfr, bit) { (_SFR_BYTE(sfr) |= _BV(bit)); 
 }
        static inline void inline_cbi(sfr, bit) { (_SFR_BYTE(sfr) &= 
~_BV(bit)); }

        #define FOO PORTB,4
        inline_sbi(FOO);
        inline_cbi(FOO);

The code works fine but is _significantly_ larger with the latter.

Changing one 'inline_sbi(FOO)' to an 'sbi(PORTB,4)' is a difference
of 12 bytes.

I tried pouring over the listing and I can't make heads-nor-tails of
what's going on.  It looks like in the case of 'sbi()' (which is 
a #define in sfr_defs.h) it does an actual 'sbi', whereas in the 
case of the inline, it does an 'in', some bit manipulations, and
then an 'out'.

Should not the outputted code be more or less identical at least
functionally with respect to the port manipulation?  (ignoring 
whether the compiler chooses to inline or simply call the function).


---
Beheading servers since 1999 -- The PC Weasel! http://www.realweasel.com


reply via email to

[Prev in Thread] Current Thread [Next in Thread]