当 GCC 进行快速优化时保持逻辑表达式的优先级

发布于 2025-01-13 16:39:29 字数 714 浏览 3 评论 0原文

我有一个 FreeRTOS 任务,它使用任务通知在调用函数和任务本身之间发出信号。然而,该任务也可以通过标志 dataWaiting 来“解锁”。

/* Make this function not optimized to maintain precedence of logical operation */
#pragma GCC push_options
#pragma GCC optimize ("O0")

void printTask(void * argument)
{
  uart1Busy = false;

  int kItr;
  char chr[1];

  while(1)
  {
    /* If data is waiting then dive straight in, otherwise wait for a notification
     * from the printfdma function.
     */
    if((dataWaiting || ulTaskNotifyTake(pdTRUE, portMAX_DELAY)))
    {
        dataWaiting = false;

如果我允许 Ofast 优化,编译器会重新排序 if 语句,以便该函数永远不会“解锁”。为了解决这个问题,我做了一个 pragma push “O0 来防止优化,但这必须应用于整个有谁

知道如何“强制”逻辑表达式的顺序以遵守Ofast 的优化?

I have a FreeRTOS task that uses task notification to signal between a calling function and the task itself. However the task can also be "unblocked" by a flag dataWaiting.

/* Make this function not optimized to maintain precedence of logical operation */
#pragma GCC push_options
#pragma GCC optimize ("O0")

void printTask(void * argument)
{
  uart1Busy = false;

  int kItr;
  char chr[1];

  while(1)
  {
    /* If data is waiting then dive straight in, otherwise wait for a notification
     * from the printfdma function.
     */
    if((dataWaiting || ulTaskNotifyTake(pdTRUE, portMAX_DELAY)))
    {
        dataWaiting = false;

If I allow the Ofast optimization the compiler reorders the if statement such that the function never "unblocks" To fix this I did a pragma push "O0 to prevent optimization, however this has to be applied across the whole task.

Does anyone know how you can "force" the order of the logical expression to be honored with optimization made Ofast?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文