This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] 编译器/TMS320F28377S:三态运算符和左移位上的优化器行为

Guru**** 2460850 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/726833/compiler-tms320f28377s-optimizer-behavior-on-ternary-operator-and-left-shift

器件型号:TMS320F28377S

工具/软件:TI C/C++编译器

您好 TI

我最近想用这种方式为32位无符号长整型值分配一些位、并看到优化器的一种奇怪的行为。

此代码被减少以显示我的意思:

volatile char myGlobalVolatileCharisOne = 1;

unsigned long myFunction (void)
{
unsigned long result = 0UL;
myGlobalVolatileCharisOne = 1;
result|=(myGlobalVolatileCharisOne? 1UL:0UL)<<1);
结果|=(myGlobalVolatileCharisOne? 1UL:0UL)<<16);
返回结果;
} 

我确实希望结果= 0x00010002。

使用-Ooff 时、我得到的结果= 0x00010002

使用-O3时、我得到的结果= 0x00000002

它似乎与左移相关。 如果我用这种方式编写表达式、则会按预期工作:

 Result |=(myGlobalVolatileCharisOne? 0x00010000UL:0UL);

这种方法也是可以的:

 Result |=(myGlobalVolatileCharisOne? (1UL<<16): 0UL);

CGT 16.9.8和 CGT 18.1.3

此致

Roger

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    感谢您报告此问题、并提交一份简明的测试案例。  我可以重现相同的结果。  我在 SDOWP 系统中提交了 CodeGen-5317、要求对此进行调查。  欢迎您在我的签名中使用下面的 SDOWP 链接进行访问。

    谢谢、此致、

    乔治

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    此致、谢谢
    Roger