Skip to content

Commit 1e2ebeb

Browse files
folkertdevtgross35
authored andcommitted
use is_multiple_of to check if an addr is aligned
1 parent 7c46e92 commit 1e2ebeb

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

compiler-builtins/src/arm.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ intrinsics! {
135135
/// eight bytes.
136136
#[cfg(not(target_vendor = "apple"))]
137137
pub unsafe extern "aapcs" fn __aeabi_memcpy8(dst: *mut u8, src: *const u8, n: usize) {
138-
debug_assert!(dst.addr() & 7 == 0);
139-
debug_assert!(src.addr() & 7 == 0);
138+
debug_assert!(dst.addr().is_multiple_of(8));
139+
debug_assert!(src.addr().is_multiple_of(8));
140140

141141
// SAFETY: memcpy preconditions apply, less strict alignment.
142142
unsafe { __aeabi_memcpy4(dst, src, n) };
@@ -161,8 +161,8 @@ intrinsics! {
161161
/// four bytes.
162162
#[cfg(not(any(target_vendor = "apple", target_env = "msvc")))]
163163
pub unsafe extern "aapcs" fn __aeabi_memmove4(dst: *mut u8, src: *const u8, n: usize) {
164-
debug_assert!(dst.addr() & 3 == 0);
165-
debug_assert!(src.addr() & 3 == 0);
164+
debug_assert!(dst.addr().is_multiple_of(4));
165+
debug_assert!(src.addr().is_multiple_of(4));
166166

167167
// SAFETY: same preconditions, less strict aligment.
168168
unsafe { __aeabi_memmove(dst, src, n) };
@@ -176,8 +176,8 @@ intrinsics! {
176176
/// eight bytes.
177177
#[cfg(not(any(target_vendor = "apple", target_env = "msvc")))]
178178
pub unsafe extern "aapcs" fn __aeabi_memmove8(dst: *mut u8, src: *const u8, n: usize) {
179-
debug_assert!(dst.addr() & 7 == 0);
180-
debug_assert!(src.addr() & 7 == 0);
179+
debug_assert!(dst.addr().is_multiple_of(8));
180+
debug_assert!(src.addr().is_multiple_of(8));
181181

182182
// SAFETY: memmove preconditions apply, less strict alignment.
183183
unsafe { __aeabi_memmove(dst, src, n) };
@@ -236,7 +236,7 @@ intrinsics! {
236236
/// eight bytes.
237237
#[cfg(not(target_vendor = "apple"))]
238238
pub unsafe extern "aapcs" fn __aeabi_memset8(dst: *mut u8, n: usize, c: i32) {
239-
debug_assert!(dst.addr() & 7 == 0);
239+
debug_assert!(dst.addr().is_multiple_of(8));
240240

241241
// SAFETY: memset preconditions apply, less strict alignment.
242242
unsafe { __aeabi_memset4(dst, n, c) };
@@ -261,7 +261,7 @@ intrinsics! {
261261
/// four bytes.
262262
#[cfg(not(any(target_vendor = "apple", target_env = "msvc")))]
263263
pub unsafe extern "aapcs" fn __aeabi_memclr4(dst: *mut u8, n: usize) {
264-
debug_assert!(dst.addr() & 3 == 0);
264+
debug_assert!(dst.addr().is_multiple_of(4));
265265

266266
// SAFETY: memclr preconditions apply, less strict alignment.
267267
unsafe { __aeabi_memset4(dst, n, 0) };
@@ -275,7 +275,7 @@ intrinsics! {
275275
/// eight bytes.
276276
#[cfg(not(any(target_vendor = "apple", target_env = "msvc")))]
277277
pub unsafe extern "aapcs" fn __aeabi_memclr8(dst: *mut u8, n: usize) {
278-
debug_assert!(dst.addr() & 7 == 0);
278+
debug_assert!(dst.addr().is_multiple_of(8));
279279

280280
// SAFETY: memclr preconditions apply, less strict alignment.
281281
unsafe { __aeabi_memset4(dst, n, 0) };

0 commit comments

Comments
 (0)