/src/aom/av1/encoder/x86/hash_sse42.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2018, 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 <nmmintrin.h> |
14 | | |
15 | | #include "config/aom_config.h" |
16 | | #include "config/av1_rtcd.h" |
17 | | |
18 | | // Byte-boundary alignment issues |
19 | 0 | #define ALIGN_SIZE 8 |
20 | 0 | #define ALIGN_MASK (ALIGN_SIZE - 1) |
21 | | |
22 | | #define CALC_CRC(op, crc, type, buf, len) \ |
23 | 0 | while ((len) >= sizeof(type)) { \ |
24 | 0 | (crc) = op((crc), *(type *)(buf)); \ |
25 | 0 | (len) -= sizeof(type); \ |
26 | 0 | buf += sizeof(type); \ |
27 | 0 | } |
28 | | |
29 | | /** |
30 | | * Calculates 32-bit CRC for the input buffer |
31 | | * polynomial is 0x11EDC6F41 |
32 | | * @return A 32-bit unsigned integer representing the CRC |
33 | | */ |
34 | | uint32_t av1_get_crc32c_value_sse4_2(void *crc_calculator, const uint8_t *p, |
35 | 0 | size_t len) { |
36 | 0 | (void)crc_calculator; |
37 | 0 | const uint8_t *buf = p; |
38 | 0 | uint32_t crc = 0xFFFFFFFF; |
39 | | |
40 | | // Align the input to the word boundary |
41 | 0 | for (; (len > 0) && ((intptr_t)buf & ALIGN_MASK); len--, buf++) { |
42 | 0 | crc = _mm_crc32_u8(crc, *buf); |
43 | 0 | } |
44 | |
|
45 | 0 | #ifdef __x86_64__ |
46 | 0 | uint64_t crc64 = crc; |
47 | 0 | CALC_CRC(_mm_crc32_u64, crc64, uint64_t, buf, len) |
48 | 0 | crc = (uint32_t)crc64; |
49 | 0 | #endif |
50 | 0 | CALC_CRC(_mm_crc32_u32, crc, uint32_t, buf, len) |
51 | 0 | CALC_CRC(_mm_crc32_u16, crc, uint16_t, buf, len) |
52 | 0 | CALC_CRC(_mm_crc32_u8, crc, uint8_t, buf, len) |
53 | 0 | return (crc ^ 0xFFFFFFFF); |
54 | 0 | } |
55 | | |
56 | | void av1_combine_block_hashes_sse4_2(void *crc_calculator, const uint32_t *top, |
57 | | const uint32_t *bottom, uint32_t *dst, |
58 | 0 | int width, int sub_size) { |
59 | 0 | (void)crc_calculator; |
60 | 0 | for (int x = 0; x < width; x++) { |
61 | | // Hash the 4 values from registers, in the same byte order as the C |
62 | | // version reads them from memory. |
63 | 0 | #if AOM_ARCH_X86_64 |
64 | 0 | uint64_t crc = 0xFFFFFFFF; |
65 | 0 | crc = _mm_crc32_u64(crc, top[x] | (uint64_t)top[x + sub_size] << 32); |
66 | 0 | crc = _mm_crc32_u64(crc, bottom[x] | (uint64_t)bottom[x + sub_size] << 32); |
67 | 0 | dst[x] = (uint32_t)crc ^ 0xFFFFFFFF; |
68 | | #else |
69 | | uint32_t crc = 0xFFFFFFFF; |
70 | | crc = _mm_crc32_u32(crc, top[x]); |
71 | | crc = _mm_crc32_u32(crc, top[x + sub_size]); |
72 | | crc = _mm_crc32_u32(crc, bottom[x]); |
73 | | crc = _mm_crc32_u32(crc, bottom[x + sub_size]); |
74 | | dst[x] = crc ^ 0xFFFFFFFF; |
75 | | #endif |
76 | 0 | } |
77 | 0 | } |