Skip to content
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

Use inline assembly in full_fence #71

Merged
merged 1 commit into from
Aug 13, 2023
Merged

Use inline assembly in full_fence #71

merged 1 commit into from
Aug 13, 2023

Conversation

taiki-e
Copy link
Collaborator

@taiki-e taiki-e commented Aug 13, 2023

Fixes #70

cc @RalfJung

Copy link
Member

@notgull notgull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, but I'll let @RalfJung, the human UB detector, make the final call

src/notify.rs Show resolved Hide resolved
Comment on lines +570 to +571
// It is common to use `lock or` here, but when using a local variable, `lock not`, which
// does not change the flag, should be slightly more efficient.
Copy link
Collaborator Author

@taiki-e taiki-e Aug 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Note on potential future optimization: I have not benchmarked, but using xchg (lock prefix is implied) here may potentially be faster than lock not. The number of registers used will increase, but the value at a and the value to be written can be uninit. Making the value at a uninit with lock not is fine from a hardware standpoint, but Valgrind will probably be angry about it.)

@RalfJung
Copy link

Overall LGTM, but I'll let @RalfJung, the human UB detector, make the final call

Sorry, when it comes to inline assembly I'm out.^^ I can't even read assembly. ;)

However the compiler certainly has to assume that an inline assembly block (without nomem or readonly) performs synchronization actions such as an SC fence, so in broad strokes this should be correct, and I trust @taiki-e to get the details right. :)

Copy link
Member

@notgull notgull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@notgull notgull merged commit 7ce2634 into master Aug 13, 2023
@notgull notgull deleted the taiki-e/lock branch August 13, 2023 21:32
@taiki-e taiki-e mentioned this pull request Sep 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

UB due to lack of a full fence in full_fence (on x86)
3 participants