HCS08 C: bit field optimization

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

HCS08 C: bit field optimization

跳至解决方案
2,695 次查看
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
 


 
标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,223 次查看
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 项奖励
回复
2 回复数
1,224 次查看
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 项奖励
回复
1,223 次查看
BasePointer
Contributor II
Bad compiler.
 
Thanks Lundin.
0 项奖励
回复