HCS08 C: bit field optimization

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HCS08 C: bit field optimization

Jump to solution
2,690 Views
BasePointer
Contributor II
Hi,
 
I defined LCD segments as bits in a struct.
 
Code:
typedef struct{ unsigned char R0:1; unsigned char R1:1; unsigned char R2:1; unsigned char R3:1; unsigned char R4:1; unsigned char R5:1; unsigned char R6:1; unsigned char R7:1;} TBits;typedef union { unsigned char Val; TBits Bit;} TLcdByte;
#pragma DATA_SEG MY_ZEROPAGE
  TLcdByte LCD_RAM[20];

 
and the definitions:
Code:
#define IND_L1           LCD_RAM[10].Bit.R0#define IND_L2           LCD_RAM[14].Bit.R2#define IND_L3           LCD_RAM[14].Bit.R3#define IND_NL1           LCD_RAM[10].Bit.R2#define IND_NL2           LCD_RAM[14].Bit.R0#define IND_NL3           LCD_RAM[14].Bit.R1#define IND_T1           LCD_RAM[14].Bit.R5#define IND_T2           LCD_RAM[14].Bit.R7#define IND_T3           LCD_RAM[9].Bit.R4#define IND_T4           LCD_RAM[8].Bit.R4
...

 
If I use
Code:
 IND_NL1 = 0; IND_NL2 = 0; IND_NL3 = 0; IND_L1 = 0; IND_L2 = 0; IND_L3 = 0; IND_PP = 0; IND_NP = 0; IND_PQ = 0; IND_NQ = 0;

 

instead of

Code:
IND_NL1 = IND_NL2 = IND_NL3 = IND_L1 = IND_L2 = IND_L3 = IND_PP = IND_NP = IND_PQ = IND_NQ = 0;

it generates more optimal code. Is this normal?

CW v6.1

10x
 


 
Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
1,218 Views
Lundin
Senior Contributor IV
I believe that the order of evaluation of nested assignments isn't specified by ISO C. So the compiler is free to evaluate the nested assignment in a completely random order, which might give code that isn't possible to optimize.

Another explanation could be that since there is no situation where it is motivated to use nested assignments, perhaps CW doesn't even bother with optimizing them.

View solution in original post

0 Kudos
Reply
2 Replies
1,219 Views
Lundin
Senior Contributor IV
I believe that the order of evaluation of nested assignments isn't specified by ISO C. So the compiler is free to evaluate the nested assignment in a completely random order, which might give code that isn't possible to optimize.

Another explanation could be that since there is no situation where it is motivated to use nested assignments, perhaps CW doesn't even bother with optimizing them.
0 Kudos
Reply
1,218 Views
BasePointer
Contributor II
Bad compiler.
 
Thanks Lundin.
0 Kudos
Reply