File: crc32c_arm.c

package info (click to toggle)
aws-crt-python 0.20.4%2Bdfsg-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 72,656 kB
  • sloc: ansic: 381,805; python: 23,008; makefile: 6,251; sh: 4,536; cpp: 699; ruby: 208; java: 77; perl: 73; javascript: 46; xml: 11
file content (97 lines) | stat: -rw-r--r-- 2,458 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

/* No instrics defined for 32-bit MSVC */
#if (defined(_M_ARM64) || defined(__aarch64__) || defined(__arm__))
#    include <aws/checksums/private/crc_priv.h>
#    ifdef _M_ARM64
#        include <arm64_neon.h>
#        define PREFETCH(p) __prefetch(p)
#    else
#        include <arm_acle.h>
#        define PREFETCH(p) __builtin_prefetch(p)
#    endif

uint32_t aws_checksums_crc32c_hw(const uint8_t *data, int length, uint32_t previousCrc32) {
    uint32_t crc = ~previousCrc32;

    // Align data if it's not aligned
    while (((uintptr_t)data & 7) && length > 0) {
        crc = __crc32cb(crc, *(uint8_t *)data);
        data++;
        length--;
    }

    while (length >= 64) {
        PREFETCH(data + 384);
        uint64_t *d = (uint64_t *)data;
        crc = __crc32cd(crc, d[0]);
        crc = __crc32cd(crc, d[1]);
        crc = __crc32cd(crc, d[2]);
        crc = __crc32cd(crc, d[3]);
        crc = __crc32cd(crc, d[4]);
        crc = __crc32cd(crc, d[5]);
        crc = __crc32cd(crc, d[6]);
        crc = __crc32cd(crc, d[7]);
        data += 64;
        length -= 64;
    }

    while (length >= 8) {
        crc = __crc32cd(crc, *(uint64_t *)data);
        data += 8;
        length -= 8;
    }

    while (length > 0) {
        crc = __crc32cb(crc, *(uint8_t *)data);
        data++;
        length--;
    }

    return ~crc;
}

uint32_t aws_checksums_crc32_hw(const uint8_t *data, int length, uint32_t previousCrc32) {
    uint32_t crc = ~previousCrc32;

    // Align data if it's not aligned
    while (((uintptr_t)data & 7) && length > 0) {
        crc = __crc32b(crc, *(uint8_t *)data);
        data++;
        length--;
    }

    while (length >= 64) {
        PREFETCH(data + 384);
        uint64_t *d = (uint64_t *)data;
        crc = __crc32d(crc, d[0]);
        crc = __crc32d(crc, d[1]);
        crc = __crc32d(crc, d[2]);
        crc = __crc32d(crc, d[3]);
        crc = __crc32d(crc, d[4]);
        crc = __crc32d(crc, d[5]);
        crc = __crc32d(crc, d[6]);
        crc = __crc32d(crc, d[7]);
        data += 64;
        length -= 64;
    }

    while (length >= 8) {
        crc = __crc32d(crc, *(uint64_t *)data);
        data += 8;
        length -= 8;
    }

    while (length > 0) {
        crc = __crc32b(crc, *(uint8_t *)data);
        data++;
        length--;
    }

    return ~crc;
}

#endif