Skip to content

Commit f9e7c11

Browse files
committed
Port all non-x86 uses of rustc_args_required_const to rustc_legacy_const_generics
1 parent 594ff85 commit f9e7c11

File tree

4 files changed

+44
-61
lines changed

4 files changed

+44
-61
lines changed

crates/core_arch/src/aarch64/prefetch.rs

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ pub const _PREFETCH_LOCALITY2: i32 = 2;
2424
/// See [`prefetch`](fn._prefetch.html).
2525
pub const _PREFETCH_LOCALITY3: i32 = 3;
2626

27-
/// Fetch the cache line that contains address `p` using the given `rw` and `locality`.
27+
/// Fetch the cache line that contains address `p` using the given `RW` and `LOCALITY`.
2828
///
29-
/// The `rw` must be one of:
29+
/// The `RW` must be one of:
3030
///
3131
/// * [`_PREFETCH_READ`](constant._PREFETCH_READ.html): the prefetch is preparing
3232
/// for a read.
3333
///
3434
/// * [`_PREFETCH_WRITE`](constant._PREFETCH_WRITE.html): the prefetch is preparing
3535
/// for a write.
3636
///
37-
/// The `locality` must be one of:
37+
/// The `LOCALITY` must be one of:
3838
///
3939
/// * [`_PREFETCH_LOCALITY0`](constant._PREFETCH_LOCALITY0.html): Streaming or
4040
/// non-temporal prefetch, for data that is used only once.
@@ -55,35 +55,19 @@ pub const _PREFETCH_LOCALITY3: i32 = 3;
5555
///
5656
/// [Arm's documentation](https://developer.arm.com/documentation/den0024/a/the-a64-instruction-set/memory-access-instructions/prefetching-memory?lang=en)
5757
#[inline(always)]
58-
#[cfg_attr(test, assert_instr("prfm pldl1strm", rw = _PREFETCH_READ, locality = _PREFETCH_LOCALITY0))]
59-
#[cfg_attr(test, assert_instr("prfm pldl3keep", rw = _PREFETCH_READ, locality = _PREFETCH_LOCALITY1))]
60-
#[cfg_attr(test, assert_instr("prfm pldl2keep", rw = _PREFETCH_READ, locality = _PREFETCH_LOCALITY2))]
61-
#[cfg_attr(test, assert_instr("prfm pldl1keep", rw = _PREFETCH_READ, locality = _PREFETCH_LOCALITY3))]
62-
#[cfg_attr(test, assert_instr("prfm pstl1strm", rw = _PREFETCH_WRITE, locality = _PREFETCH_LOCALITY0))]
63-
#[cfg_attr(test, assert_instr("prfm pstl3keep", rw = _PREFETCH_WRITE, locality = _PREFETCH_LOCALITY1))]
64-
#[cfg_attr(test, assert_instr("prfm pstl2keep", rw = _PREFETCH_WRITE, locality = _PREFETCH_LOCALITY2))]
65-
#[cfg_attr(test, assert_instr("prfm pstl1keep", rw = _PREFETCH_WRITE, locality = _PREFETCH_LOCALITY3))]
66-
#[rustc_args_required_const(1, 2)]
67-
pub unsafe fn _prefetch(p: *const i8, rw: i32, locality: i32) {
58+
#[cfg_attr(test, assert_instr("prfm pldl1strm", RW = _PREFETCH_READ, LOCALITY = _PREFETCH_LOCALITY0))]
59+
#[cfg_attr(test, assert_instr("prfm pldl3keep", RW = _PREFETCH_READ, LOCALITY = _PREFETCH_LOCALITY1))]
60+
#[cfg_attr(test, assert_instr("prfm pldl2keep", RW = _PREFETCH_READ, LOCALITY = _PREFETCH_LOCALITY2))]
61+
#[cfg_attr(test, assert_instr("prfm pldl1keep", RW = _PREFETCH_READ, LOCALITY = _PREFETCH_LOCALITY3))]
62+
#[cfg_attr(test, assert_instr("prfm pstl1strm", RW = _PREFETCH_WRITE, LOCALITY = _PREFETCH_LOCALITY0))]
63+
#[cfg_attr(test, assert_instr("prfm pstl3keep", RW = _PREFETCH_WRITE, LOCALITY = _PREFETCH_LOCALITY1))]
64+
#[cfg_attr(test, assert_instr("prfm pstl2keep", RW = _PREFETCH_WRITE, LOCALITY = _PREFETCH_LOCALITY2))]
65+
#[cfg_attr(test, assert_instr("prfm pstl1keep", RW = _PREFETCH_WRITE, LOCALITY = _PREFETCH_LOCALITY3))]
66+
#[rustc_legacy_const_generics(1, 2)]
67+
// FIXME: Replace this with the standard ACLE __pld/__pldx/__pli/__plix intrinsics
68+
pub unsafe fn _prefetch<const RW: i32, const LOCALITY: i32>(p: *const i8) {
6869
// We use the `llvm.prefetch` instrinsic with `cache type` = 1 (data cache).
69-
// `rw` and `strategy` are based on the function parameters.
70-
macro_rules! pref {
71-
($rdwr:expr, $local:expr) => {
72-
match ($rdwr, $local) {
73-
(0, 0) => prefetch(p, 0, 0, 1),
74-
(0, 1) => prefetch(p, 0, 1, 1),
75-
(0, 2) => prefetch(p, 0, 2, 1),
76-
(0, 3) => prefetch(p, 0, 3, 1),
77-
(1, 0) => prefetch(p, 1, 0, 1),
78-
(1, 1) => prefetch(p, 1, 1, 1),
79-
(1, 2) => prefetch(p, 1, 2, 1),
80-
(1, 3) => prefetch(p, 1, 3, 1),
81-
(_, _) => panic!(
82-
"Illegal (rw, locality) pair in prefetch, value ({}, {}).",
83-
$rdwr, $local
84-
),
85-
}
86-
};
87-
}
88-
pref!(rw, locality);
70+
static_assert_imm1!(RW);
71+
static_assert_imm2!(LOCALITY);
72+
prefetch(p, RW, LOCALITY, 1);
8973
}

crates/core_arch/src/aarch64/tme.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,11 @@ pub unsafe fn __tcommit() {
9393
/// [ARM TME Intrinsics](https://developer.arm.com/docs/101028/0010/transactional-memory-extension-tme-intrinsics).
9494
#[inline]
9595
#[target_feature(enable = "tme")]
96-
#[cfg_attr(test, assert_instr(tcancel, imm0 = 0x0))]
97-
#[rustc_args_required_const(0)]
98-
pub unsafe fn __tcancel(imm0: u64) {
99-
macro_rules! call {
100-
($imm0:expr) => {
101-
aarch64_tcancel($imm0)
102-
};
103-
}
104-
constify_imm8!(imm0, call)
96+
#[cfg_attr(test, assert_instr(tcancel, IMM16 = 0x0))]
97+
#[rustc_legacy_const_generics(0)]
98+
pub unsafe fn __tcancel<const IMM16: u64>() {
99+
static_assert!(IMM16: u64 where IMM16 <= 65535);
100+
aarch64_tcancel(IMM16);
105101
}
106102

107103
/// Tests if executing inside a transaction. If no transaction is currently executing,
@@ -160,7 +156,7 @@ mod tests {
160156
if code == _TMSTART_SUCCESS {
161157
x += 1;
162158
assert_eq!(x, i + 1);
163-
tme::__tcancel(CANCEL_CODE);
159+
tme::__tcancel::<CANCEL_CODE>();
164160
break;
165161
}
166162
}
@@ -174,7 +170,7 @@ mod tests {
174170
let code = tme::__tstart();
175171
if code == _TMSTART_SUCCESS {
176172
if tme::__ttest() == 2 {
177-
tme::__tcancel(CANCEL_CODE);
173+
tme::__tcancel::<CANCEL_CODE>();
178174
break;
179175
}
180176
}

crates/core_arch/src/powerpc/vsx.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,13 @@ mod sealed {
7575
/// Vector permute.
7676
#[inline]
7777
#[target_feature(enable = "vsx")]
78-
#[rustc_args_required_const(2)]
79-
pub unsafe fn vec_xxpermdi<T>(a: T, b: T, dm: u8) -> T
78+
//#[rustc_legacy_const_generics(2)]
79+
pub unsafe fn vec_xxpermdi<T, const DM: i32>(a: T, b: T) -> T
8080
where
8181
T: sealed::VectorPermDI,
8282
{
83-
a.vec_xxpermdi(b, dm)
83+
static_assert_imm2!(DM);
84+
a.vec_xxpermdi(b, DM as u8)
8485
}
8586

8687
#[cfg(test)]
@@ -102,10 +103,10 @@ mod tests {
102103
let a: $longtype = mem::transmute($shorttype::new($($a),+, $($b),+));
103104
let b = mem::transmute($shorttype::new($($c),+, $($d),+));
104105

105-
assert_eq!($shorttype::new($($a),+, $($c),+), mem::transmute(vec_xxpermdi(a, b, 0)));
106-
assert_eq!($shorttype::new($($b),+, $($c),+), mem::transmute(vec_xxpermdi(a, b, 1)));
107-
assert_eq!($shorttype::new($($a),+, $($d),+), mem::transmute(vec_xxpermdi(a, b, 2)));
108-
assert_eq!($shorttype::new($($b),+, $($d),+), mem::transmute(vec_xxpermdi(a, b, 3)));
106+
assert_eq!($shorttype::new($($a),+, $($c),+), mem::transmute(vec_xxpermdi::<0>(a, b)));
107+
assert_eq!($shorttype::new($($b),+, $($c),+), mem::transmute(vec_xxpermdi::<1>(a, b)));
108+
assert_eq!($shorttype::new($($a),+, $($d),+), mem::transmute(vec_xxpermdi::<2>(a, b)));
109+
assert_eq!($shorttype::new($($b),+, $($d),+), mem::transmute(vec_xxpermdi::<3>(a, b)));
109110
}
110111
}
111112
}

crates/core_arch/src/wasm32/memory.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@ extern "C" {
1313
/// This function, when called, will return the current memory size in units of
1414
/// pages. The current WebAssembly page size is 65536 bytes (64 KB).
1515
///
16-
/// The argument `mem` is the numerical index of which memory to return the
16+
/// The argument `MEM` is the numerical index of which memory to return the
1717
/// size of. Note that currently the WebAssembly specification only supports one
1818
/// memory, so it is required that zero is passed in. The argument is present to
1919
/// be forward-compatible with future WebAssembly revisions. If a nonzero
2020
/// argument is passed to this function it will currently unconditionally abort.
2121
///
2222
/// [instr]: http://webassembly.github.io/spec/core/exec/instructions.html#exec-memory-size
2323
#[inline]
24-
#[cfg_attr(test, assert_instr("memory.size", mem = 0))]
25-
#[rustc_args_required_const(0)]
24+
#[cfg_attr(test, assert_instr("memory.size", MEM = 0))]
25+
#[rustc_legacy_const_generics(0)]
2626
#[stable(feature = "simd_wasm32", since = "1.33.0")]
27-
pub fn memory_size(mem: u32) -> usize {
27+
pub fn memory_size<const MEM: u32>() -> usize {
2828
unsafe {
29-
if mem != 0 {
29+
// FIXME: Consider replacing with a static_assert!
30+
if MEM != 0 {
3031
crate::intrinsics::abort();
3132
}
3233
llvm_memory_size(0) as usize
@@ -41,20 +42,21 @@ pub fn memory_size(mem: u32) -> usize {
4142
/// of memory, in pages, is returned. If memory cannot be grown then
4243
/// `usize::MAX` is returned.
4344
///
44-
/// The argument `mem` is the numerical index of which memory to return the
45+
/// The argument `MEM` is the numerical index of which memory to return the
4546
/// size of. Note that currently the WebAssembly specification only supports one
4647
/// memory, so it is required that zero is passed in. The argument is present to
4748
/// be forward-compatible with future WebAssembly revisions. If a nonzero
4849
/// argument is passed to this function it will currently unconditionally abort.
4950
///
5051
/// [instr]: http://webassembly.github.io/spec/core/exec/instructions.html#exec-memory-grow
5152
#[inline]
52-
#[cfg_attr(test, assert_instr("memory.grow", mem = 0))]
53-
#[rustc_args_required_const(0)]
53+
#[cfg_attr(test, assert_instr("memory.grow", MEM = 0))]
54+
#[rustc_legacy_const_generics(0)]
5455
#[stable(feature = "simd_wasm32", since = "1.33.0")]
55-
pub fn memory_grow(mem: u32, delta: usize) -> usize {
56+
pub fn memory_grow<const MEM: u32>(delta: usize) -> usize {
5657
unsafe {
57-
if mem != 0 {
58+
// FIXME: Consider replacing with a static_assert!
59+
if MEM != 0 {
5860
crate::intrinsics::abort();
5961
}
6062
llvm_memory_grow(0, delta as i32) as isize as usize

0 commit comments

Comments
 (0)