# Re: \[RFC\] LKMM: Add volatile\_if()

- From: Paul E. McKenney \<paulmck@kernel.org\>
- Date: 2021-06-06 19:15:43 
- List: linux-toolchains
- Page: https://ratatoskr.run/linux-toolchains/2021/06/1404050
- Thread: https://ratatoskr.run/linux-toolchains/2021/06/1402437/t.md

```text
On Sun, Jun 06, 2021 at 08:59:22PM +0200, Jakub Jelinek wrote:
> On Sat, Jun 05, 2021 at 08:41:00PM -0700, Linus Torvalds wrote:
> > Something like this *does* seem to work:
> > 
> >    #define ____barrier(id) __asm__ __volatile__("#" #id: : :"memory")
> >    #define __barrier(id) ____barrier(id)
> >    #define barrier() __barrier(__COUNTER__)
> > 
> > which is "interesting" or "disgusting" depending on how you happen to feel.
> 
> I think just
> #define barrier() __asm__ __volatile__("" : : "i" (__COUNTER__) : "memory")
> should be enough (or "X" instead of "i" if some arch uses -fpic and will not
> accept small constants in PIC code), for CSE gcc compares that the asm template
> string and all arguments are the same.

This does seem to do the trick: https://godbolt.org/z/K5j3bYqGT

So thank you for that!

							Thanx, Paul

> As for volatile, that is implicit on asm without any output operands and
> it is about whether the inline asm can be DCEd, not whether it can be CSEd.
> 
> 	Jakub
> 
```
