-
Notifications
You must be signed in to change notification settings - Fork 259
Implement __sync builtins for thumbv6-none-eabi #1050
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
Open
taiki-e
wants to merge
6
commits into
rust-lang:main
Choose a base branch
from
taiki-e:thumbv6k
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+413
−138
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
363382c
Implement __sync builtins for thumbv6-none-eabi
taiki-e c93feea
Separate __sync builtins definitions into its own file
taiki-e f989e56
Remove asm_use_dmb helper, rename dmb macro to cp15_barrier
taiki-e 5ccc285
Move arm's atomic-related code to sync module
taiki-e 83d096b
Remove casts and needless rustfmt::skip
taiki-e e420b6b
Add safety comments for arm_linux.rs and thumbv6k.rs
taiki-e File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| // Used by both arm_linux.rs and thumbv6k.rs. | ||
|
|
||
| // References: | ||
| // - https://llvm.org/docs/Atomics.html#libcalls-sync | ||
| // - https://gcc.gnu.org/onlinedocs/gcc/_005f_005fsync-Builtins.html | ||
| // - https://refspecs.linuxfoundation.org/elf/IA64-SysV-psABI.pdf#page=58 | ||
|
|
||
| atomic_rmw!(@old __sync_fetch_and_add_1, u8, |a: u8, b: u8| a.wrapping_add(b)); | ||
| atomic_rmw!(@old __sync_fetch_and_add_2, u16, |a: u16, b: u16| a | ||
| .wrapping_add(b)); | ||
| atomic_rmw!(@old __sync_fetch_and_add_4, u32, |a: u32, b: u32| a | ||
| .wrapping_add(b)); | ||
|
|
||
| atomic_rmw!(@new __sync_add_and_fetch_1, u8, |a: u8, b: u8| a.wrapping_add(b)); | ||
| atomic_rmw!(@new __sync_add_and_fetch_2, u16, |a: u16, b: u16| a | ||
| .wrapping_add(b)); | ||
| atomic_rmw!(@new __sync_add_and_fetch_4, u32, |a: u32, b: u32| a | ||
| .wrapping_add(b)); | ||
|
|
||
| atomic_rmw!(@old __sync_fetch_and_sub_1, u8, |a: u8, b: u8| a.wrapping_sub(b)); | ||
| atomic_rmw!(@old __sync_fetch_and_sub_2, u16, |a: u16, b: u16| a | ||
| .wrapping_sub(b)); | ||
| atomic_rmw!(@old __sync_fetch_and_sub_4, u32, |a: u32, b: u32| a | ||
| .wrapping_sub(b)); | ||
|
|
||
| atomic_rmw!(@new __sync_sub_and_fetch_1, u8, |a: u8, b: u8| a.wrapping_sub(b)); | ||
| atomic_rmw!(@new __sync_sub_and_fetch_2, u16, |a: u16, b: u16| a | ||
| .wrapping_sub(b)); | ||
| atomic_rmw!(@new __sync_sub_and_fetch_4, u32, |a: u32, b: u32| a | ||
| .wrapping_sub(b)); | ||
|
|
||
| atomic_rmw!(@old __sync_fetch_and_and_1, u8, |a: u8, b: u8| a & b); | ||
| atomic_rmw!(@old __sync_fetch_and_and_2, u16, |a: u16, b: u16| a & b); | ||
| atomic_rmw!(@old __sync_fetch_and_and_4, u32, |a: u32, b: u32| a & b); | ||
|
|
||
| atomic_rmw!(@new __sync_and_and_fetch_1, u8, |a: u8, b: u8| a & b); | ||
| atomic_rmw!(@new __sync_and_and_fetch_2, u16, |a: u16, b: u16| a & b); | ||
| atomic_rmw!(@new __sync_and_and_fetch_4, u32, |a: u32, b: u32| a & b); | ||
|
|
||
| atomic_rmw!(@old __sync_fetch_and_or_1, u8, |a: u8, b: u8| a | b); | ||
| atomic_rmw!(@old __sync_fetch_and_or_2, u16, |a: u16, b: u16| a | b); | ||
| atomic_rmw!(@old __sync_fetch_and_or_4, u32, |a: u32, b: u32| a | b); | ||
|
|
||
| atomic_rmw!(@new __sync_or_and_fetch_1, u8, |a: u8, b: u8| a | b); | ||
| atomic_rmw!(@new __sync_or_and_fetch_2, u16, |a: u16, b: u16| a | b); | ||
| atomic_rmw!(@new __sync_or_and_fetch_4, u32, |a: u32, b: u32| a | b); | ||
|
|
||
| atomic_rmw!(@old __sync_fetch_and_xor_1, u8, |a: u8, b: u8| a ^ b); | ||
| atomic_rmw!(@old __sync_fetch_and_xor_2, u16, |a: u16, b: u16| a ^ b); | ||
| atomic_rmw!(@old __sync_fetch_and_xor_4, u32, |a: u32, b: u32| a ^ b); | ||
|
|
||
| atomic_rmw!(@new __sync_xor_and_fetch_1, u8, |a: u8, b: u8| a ^ b); | ||
| atomic_rmw!(@new __sync_xor_and_fetch_2, u16, |a: u16, b: u16| a ^ b); | ||
| atomic_rmw!(@new __sync_xor_and_fetch_4, u32, |a: u32, b: u32| a ^ b); | ||
|
|
||
| atomic_rmw!(@old __sync_fetch_and_nand_1, u8, |a: u8, b: u8| !(a & b)); | ||
| atomic_rmw!(@old __sync_fetch_and_nand_2, u16, |a: u16, b: u16| !(a & b)); | ||
| atomic_rmw!(@old __sync_fetch_and_nand_4, u32, |a: u32, b: u32| !(a & b)); | ||
|
|
||
| atomic_rmw!(@new __sync_nand_and_fetch_1, u8, |a: u8, b: u8| !(a & b)); | ||
| atomic_rmw!(@new __sync_nand_and_fetch_2, u16, |a: u16, b: u16| !(a & b)); | ||
| atomic_rmw!(@new __sync_nand_and_fetch_4, u32, |a: u32, b: u32| !(a & b)); | ||
|
|
||
| atomic_rmw!(@old __sync_fetch_and_max_1, i8, |a: i8, b: i8| if a > b { | ||
| a | ||
| } else { | ||
| b | ||
| }); | ||
| atomic_rmw!(@old __sync_fetch_and_max_2, i16, |a: i16, b: i16| if a > b { | ||
| a | ||
| } else { | ||
| b | ||
| }); | ||
| atomic_rmw!(@old __sync_fetch_and_max_4, i32, |a: i32, b: i32| if a > b { | ||
| a | ||
| } else { | ||
| b | ||
| }); | ||
|
|
||
| atomic_rmw!(@old __sync_fetch_and_umax_1, u8, |a: u8, b: u8| if a > b { | ||
| a | ||
| } else { | ||
| b | ||
| }); | ||
| atomic_rmw!(@old __sync_fetch_and_umax_2, u16, |a: u16, b: u16| if a > b { | ||
| a | ||
| } else { | ||
| b | ||
| }); | ||
| atomic_rmw!(@old __sync_fetch_and_umax_4, u32, |a: u32, b: u32| if a > b { | ||
| a | ||
| } else { | ||
| b | ||
| }); | ||
|
|
||
| atomic_rmw!(@old __sync_fetch_and_min_1, i8, |a: i8, b: i8| if a < b { | ||
| a | ||
| } else { | ||
| b | ||
| }); | ||
| atomic_rmw!(@old __sync_fetch_and_min_2, i16, |a: i16, b: i16| if a < b { | ||
| a | ||
| } else { | ||
| b | ||
| }); | ||
| atomic_rmw!(@old __sync_fetch_and_min_4, i32, |a: i32, b: i32| if a < b { | ||
| a | ||
| } else { | ||
| b | ||
| }); | ||
|
|
||
| atomic_rmw!(@old __sync_fetch_and_umin_1, u8, |a: u8, b: u8| if a < b { | ||
| a | ||
| } else { | ||
| b | ||
| }); | ||
| atomic_rmw!(@old __sync_fetch_and_umin_2, u16, |a: u16, b: u16| if a < b { | ||
| a | ||
| } else { | ||
| b | ||
| }); | ||
| atomic_rmw!(@old __sync_fetch_and_umin_4, u32, |a: u32, b: u32| if a < b { | ||
| a | ||
| } else { | ||
| b | ||
| }); | ||
|
|
||
| atomic_rmw!(@old __sync_lock_test_and_set_1, u8, |_: u8, b: u8| b); | ||
| atomic_rmw!(@old __sync_lock_test_and_set_2, u16, |_: u16, b: u16| b); | ||
| atomic_rmw!(@old __sync_lock_test_and_set_4, u32, |_: u32, b: u32| b); | ||
|
|
||
| atomic_cmpxchg!(__sync_val_compare_and_swap_1, u8); | ||
| atomic_cmpxchg!(__sync_val_compare_and_swap_2, u16); | ||
| atomic_cmpxchg!(__sync_val_compare_and_swap_4, u32); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #[cfg(all( | ||
| kernel_user_helpers, | ||
| any(target_os = "linux", target_os = "android"), | ||
| target_arch = "arm" | ||
| ))] | ||
| pub mod arm_linux; | ||
|
|
||
| // Armv6k supports atomic instructions, but they are unavailable in Thumb mode | ||
| // unless Thumb-2 instructions available (v6t2). | ||
| // Using Thumb interworking allows us to use these instructions even from Thumb mode | ||
| // without Thumb-2 instructions, but LLVM does not implement that processing (as of LLVM 21), | ||
| // so we implement it here at this time. | ||
| // (`not(target_feature = "mclass")` is unneeded because v6k is not set on thumbv6m.) | ||
| #[cfg(all( | ||
| target_arch = "arm", | ||
| target_feature = "thumb-mode", | ||
| target_feature = "v6k", | ||
| not(target_feature = "v6t2"), | ||
| ))] | ||
| pub mod thumbv6k; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nit: could you name this
arm_thumb_sync_builtinsor similar?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.
Actually, I think we may as well group this by functionality like we have for other areas, something like:
I'll move the aarch64 builtins there too.
Uh oh!
There was an error while loading. Please reload this page.
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.
Done in 5ccc285.