Switch statement problems with Codewarrior 5.0

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

Switch statement problems with Codewarrior 5.0

3,033 次查看
FC
Contributor III

Hello,

 

For switch statments with a lot of labels, the simulator does not select the correct label.  It produces a lot of exta instructions.  If a few labels are used, then it works fine.  Below is the sample code.  For example, if level = 4, the simulator selects 12.

 

Thansks

 

switch(DISPLevelCode)
  {
   
    case 1:     DISPGraphData = 0x03;
                   break;
    case 2:     DISPGraphData = 0x0F;
                   break;
    case 3:     DISPGraphData = 0x3F;
                   break;
    case 4:     DISPGraphData = 0xFF;
                   break;
    case 8:     DISPGraphData = 0x01;
                   break;
    case 9:     DISPGraphData = 0x07;
                   break;
    case 10:   DISPGraphData = 0x1F;
                   break;
    case 11:   DISPGraphData = 0x7F;
                   break;
    case 12:   DISPGraphData = 0xFF;
                  break;
    default:    DISPGraphData = 0x00;

标签 (1)
标记 (1)
0 项奖励
回复
2 回复数

1,527 次查看
bigmac
Specialist III

Hello,

 

I wonder if this is an issue of optimisation by the compiler, since the same action occurs for case 4 and case 12.  You could have equally written this code in the following form, and there would be no issue.

 

  case 4:

  case 12:

     DISPGraphData = 0xFF; break;

 

 Does the issue still occur if different values are assigned in each of the cases?

 

Regards,

Mac

 

1,527 次查看
CompilerGuru
NXP Employee
NXP Employee

It's probably the branch tail merging optimization which combines the identical case entries.

Try with "-onb=t -onbt".

 

Daniel

 

BTW: Please always list which cpu you are targeting.