From Fri, 21 Aug 2009 21:35:39 +0200 (MET DST)
j...@uriah.heep.sax.de (Joerg Wunsch) wrote:

> Francisco Silva <fran...@gmail.com> wrote:
> > Try the following spell:
> Using a typecast looks a little better, I think.
Looks better, but does not work. But Francisco recipe works, wonders.
Another solution which works is your hint about inline functions, e.g:

static inline uint8_t dummy (uint8_t x) { return x; }

if (dummy (flags & (FLAG_A | FLAG_B))) ...

what's interesting as well is that I have two of such if's in code, and
"fixing" the first one automagically fixes the second if without making
any actual modifications to it.

> Andrew, maybe you can post some compilable code snippet to check.
Sure, I've attached a bare-bone sample which I can't force to use eight
bits without the temporary variable or inline function hack.

The command line I use is:

avr-gcc -mmcu=atmega168 -S -Os code.c

in the resulting .S file (I hope) you will see this:

movw r24,r28
andi r24,lo8(7)
andi r25,hi8(7)
or r24,r25
breq .L2
call something
.L2:
...

ditto for second if.

-- 
Andrew
#include <stdint.h>

#define TTY_F_DISPLAY           ((uint8_t)0x01)
#define TTY_F_CURSOR            ((uint8_t)0x02)
#define TTY_F_BLINKCURSOR       ((uint8_t)0x04)
#define TTY_F_SCROLL            ((uint8_t)0x08)
#define TTY_F_L2R               ((uint8_t)0x10)

uint8_t tty_flags;

extern void something (void);
extern void somethingelse (void);

static inline uint8_t blah (uint8_t x)
{ return x; }

void tty_setup (uint8_t flags, uint8_t mask)
{
    uint8_t new_flags = (tty_flags & ~mask) | (flags & mask);
    uint8_t flags_changed = new_flags ^ tty_flags;
    tty_flags = new_flags;

    if (flags_changed & (TTY_F_DISPLAY | TTY_F_CURSOR | TTY_F_BLINKCURSOR))
        something ();

    if (flags_changed & (TTY_F_SCROLL | TTY_F_L2R))
        somethingelse ();
}

Attachment: signature.asc
Description: PGP signature

_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to