]> git.proxmox.com Git - rustc.git/blob - src/stdarch/crates/core_arch/src/aarch64/crc.rs
New upstream version 1.46.0+dfsg1
[rustc.git] / src / stdarch / crates / core_arch / src / aarch64 / crc.rs
1 extern "C" {
2 #[link_name = "llvm.aarch64.crc32x"]
3 fn crc32x_(crc: u32, data: u64) -> u32;
4
5 #[link_name = "llvm.aarch64.crc32cx"]
6 fn crc32cx_(crc: u32, data: u64) -> u32;
7 }
8
9 #[cfg(test)]
10 use stdarch_test::assert_instr;
11
12 /// CRC32 single round checksum for quad words (64 bits).
13 #[inline]
14 #[target_feature(enable = "crc")]
15 #[cfg_attr(test, assert_instr(crc32x))]
16 pub unsafe fn __crc32d(crc: u32, data: u64) -> u32 {
17 crc32x_(crc, data)
18 }
19
20 /// CRC32-C single round checksum for quad words (64 bits).
21 #[inline]
22 #[target_feature(enable = "crc")]
23 #[cfg_attr(test, assert_instr(crc32cx))]
24 pub unsafe fn __crc32cd(crc: u32, data: u64) -> u32 {
25 crc32cx_(crc, data)
26 }
27
28 #[cfg(test)]
29 mod tests {
30 use crate::core_arch::{aarch64::*, simd::*};
31 use std::mem;
32 use stdarch_test::simd_test;
33
34 #[simd_test(enable = "crc")]
35 unsafe fn test_crc32d() {
36 assert_eq!(__crc32d(0, 0), 0);
37 assert_eq!(__crc32d(0, 18446744073709551615), 1147535477);
38 }
39
40 #[simd_test(enable = "crc")]
41 unsafe fn test_crc32cd() {
42 assert_eq!(__crc32cd(0, 0), 0);
43 assert_eq!(__crc32cd(0, 18446744073709551615), 3293575501);
44 }
45 }