lkml.org 
[lkml]   [2021]   [Jun]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC] LKMM: Add volatile_if()
On Sun, Jun 06, 2021 at 11:04:49AM -0700, Linus Torvalds wrote:
> if (READ_ONCE(a)) {
> barrier();
> WRITE_ONCE(b,1);
> } else {
> barrier();
> WRITE_ONCE(b, 1);
> }
>
> and currently because gcc thinks "same exact code", it will actually
> optimize this to (pseudo-asm):
>
> LD A
> "empty asm"
> ST $1,B
>
> which is very much NOT equivalent to
>
> LD A
> BEQ over
> "empty asm"
> ST $1,B
> JMP join
>
> over:
> "empty asm"
> ST $1,B
>
> join:
>
> and that's the whole point of the barriers.

You didn't use a barrier with these semantics though. There is nothing
in that code that guarantees a branch.

> See, but it VIOLATES the semantics of the code.

The code violates your expectations of the code.

> You can't join those two empty asm's (and then remove the branch),
> because the semantics of the code really aren't the same any more if
> you do. Truly.

You truly should have written a branch in tthe asm if you truly wanted
a branch instruction.


Segher

\
 
 \ /
  Last update: 2021-06-06 20:45    [W:0.131 / U:1.448 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site