Skip to content

Commit 776ca70

Browse files
committed
move outlined_atomics from build.rs as aarch64_linux.rs
1 parent add44a7 commit 776ca70

File tree

3 files changed

+60
-63
lines changed

3 files changed

+60
-63
lines changed

compiler-builtins/build.rs

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
mod configure;
22

3-
use std::collections::BTreeMap;
43
use std::env;
5-
use std::path::PathBuf;
6-
use std::sync::atomic::Ordering;
74

85
use configure::{Target, configure_aliases, configure_f16_f128};
96

@@ -86,9 +83,6 @@ fn main() {
8683
println!("cargo:rustc-cfg=kernel_user_helpers")
8784
}
8885

89-
if llvm_target[0].starts_with("aarch64") {
90-
generate_aarch64_outlined_atomics();
91-
}
9286
}
9387

9488
/// Run configuration for `libm` since it is included directly.
@@ -131,61 +125,6 @@ fn configure_libm(target: &Target) {
131125
println!("cargo:rustc-cfg=feature=\"unstable-intrinsics\"");
132126
}
133127

134-
fn aarch64_symbol(ordering: Ordering) -> &'static str {
135-
match ordering {
136-
Ordering::Relaxed => "relax",
137-
Ordering::Acquire => "acq",
138-
Ordering::Release => "rel",
139-
Ordering::AcqRel => "acq_rel",
140-
_ => panic!("unknown symbol for {ordering:?}"),
141-
}
142-
}
143-
144-
/// The `concat_idents` macro is extremely annoying and doesn't allow us to define new items.
145-
/// Define them from the build script instead.
146-
/// Note that the majority of the code is still defined in `aarch64.rs` through inline macros.
147-
fn generate_aarch64_outlined_atomics() {
148-
use std::fmt::Write;
149-
// #[macro_export] so that we can use this in tests
150-
let gen_macro =
151-
|name| format!("#[macro_export] macro_rules! foreach_{name} {{ ($macro:path) => {{\n");
152-
153-
// Generate different macros for add/clr/eor/set so that we can test them separately.
154-
let sym_names = ["cas", "ldadd", "ldclr", "ldeor", "ldset", "swp"];
155-
let mut macros = BTreeMap::new();
156-
for sym in sym_names {
157-
macros.insert(sym, gen_macro(sym));
158-
}
159-
160-
// Only CAS supports 16 bytes, and it has a different implementation that uses a different macro.
161-
let mut cas16 = gen_macro("cas16");
162-
163-
for ordering in [
164-
Ordering::Relaxed,
165-
Ordering::Acquire,
166-
Ordering::Release,
167-
Ordering::AcqRel,
168-
] {
169-
let sym_ordering = aarch64_symbol(ordering);
170-
for size in [1, 2, 4, 8] {
171-
for (sym, macro_) in &mut macros {
172-
let name = format!("__aarch64_{sym}{size}_{sym_ordering}");
173-
writeln!(macro_, "$macro!( {ordering:?}, {size}, {name} );").unwrap();
174-
}
175-
}
176-
let name = format!("__aarch64_cas16_{sym_ordering}");
177-
writeln!(cas16, "$macro!( {ordering:?}, {name} );").unwrap();
178-
}
179-
180-
let mut buf = String::new();
181-
for macro_def in macros.values().chain(std::iter::once(&cas16)) {
182-
buf += macro_def;
183-
buf += "}; }\n";
184-
}
185-
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
186-
std::fs::write(out_dir.join("outlined_atomics.rs"), buf).unwrap();
187-
}
188-
189128
/// Emit directives for features we expect to support that aren't in `Cargo.toml`.
190129
///
191130
/// These are mostly cfg elements emitted by this `build.rs`.

compiler-builtins/src/aarch64_linux.rs

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,65 @@ macro_rules! or {
262262
};
263263
}
264264

265-
// See `generate_aarch64_outlined_atomics` in build.rs.
266-
include!(concat!(env!("OUT_DIR"), "/outlined_atomics.rs"));
265+
macro_rules! foreach_ordering {
266+
($macro:path, $bytes:tt, $name:ident) => {
267+
$macro!( Relaxed, $bytes, ${concat($name,_relax)} );
268+
$macro!( Acquire, $bytes, ${concat($name, _acq)} );
269+
$macro!( Release, $bytes, ${concat($name, _rel)} );
270+
$macro!( AcqRel, $bytes, ${concat($name, _acq_rel)} );
271+
};
272+
($macro:path, $name:ident) => {
273+
$macro!( Relaxed, ${concat($name,_relax)} );
274+
$macro!( Acquire, ${concat($name, _acq)} );
275+
$macro!( Release, ${concat($name, _rel)} );
276+
$macro!( AcqRel, ${concat($name, _acq_rel)} );
277+
};
278+
}
279+
280+
macro_rules! foreach_bytes {
281+
($macro:path, $name:ident) => {
282+
foreach_ordering!( $macro, 1, ${concat(__aarch64_, $name, "1")} );
283+
foreach_ordering!( $macro, 2, ${concat(__aarch64_, $name, "2")} );
284+
foreach_ordering!( $macro, 4, ${concat(__aarch64_, $name, "4")} );
285+
foreach_ordering!( $macro, 8, ${concat(__aarch64_, $name, "8")} );
286+
};
287+
}
288+
macro_rules! foreach_cas {
289+
($macro:path) => {
290+
foreach_bytes!($macro, cas);
291+
};
292+
}
293+
macro_rules! foreach_cas16 {
294+
($macro:path) => {
295+
foreach_ordering!($macro, __aarch64_cas16);
296+
};
297+
}
298+
macro_rules! foreach_swp {
299+
($macro:path) => {
300+
foreach_bytes!($macro, swp);
301+
};
302+
}
303+
macro_rules! foreach_ldadd {
304+
($macro:path) => {
305+
foreach_bytes!($macro, ldadd);
306+
};
307+
}
308+
macro_rules! foreach_ldclr {
309+
($macro:path) => {
310+
foreach_bytes!($macro, ldclr);
311+
};
312+
}
313+
macro_rules! foreach_ldeor {
314+
($macro:path) => {
315+
foreach_bytes!($macro, ldeor);
316+
};
317+
}
318+
macro_rules! foreach_ldset {
319+
($macro:path) => {
320+
foreach_bytes!($macro, ldset);
321+
};
322+
}
323+
267324
foreach_cas!(compare_and_swap);
268325
foreach_cas16!(compare_and_swap_i128);
269326
foreach_swp!(swap);

compiler-builtins/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![feature(linkage)]
99
#![feature(naked_functions)]
1010
#![feature(repr_simd)]
11+
#![feature(macro_metavar_expr_concat)]
1112
#![cfg_attr(f16_enabled, feature(f16))]
1213
#![cfg_attr(f128_enabled, feature(f128))]
1314
#![no_builtins]

0 commit comments

Comments
 (0)