1 --- storage/innobase/ut/crc32.cc.orig	2024-04-10 06:26:28 UTC
2 +++ storage/innobase/ut/crc32.cc
3 @@ -333,8 +333,25 @@ bool can_use_poly_mul() { return true; }
4  #endif /* CRC32_ARM64_APPLE */
5 
6  #ifdef CRC32_ARM64_DEFAULT
7 +#ifdef __FreeBSD__
8 +bool can_use_crc32() {
9 +  unsigned long capabilities;
10 +
11 +  if (elf_aux_info(AT_HWCAP, &capabilities, sizeof(unsigned long)))
12 +    return false;
13 +  return capabilities & HWCAP_CRC32;
14 +}
15 +bool can_use_poly_mul() {
16 +  unsigned long capabilities;
17 +
18 +  if (elf_aux_info(AT_HWCAP, &capabilities, sizeof(unsigned long)))
19 +    return false;
20 +  return capabilities & HWCAP_PMULL;
21 +}
22 +#else
23  bool can_use_crc32() { return getauxval(AT_HWCAP) & HWCAP_CRC32; }
24  bool can_use_poly_mul() { return getauxval(AT_HWCAP) & HWCAP_PMULL; }
25 +#endif
26  #endif /* CRC32_ARM64_DEFAULT */
27 
28  /** A helper template to statically unroll a loop with a fixed number of
29 @@ -443,25 +460,39 @@ uint64_t crc32_impl::update(uint64_t crc, uint64_t dat
30 
31  #ifdef CRC32_ARM64
32  #ifdef CRC32_ARM64_DEFAULT
33 +#ifndef __clang__
34  MY_ATTRIBUTE((target("+crc")))
35 +#else
36 +MY_ATTRIBUTE((target("crc")))
37 +#endif
38  #endif /* CRC32_ARM64_DEFAULT */
39  uint32_t crc32_impl::update(uint32_t crc, unsigned char data) {
40    return __crc32cb(crc, data);
41  }
42  #ifdef CRC32_ARM64_DEFAULT
43 +#ifndef __clang__
44  MY_ATTRIBUTE((target("+crc")))
45 +#endif
46  #endif /* CRC32_ARM64_DEFAULT */
47  uint32_t crc32_impl::update(uint32_t crc, uint16_t data) {
48    return __crc32ch(crc, data);
49  }
50  #ifdef CRC32_ARM64_DEFAULT
51 +#ifndef __clang__
52  MY_ATTRIBUTE((target("+crc")))
53 +#else
54 +MY_ATTRIBUTE((target("crc")))
55 +#endif
56  #endif /* CRC32_ARM64_DEFAULT */
57  uint32_t crc32_impl::update(uint32_t crc, uint32_t data) {
58    return __crc32cw(crc, data);
59  }
60  #ifdef CRC32_ARM64_DEFAULT
61 +#ifndef __clang__
62  MY_ATTRIBUTE((target("+crc")))
63 +#else
64 +MY_ATTRIBUTE((target("crc")))
65 +#endif
66  #endif /* CRC32_ARM64_DEFAULT */
67  uint64_t crc32_impl::update(uint64_t crc, uint64_t data) {
68    return (uint64_t)__crc32cd((uint32_t)crc, data);
69 @@ -508,7 +539,11 @@ template <uint32_t w>
70  }
71  template <uint32_t w>
72  #ifdef CRC32_ARM64_DEFAULT
73 +#ifndef __clang__
74  MY_ATTRIBUTE((target("+crypto")))
75 +#else
76 +MY_ATTRIBUTE((target("crypto")))
77 +#endif
78  #endif /* CRC32_ARM64_DEFAULT */
79  uint64_t use_pclmul::polynomial_mul_rev(uint32_t rev_u) {
80    constexpr uint64_t flipped_w = flip_at_32(w);
81 @@ -751,7 +786,11 @@ MY_ATTRIBUTE((flatten))
82  MY_ATTRIBUTE((flatten))
83  #endif /* CRC32_ARM64_APPLE */
84  #ifdef CRC32_ARM64_DEFAULT
85 +#ifndef __clang__
86  MY_ATTRIBUTE((target("+crc+crypto"), flatten))
87 +#else
88 +MY_ATTRIBUTE((target("crc,crypto")))
89 +#endif
90  #endif /* CRC32_ARM64_DEFAULT */
91  uint32_t crc32_using_pclmul(const byte *data, size_t len) {
92    return crc32<use_pclmul>(0, data, len);
93 @@ -771,7 +810,11 @@ MY_ATTRIBUTE((flatten))
94  MY_ATTRIBUTE((flatten))
95  #endif /* CRC32_ARM64_APPLE */
96  #ifdef CRC32_ARM64_DEFAULT
97 +#ifndef __clang__
98  MY_ATTRIBUTE((target("+crc"), flatten))
99 +#else
100 +MY_ATTRIBUTE((target("crc")))
101 +#endif
102  #endif /* CRC32_ARM64_DEFAULT */
103  uint32_t crc32_using_unrolled_loop_poly_mul(const byte *data, size_t len) {
104    return crc32<use_unrolled_loop_poly_mul>(0, data, len);
105