1 | // Licensed to the Apache Software Foundation (ASF) under one |
2 | // or more contributor license agreements. See the NOTICE file |
3 | // distributed with this work for additional information |
4 | // regarding copyright ownership. The ASF licenses this file |
5 | // to you under the Apache License, Version 2.0 (the |
6 | // "License"); you may not use this file except in compliance |
7 | // with the License. You may obtain a copy of the License at |
8 | // |
9 | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | // |
11 | // Unless required by applicable law or agreed to in writing, |
12 | // software distributed under the License is distributed on an |
13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | // KIND, either express or implied. See the License for the |
15 | // specific language governing permissions and limitations |
16 | // under the License. |
17 | |
18 | #ifndef ARROW_UTIL_NEON_UTIL_H |
19 | #define ARROW_UTIL_NEON_UTIL_H |
20 | |
21 | namespace arrow { |
22 | |
23 | #if defined(__aarch64__) || defined(__AARCH64__) |
24 | #ifdef __ARM_FEATURE_CRC32 |
25 | #define ARROW_HAVE_ARM_CRC |
26 | #include <arm_acle.h> |
27 | #endif |
28 | #endif |
29 | |
30 | #if defined(__GNUC__) && defined(__linux__) && defined(ARROW_HAVE_ARM_CRC) |
31 | |
32 | #include <asm/hwcap.h> |
33 | #include <sys/auxv.h> |
34 | #ifndef HWCAP_CRC32 |
35 | #define HWCAP_CRC32 (1 << 7) |
36 | #endif |
37 | static inline uint32_t crc32c_runtime_check(void) { |
38 | uint64_t auxv = getauxval(AT_HWCAP); |
39 | return (auxv & HWCAP_CRC32) != 0; |
40 | } |
41 | |
42 | static inline uint32_t ARMCE_crc32_u8(uint32_t crc, uint8_t v) { |
43 | return __crc32cb(crc, v); |
44 | } |
45 | |
46 | static inline uint32_t ARMCE_crc32_u16(uint32_t crc, uint16_t v) { |
47 | return __crc32ch(crc, v); |
48 | } |
49 | |
50 | static inline uint32_t ARMCE_crc32_u32(uint32_t crc, uint32_t v) { |
51 | return __crc32cw(crc, v); |
52 | } |
53 | |
54 | static inline uint32_t ARMCE_crc32_u64(uint32_t crc, uint64_t v) { |
55 | return __crc32cd(crc, v); |
56 | } |
57 | |
58 | #else |
59 | |
60 | static inline uint32_t crc32c_runtime_check(void) { |
61 | DCHECK(false) << "Arm crc32 support is not enabled" ; |
62 | return 0; |
63 | } |
64 | |
65 | static inline uint32_t ARMCE_crc32_u8(uint32_t, uint8_t) { |
66 | DCHECK(false) << "Arm crc32 support is not enabled" ; |
67 | return 0; |
68 | } |
69 | |
70 | static inline uint32_t ARMCE_crc32_u16(uint32_t, uint16_t) { |
71 | DCHECK(false) << "Arm crc32 is not enabled" ; |
72 | return 0; |
73 | } |
74 | |
75 | static inline uint32_t ARMCE_crc32_u32(uint32_t, uint32_t) { |
76 | DCHECK(false) << "Arm crc32 support is not enabled" ; |
77 | return 0; |
78 | } |
79 | |
80 | static inline uint32_t ARMCE_crc32_u64(uint32_t, uint64_t) { |
81 | DCHECK(false) << "Arm crc32 support is not enabled" ; |
82 | return 0; |
83 | } |
84 | |
85 | #endif // defined(__GNUC__) && defined(__linux__) && defined(ARROW_HAVE_ARM_CRC) |
86 | |
87 | } // namespace arrow |
88 | |
89 | #endif // ARROW_UTIL_NEON_UTIL_H |
90 | |