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.

[参考译文] TMS320F280039C:启用优化时、浮点值的位字段分配不正确。

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

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1398207/tms320f280039c-incorrect-bitfield-assignment-from-float-value-with-optimization-enabled

器件型号:TMS320F280039C

工具与软件:

您好!

在 uint64_t 中使用位字段时、我遇到了一个问题、其中更改一个字段会影响另一个字段。 仅当分配的值为负且启用了优化时才会发生这种情况。 下面提供了最小测试用例:

编译器版本:TI v22.6.0.1.LTS

///home/mwrze/ti/ccs1040/ccs/tools/compiler/ti-cgt-c2000_22.6.1.LTS/bin/cl2000 -c  --float_support=fpu32 --abi=eabi -mt --diag_wrap=off --keep_asm --gen_func_subsections=on --issue_remarks -g --c99 --fp_mode=relaxed -I/home/mwrze/ti/ccs1040/ccs/tools/compiler/ti-cgt-c2000_22.6.1.LTS/include -O1 main.c -fe main.o

#include "stdint.h"

struct 
{
    uint32_t a:16;
    uint32_t b:16;
}foo;

float getA(){return -10.f;}
int16_t getB(){return 10;}

int main(void)
{
    foo.b = getB();
    foo.a = (int16_t)getA();

    while (1) {}
}

我希望"a"应该是-10、"b"应该是10、二者都为 int16_t 但是、在给定的情况下、"a"的结果是正确的(-10)、但"b"等于0xFFFF。 我注意到、将浮点转换为 int16_t 时会发生错误(结果作为32位变量而不是16位变量写入 bitfield)。

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

    您好!

    我已将该线程提请编译器专家进行进一步分析。

    谢谢

    Ki

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

    感谢您报告此问题并提供一个简短的测试用例。  我能够重现相同的行为。  我提交了 EXT_EP-11874条目 来调查这件事。  我们欢迎您通过这个链接来了解。

    谢谢。此致、

    -George.