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

Add add/sub/and/or/xor methods that do not return previous value #47

Merged
merged 1 commit into from
Dec 9, 2022

Conversation

taiki-e
Copy link
Owner

@taiki-e taiki-e commented Dec 4, 2022

This adds Atomic{I,U}*::{add,sub,and,or,xor} and AtomicBool::{and,or,xor} methods.

They are equivalent to the corresponding fetch_* methods, but do not return the previous value. They are intended for optimization on platforms that implement atomics using inline assembly, such as the MSP430.

Currently, optimizations by these methods (add,sub,and,or,xor) are only guaranteed for MSP430; on x86, LLVM can optimize in most cases, so cases, where this would improve things, should be rare.

See pftbest/msp430-atomic#7 for the context.
cc @cr1901 @YuhanLiin

@taiki-e taiki-e added the O-msp430 Target: MSP430 label Dec 4, 2022
@taiki-e taiki-e mentioned this pull request Dec 4, 2022
5 tasks
@cr1901
Copy link

cr1901 commented Dec 4, 2022

Look great to me. @YuhanLiin, if this works for you, I'll release msp430-atomic v0.1.5 with a deprecation notice (yea, sorry about that :P). With this commit, msp430-atomic should be a proper subset of portable-atomic.

@@ -2539,6 +2779,55 @@ assert_eq!(foo.load(Ordering::SeqCst), 10);
}
}

doc_comment! {

Choose a reason for hiding this comment

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

Why not use triple slashes for this comment?

Copy link
Owner Author

Choose a reason for hiding this comment

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

If we want to stringify a macro metavariable using stringify!, we need to use the #[doc] attribute and string literal instead of the usual doc comment. In recent compilers (1.54+), #[doc = concat!(...)] also works, but in older compilers, a macro like this needs to be used.

Choose a reason for hiding this comment

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

Makes sense

@YuhanLiin
Copy link

Yeah everything looks good to me.

@taiki-e
Copy link
Owner Author

taiki-e commented Dec 9, 2022

Thanks both of you for the review!

bors r+

bors bot added a commit that referenced this pull request Dec 9, 2022
47: Add add/sub/and/or/xor methods that do not return previous value r=taiki-e a=taiki-e

This adds `Atomic{I,U}*::{add,sub,and,or,xor}` and `AtomicBool::{and,or,xor}` methods.

They are equivalent to the corresponding `fetch_*` methods, but do not return the previous value. They are intended for optimization on platforms that implement atomics using inline assembly, such as the MSP430.

Currently, optimizations by these methods (add,sub,and,or,xor) are only guaranteed for MSP430; on x86, LLVM can optimize in most cases, so cases, where this would improve things, should be rare.

See pftbest/msp430-atomic#7 for the context.
cc `@cr1901` `@YuhanLiin` 

Co-authored-by: Taiki Endo <te316e89@gmail.com>
@bors
Copy link
Contributor

bors bot commented Dec 9, 2022

Timed out.

@taiki-e
Copy link
Owner Author

taiki-e commented Dec 9, 2022

bors retry

@bors
Copy link
Contributor

bors bot commented Dec 9, 2022

@bors bors bot merged commit 6eac1c5 into main Dec 9, 2022
@bors bors bot deleted the no-fetch branch December 9, 2022 15:51
@taiki-e
Copy link
Owner Author

taiki-e commented Dec 9, 2022

Published in 0.3.16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-msp430 Target: MSP430
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants