Skip to content

Commit 5ea51fc

Browse files
committed
mark crc intrinsics as safe
1 parent b68dfed commit 5ea51fc

File tree

1 file changed

+30
-26
lines changed
  • crates/core_arch/src/arm_shared

1 file changed

+30
-26
lines changed

crates/core_arch/src/arm_shared/crc.rs

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ use stdarch_test::assert_instr;
6666
not(target_arch = "arm"),
6767
stable(feature = "stdarch_aarch64_crc32", since = "1.80.0")
6868
)]
69-
pub unsafe fn __crc32b(crc: u32, data: u8) -> u32 {
70-
crc32b_(crc, data as u32)
69+
pub fn __crc32b(crc: u32, data: u8) -> u32 {
70+
unsafe { crc32b_(crc, data as u32) }
7171
}
7272

7373
/// CRC32 single round checksum for half words (16 bits).
@@ -85,8 +85,8 @@ pub unsafe fn __crc32b(crc: u32, data: u8) -> u32 {
8585
not(target_arch = "arm"),
8686
stable(feature = "stdarch_aarch64_crc32", since = "1.80.0")
8787
)]
88-
pub unsafe fn __crc32h(crc: u32, data: u16) -> u32 {
89-
crc32h_(crc, data as u32)
88+
pub fn __crc32h(crc: u32, data: u16) -> u32 {
89+
unsafe { crc32h_(crc, data as u32) }
9090
}
9191

9292
/// CRC32 single round checksum for words (32 bits).
@@ -104,8 +104,8 @@ pub unsafe fn __crc32h(crc: u32, data: u16) -> u32 {
104104
not(target_arch = "arm"),
105105
stable(feature = "stdarch_aarch64_crc32", since = "1.80.0")
106106
)]
107-
pub unsafe fn __crc32w(crc: u32, data: u32) -> u32 {
108-
crc32w_(crc, data)
107+
pub fn __crc32w(crc: u32, data: u32) -> u32 {
108+
unsafe { crc32w_(crc, data) }
109109
}
110110

111111
/// CRC32-C single round checksum for bytes (8 bits).
@@ -123,8 +123,8 @@ pub unsafe fn __crc32w(crc: u32, data: u32) -> u32 {
123123
not(target_arch = "arm"),
124124
stable(feature = "stdarch_aarch64_crc32", since = "1.80.0")
125125
)]
126-
pub unsafe fn __crc32cb(crc: u32, data: u8) -> u32 {
127-
crc32cb_(crc, data as u32)
126+
pub fn __crc32cb(crc: u32, data: u8) -> u32 {
127+
unsafe { crc32cb_(crc, data as u32) }
128128
}
129129

130130
/// CRC32-C single round checksum for half words (16 bits).
@@ -142,8 +142,8 @@ pub unsafe fn __crc32cb(crc: u32, data: u8) -> u32 {
142142
not(target_arch = "arm"),
143143
stable(feature = "stdarch_aarch64_crc32", since = "1.80.0")
144144
)]
145-
pub unsafe fn __crc32ch(crc: u32, data: u16) -> u32 {
146-
crc32ch_(crc, data as u32)
145+
pub fn __crc32ch(crc: u32, data: u16) -> u32 {
146+
unsafe { crc32ch_(crc, data as u32) }
147147
}
148148

149149
/// CRC32-C single round checksum for words (32 bits).
@@ -161,8 +161,8 @@ pub unsafe fn __crc32ch(crc: u32, data: u16) -> u32 {
161161
not(target_arch = "arm"),
162162
stable(feature = "stdarch_aarch64_crc32", since = "1.80.0")
163163
)]
164-
pub unsafe fn __crc32cw(crc: u32, data: u32) -> u32 {
165-
crc32cw_(crc, data)
164+
pub fn __crc32cw(crc: u32, data: u32) -> u32 {
165+
unsafe { crc32cw_(crc, data) }
166166
}
167167

168168
/// CRC32 single round checksum for quad words (64 bits).
@@ -173,8 +173,8 @@ pub unsafe fn __crc32cw(crc: u32, data: u32) -> u32 {
173173
#[cfg(not(target_arch = "arm"))]
174174
#[cfg_attr(test, assert_instr(crc32x))]
175175
#[stable(feature = "stdarch_aarch64_crc32", since = "1.80.0")]
176-
pub unsafe fn __crc32d(crc: u32, data: u64) -> u32 {
177-
crc32x_(crc, data)
176+
pub fn __crc32d(crc: u32, data: u64) -> u32 {
177+
unsafe { crc32x_(crc, data) }
178178
}
179179

180180
/// CRC32 single round checksum for quad words (64 bits).
@@ -185,13 +185,15 @@ pub unsafe fn __crc32d(crc: u32, data: u64) -> u32 {
185185
#[cfg(target_arch = "arm")]
186186
#[cfg_attr(test, assert_instr(crc32w))]
187187
#[unstable(feature = "stdarch_aarch32_crc32", issue = "125085")]
188-
pub unsafe fn __crc32d(crc: u32, data: u64) -> u32 {
188+
pub fn __crc32d(crc: u32, data: u64) -> u32 {
189189
// On 32-bit ARM this intrinsic emits a chain of two `crc32_w` instructions
190190
// and truncates the data to 32 bits in both clang and gcc
191-
crc32w_(
192-
crc32w_(crc, (data & 0xffffffff) as u32),
193-
(data >> 32) as u32,
194-
)
191+
unsafe {
192+
crc32w_(
193+
crc32w_(crc, (data & 0xffffffff) as u32),
194+
(data >> 32) as u32,
195+
)
196+
}
195197
}
196198

197199
/// CRC32 single round checksum for quad words (64 bits).
@@ -202,8 +204,8 @@ pub unsafe fn __crc32d(crc: u32, data: u64) -> u32 {
202204
#[cfg(not(target_arch = "arm"))]
203205
#[cfg_attr(test, assert_instr(crc32cx))]
204206
#[stable(feature = "stdarch_aarch64_crc32", since = "1.80.0")]
205-
pub unsafe fn __crc32cd(crc: u32, data: u64) -> u32 {
206-
crc32cx_(crc, data)
207+
pub fn __crc32cd(crc: u32, data: u64) -> u32 {
208+
unsafe { crc32cx_(crc, data) }
207209
}
208210

209211
/// CRC32 single round checksum for quad words (64 bits).
@@ -214,13 +216,15 @@ pub unsafe fn __crc32cd(crc: u32, data: u64) -> u32 {
214216
#[cfg(target_arch = "arm")]
215217
#[cfg_attr(test, assert_instr(crc32cw))]
216218
#[unstable(feature = "stdarch_aarch32_crc32", issue = "125085")]
217-
pub unsafe fn __crc32cd(crc: u32, data: u64) -> u32 {
219+
pub fn __crc32cd(crc: u32, data: u64) -> u32 {
218220
// On 32-bit ARM this intrinsic emits a chain of two `crc32_cw` instructions
219221
// and truncates the data to 32 bits in both clang and gcc
220-
crc32cw_(
221-
crc32cw_(crc, (data & 0xffffffff) as u32),
222-
(data >> 32) as u32,
223-
)
222+
unsafe {
223+
crc32cw_(
224+
crc32cw_(crc, (data & 0xffffffff) as u32),
225+
(data >> 32) as u32,
226+
)
227+
}
224228
}
225229

226230
#[cfg(test)]

0 commit comments

Comments
 (0)