Skip to main content
Matt.Dash
Associate II
November 28, 2022
Solved

what's the __COMPILER_BARRIER?

  • November 28, 2022
  • 2 replies
  • 4244 views

hi, everyone!

May you have a nice day!

In en.stm32cubeg4_v1-5-0\STM32Cube_FW_G4_V1.5.0\Projects, core_cm4.h file.

I encounter the following codes:

__STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn)

{

  if ((int32_t)(IRQn) >= 0)

  {

    __COMPILER_BARRIER();

    NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));

    __COMPILER_BARRIER();

  }

}

So the questions are:

  1. what's the meaning of __COMPILER_BARRIER();?
  2. why it's called here, is ISERx registers related to it?
  3. could anyone share some literature on this?

thank you for your attention!

Best wishes!

This topic has been closed for replies.
Best answer by Matt.Dash

HI, everyone.

I think this post answers my question in detail, lets close this topic.

gcc - difference in mfence and asm volatile ("" : : : "memory") - Stack Overflow

2 replies

Tesla DeLorean
Guru
November 28, 2022

Goto the definition of the function

T​ypically such things are designed to stop the compiler moving or optimizing code that has primary, or secondary, behavior the compiler can't understand.

O​r involves a memory fencing requirement, where data needs to reach its final destination before completion. So pipeline and write buffers must complete before next instruction starts.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Matt.Dash
Matt.DashAuthor
Associate II
November 29, 2022

hi tesla, thank you for your answer~

here is its definition:

#define __COMPILER_BARRIER() __ASM volatile("":::"memory")

it seems conform to the following format:

asm(code : output operand list : input operand list : clobber list);

I am new to this, where should I go to find related literature  or pdf ?

thank you very much!

Matt.Dash
Matt.DashAuthorBest answer
Associate II
October 9, 2023

HI, everyone.

I think this post answers my question in detail, lets close this topic.

gcc - difference in mfence and asm volatile ("" : : : "memory") - Stack Overflow

Tesla DeLorean
Guru
October 9, 2023

The predominant hazard with the NVIC and peripherals is that the write-buffers clearing the source of an interrupt can be slower than the interrupt tail-chaining mechanics resulting in it wanting to re-enter the IRQHandler somewhat spuriously.  When you double-check the source it will have been cleared. So robust coding of the Handler is recommended.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..