Skip to content

Commit 04835ea

Browse files
committed
Add #[cfg(target_has_atomic)] to get atomic support for the current target
1 parent 50909f2 commit 04835ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+90
-10
lines changed

src/doc/reference.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,6 +2091,8 @@ The following configurations must be defined by the implementation:
20912091
* `target_pointer_width = "..."` - Target pointer width in bits. This is set
20922092
to `"32"` for targets with 32-bit pointers, and likewise set to `"64"` for
20932093
64-bit pointers.
2094+
* `target_has_atomic = "..."` - Set of integer sizes on which the target can perform
2095+
atomic operations. Values are `"8"`, `"16"`, `"32"`, `"64"` and `"ptr"`.
20942096
* `target_vendor = "..."` - Vendor of the target, for example `apple`, `pc`, or
20952097
simply `"unknown"`.
20962098
* `test` - Enabled when compiling the test harness (using the `--test` flag).
@@ -2295,6 +2297,9 @@ The currently implemented features of the reference compiler are:
22952297
* `cfg_target_vendor` - Allows conditional compilation using the `target_vendor`
22962298
matcher which is subject to change.
22972299

2300+
* `cfg_target_has_atomic` - Allows conditional compilation using the `target_has_atomic`
2301+
matcher which is subject to change.
2302+
22982303
* `concat_idents` - Allows use of the `concat_idents` macro, which is in many
22992304
ways insufficient for concatenating identifiers, and may be
23002305
removed entirely for something more wholesome.

src/libcore/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#![feature(associated_type_defaults)]
6464
#![feature(concat_idents)]
6565
#![feature(const_fn)]
66+
#![feature(cfg_target_has_atomic)]
6667
#![feature(custom_attribute)]
6768
#![feature(fundamental)]
6869
#![feature(inclusive_range_syntax)]

src/librustc/session/config.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
695695
let os = &sess.target.target.target_os;
696696
let env = &sess.target.target.target_env;
697697
let vendor = &sess.target.target.target_vendor;
698+
let max_atomic_width = sess.target.target.options.max_atomic_width;
698699

699700
let fam = if let Some(ref fam) = sess.target.target.options.target_family {
700701
intern(fam)
@@ -721,6 +722,15 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
721722
if sess.target.target.options.has_elf_tls {
722723
ret.push(attr::mk_word_item(InternedString::new("target_thread_local")));
723724
}
725+
for &i in &[8, 16, 32, 64, 128] {
726+
if i <= max_atomic_width {
727+
let s = i.to_string();
728+
ret.push(mk(InternedString::new("target_has_atomic"), intern(&s)));
729+
if &s == wordsz {
730+
ret.push(mk(InternedString::new("target_has_atomic"), intern("ptr")));
731+
}
732+
}
733+
}
724734
if sess.opts.debug_assertions {
725735
ret.push(attr::mk_word_item(InternedString::new("debug_assertions")));
726736
}

src/librustc_back/target/aarch64_apple_ios.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub fn target() -> Target {
2424
options: TargetOptions {
2525
features: "+neon,+fp-armv8,+cyclone".to_string(),
2626
eliminate_frame_pointer: false,
27+
max_atomic_width: 128,
2728
.. opts(Arch::Arm64)
2829
},
2930
}

src/librustc_back/target/aarch64_linux_android.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use target::Target;
1212

1313
pub fn target() -> Target {
14+
let mut base = super::android_base::opts();
15+
base.max_atomic_width = 128;
1416
Target {
1517
llvm_target: "aarch64-linux-android".to_string(),
1618
target_endian: "little".to_string(),
@@ -20,6 +22,6 @@ pub fn target() -> Target {
2022
target_os: "android".to_string(),
2123
target_env: "".to_string(),
2224
target_vendor: "unknown".to_string(),
23-
options: super::android_base::opts(),
25+
options: base,
2426
}
2527
}

src/librustc_back/target/aarch64_unknown_linux_gnu.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
use target::Target;
1212

1313
pub fn target() -> Target {
14-
let base = super::linux_base::opts();
14+
let mut base = super::linux_base::opts();
15+
base.max_atomic_width = 128;
1516
Target {
1617
llvm_target: "aarch64-unknown-linux-gnu".to_string(),
1718
target_endian: "little".to_string(),

src/librustc_back/target/arm_linux_androideabi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use target::Target;
1313
pub fn target() -> Target {
1414
let mut base = super::android_base::opts();
1515
base.features = "+v7,+vfp3,+d16".to_string();
16+
base.max_atomic_width = 64;
1617

1718
Target {
1819
llvm_target: "arm-linux-androideabi".to_string(),

src/librustc_back/target/arm_unknown_linux_gnueabi.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
use target::{Target, TargetOptions};
1212

1313
pub fn target() -> Target {
14-
let base = super::linux_base::opts();
14+
let mut base = super::linux_base::opts();
15+
base.max_atomic_width = 64;
1516
Target {
1617
llvm_target: "arm-unknown-linux-gnueabi".to_string(),
1718
target_endian: "little".to_string(),

src/librustc_back/target/arm_unknown_linux_gnueabihf.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
use target::{Target, TargetOptions};
1212

1313
pub fn target() -> Target {
14-
let base = super::linux_base::opts();
14+
let mut base = super::linux_base::opts();
15+
base.max_atomic_width = 64;
1516
Target {
1617
llvm_target: "arm-unknown-linux-gnueabihf".to_string(),
1718
target_endian: "little".to_string(),

src/librustc_back/target/armv7_apple_ios.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub fn target() -> Target {
2323
target_vendor: "apple".to_string(),
2424
options: TargetOptions {
2525
features: "+v7,+vfp3,+neon".to_string(),
26+
max_atomic_width: 64,
2627
.. opts(Arch::Armv7)
2728
}
2829
}

0 commit comments

Comments
 (0)