-
Notifications
You must be signed in to change notification settings - Fork 240
Fix a_store operation in atomic.h #403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -182,13 +182,26 @@ static inline void a_dec(volatile int *p) | |
| #define a_store a_store | ||
| static inline void a_store(volatile int *p, int v) | ||
| { | ||
| #ifdef __wasilibc_unmodified_upstream | ||
| #ifdef a_barrier | ||
| a_barrier(); | ||
| *p = v; | ||
| a_barrier(); | ||
| #else | ||
| a_swap(p, v); | ||
| #endif | ||
| #else | ||
| /** | ||
| * The wasm opcodes generated by a_barrier mode are like below: | ||
| * atomic.fence | ||
| * local.get | ||
| * i32.const | ||
| * i32.store | ||
| * atomic.fence | ||
| * which are not atomic operations, so we use a_swap instead. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clearly the I guess Again, maybe better to just not defined
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
maybe it's assumed to be compiled to an atomic-enough instruction. like or maybe
are you aware of any doc which explains what musl expects?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is not easy to just use And yes, it is better to not define
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
instruction fetch doesn't matter because it's read-only.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The AOT code is generated dynamically according to the input bytecode, the machine codes generated may be like handler_of_I32.STORE:
...
store instruction
fetch next opcode and jump to its handler
...
...
handler_of_ATOMIC.FENCE:
memory barrier
fetch next opcode and jump to its handlerOr: handler_of_ATOMIC.FENCE:
memory barrier
fetch next opcode and jump to its handler
...
...
handler_of_I32.STORE:
...
store instruction
fetch next opcode and jump to its handlerNote there is only one
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks @sbc100, I removed the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
i don't understand your concern.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure, isn't the memory ordering related to the place of barrier inside the compiled code? And will it prevent the compiler from generation some re-ordered instructions?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. memory barrier is cpu instruction which takes effect when it's executed. |
||
| */ | ||
| a_swap(p, v); | ||
| #endif | ||
| } | ||
| #endif | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better so not defined
a_barrierinwasm32/atomic_arch.hif its not doing the right thing?