• 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 #include <stdint.h>
13 #include <stddef.h>
14 #include <arm_acle.h>
15 
16 #define CRC_LOOP(op, crc, type, buf, len) \
17   while ((len) >= sizeof(type)) {         \
18     (crc) = op((crc), *(type *)(buf));    \
19     (len) -= sizeof(type);                \
20     buf += sizeof(type);                  \
21   }
22 
23 #define CRC_SINGLE(op, crc, type, buf, len) \
24   if ((len) >= sizeof(type)) {              \
25     (crc) = op((crc), *(type *)(buf));      \
26     (len) -= sizeof(type);                  \
27     buf += sizeof(type);                    \
28   }
29 
30 /* Return 32-bit CRC for the input buffer.
31  * Polynomial is 0x1EDC6F41.
32  */
33 
av1_get_crc32c_value_arm_crc32(void * crc_calculator,uint8_t * p,size_t len)34 uint32_t av1_get_crc32c_value_arm_crc32(void *crc_calculator, uint8_t *p,
35                                         size_t len) {
36   (void)crc_calculator;
37   const uint8_t *buf = p;
38   uint32_t crc = 0xFFFFFFFF;
39 
40 #if !defined(__aarch64__)
41   // Align input to 8-byte boundary (only necessary for 32-bit builds.)
42   while (len && ((uintptr_t)buf & 7)) {
43     crc = __crc32cb(crc, *buf++);
44     len--;
45   }
46 #endif
47 
48   CRC_LOOP(__crc32cd, crc, uint64_t, buf, len)
49   CRC_SINGLE(__crc32cw, crc, uint32_t, buf, len)
50   CRC_SINGLE(__crc32ch, crc, uint16_t, buf, len)
51   CRC_SINGLE(__crc32cb, crc, uint8_t, buf, len)
52 
53   return ~crc;
54 }
55