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

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

[avr-gcc-list] 8 bit bitwise operation promoted to 16 bit values


From: Alex Shepherd
Subject: [avr-gcc-list] 8 bit bitwise operation promoted to 16 bit values
Date: Sun, 26 Oct 2003 22:31:52 +1300

Hi Guys,

I was surprised a while ago to learn that the compiler can promote 8 bit
bitwise operations to 16 bit sometimes, so I had a look through some of
my code and looked at the LST files and sure enough there were some.

However it seemed to be inconsistent and adding the (unsigned char) type
case didn't seem to fix the problem as per the FAQ.

For instance:

LN_STATUS addByteToLocoNetPacket( LN_PACKET * RxPacket, byte RxByte )
{
  if( RxByte & 0x80 )
   
This code seems to be fine.

But this code:

  #define LN_TX_PORT            PORTB
  #define LN_TX_BIT             PB1
  #define LN_RX_PORT            ACSR
  #define LN_RX_BIT             ACO

  if( ( ( LN_TX_PORT >> LN_TX_BIT ) & 0x01 ) == ( ( LN_RX_PORT >>
LN_RX_BIT ) & 0x01 ) )

Will always produce a 16 bit operation even if I add the type casts like
so  

  if( ( ( LN_TX_PORT >> LN_TX_BIT ) & (byte)0x01 ) == ( ( LN_RX_PORT >>
LN_RX_BIT ) & (byte)0x01 ) )

Finally I had to do the following to make it do it:

  register byte Mask ;
  Mask = 0x01 ;
  if( ( ( LN_TX_PORT >> LN_TX_BIT ) & Mask ) == ( ( LN_RX_PORT >>
LN_RX_BIT ) & Mask ) )

Then it generates 8 bit only code.

Can anyone tell me what I need to do to get this to work correctly?

I have other instances but lets deal with this one first, maybe that
will sort the rest.

BTW I am using WinAVR-20030913 on Win XP

Cheers

Alex Shepherd



reply via email to

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