• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022, Alliance for Open Media. All rights reserved
3  *
4  * This source code is subject to the terms of the BSD 2 Clause License and
5  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6  * was not distributed with this source code in the LICENSE file, you can
7  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8  * Media Patent License 1.0 was not distributed with this source code in the
9  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10  */
11 
12 #if defined(_MSC_VER) && !defined(__clang__)
13 #include <intrin.h>
14 #else
15 #include <arm_acle.h>
16 #endif
17 
18 #include <stddef.h>
19 #include <stdint.h>
20 
21 #include "config/aom_config.h"
22 
23 #define CRC_LOOP(op, crc, type, buf, len) \
24   while ((len) >= sizeof(type)) {         \
25     (crc) = op((crc), *(type *)(buf));    \
26     (len) -= sizeof(type);                \
27     buf += sizeof(type);                  \
28   }
29 
30 #define CRC_SINGLE(op, crc, type, buf, len) \
31   if ((len) >= sizeof(type)) {              \
32     (crc) = op((crc), *(type *)(buf));      \
33     (len) -= sizeof(type);                  \
34     buf += sizeof(type);                    \
35   }
36 
37 /* Return 32-bit CRC for the input buffer.
38  * Polynomial is 0x1EDC6F41.
39  */
40 
av1_get_crc32c_value_arm_crc32(void * crc_calculator,uint8_t * p,size_t len)41 uint32_t av1_get_crc32c_value_arm_crc32(void *crc_calculator, uint8_t *p,
42                                         size_t len) {
43   (void)crc_calculator;
44   const uint8_t *buf = p;
45   uint32_t crc = 0xFFFFFFFF;
46 
47 #if !AOM_ARCH_AARCH64
48   // Align input to 8-byte boundary (only necessary for 32-bit builds.)
49   while (len && ((uintptr_t)buf & 7)) {
50     crc = __crc32cb(crc, *buf++);
51     len--;
52   }
53 #endif
54 
55   CRC_LOOP(__crc32cd, crc, uint64_t, buf, len)
56   CRC_SINGLE(__crc32cw, crc, uint32_t, buf, len)
57   CRC_SINGLE(__crc32ch, crc, uint16_t, buf, len)
58   CRC_SINGLE(__crc32cb, crc, uint8_t, buf, len)
59 
60   return ~crc;
61 }
62