hash_arm_crc32.c (1887B)
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 #include "config/av1_rtcd.h" 23 24 #define CRC_LOOP(op, crc, type, buf, len) \ 25 while ((len) >= sizeof(type)) { \ 26 (crc) = op((crc), *(type *)(buf)); \ 27 (len) -= sizeof(type); \ 28 buf += sizeof(type); \ 29 } 30 31 #define CRC_SINGLE(op, crc, type, buf, len) \ 32 if ((len) >= sizeof(type)) { \ 33 (crc) = op((crc), *(type *)(buf)); \ 34 (len) -= sizeof(type); \ 35 buf += sizeof(type); \ 36 } 37 38 /* Return 32-bit CRC for the input buffer. 39 * Polynomial is 0x1EDC6F41. 40 */ 41 42 uint32_t av1_get_crc32c_value_arm_crc32(void *crc_calculator, const uint8_t *p, 43 size_t len) { 44 (void)crc_calculator; 45 const uint8_t *buf = p; 46 uint32_t crc = 0xFFFFFFFF; 47 48 #if !AOM_ARCH_AARCH64 49 // Align input to 8-byte boundary (only necessary for 32-bit builds.) 50 while (len && ((uintptr_t)buf & 7)) { 51 crc = __crc32cb(crc, *buf++); 52 len--; 53 } 54 #endif 55 56 CRC_LOOP(__crc32cd, crc, uint64_t, buf, len) 57 CRC_SINGLE(__crc32cw, crc, uint32_t, buf, len) 58 CRC_SINGLE(__crc32ch, crc, uint16_t, buf, len) 59 CRC_SINGLE(__crc32cb, crc, uint8_t, buf, len) 60 61 return ~crc; 62 }