]> git.proxmox.com Git - ceph.git/blob - ceph/src/isa-l/crc/crc64_base.c
update sources to v12.1.1
[ceph.git] / ceph / src / isa-l / crc / crc64_base.c
1 /**********************************************************************
2 Copyright(c) 2011-2016 Intel Corporation All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in
11 the documentation and/or other materials provided with the
12 distribution.
13 * Neither the name of Intel Corporation nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 **********************************************************************/
29
30 #include <stdlib.h>
31 #include "crc64.h"
32
33 #define MAX_ITER 8
34
35 // crc64_ecma baseline function
36 // Slow crc64 from the definition. Can be sped up with a lookup table.
37 uint64_t crc64_ecma_refl_base(uint64_t seed, const uint8_t * buf, uint64_t len)
38 {
39 uint64_t rem = ~seed;
40 unsigned int i, j;
41
42 uint64_t poly = 0xC96C5795D7870F42ULL; // ECMA-182 standard reflected
43
44 for (i = 0; i < len; i++) {
45 rem = rem ^ (uint64_t) buf[i];
46 for (j = 0; j < MAX_ITER; j++) {
47 rem = (rem & 0x1ULL ? poly : 0) ^ (rem >> 1);
48 }
49 }
50 return ~rem;
51 }
52
53 uint64_t crc64_ecma_norm_base(uint64_t seed, const uint8_t * buf, uint64_t len)
54 {
55 uint64_t rem = ~seed;
56 unsigned int i, j;
57
58 uint64_t poly = 0x42F0E1EBA9EA3693ULL; // ECMA-182 standard
59
60 for (i = 0; i < len; i++) {
61 rem = rem ^ ((uint64_t) buf[i] << 56);
62 for (j = 0; j < MAX_ITER; j++) {
63 rem = (rem & 0x8000000000000000ULL ? poly : 0) ^ (rem << 1);
64 }
65 }
66 return ~rem;
67 }
68
69 // crc64_iso baseline function
70 // Slow crc64 from the definition. Can be sped up with a lookup table.
71 uint64_t crc64_iso_refl_base(uint64_t seed, const uint8_t * buf, uint64_t len)
72 {
73 uint64_t rem = ~seed;
74 unsigned int i, j;
75
76 uint64_t poly = 0xD800000000000000ULL; // ISO standard reflected
77
78 for (i = 0; i < len; i++) {
79 rem = rem ^ (uint64_t) buf[i];
80 for (j = 0; j < MAX_ITER; j++) {
81 rem = (rem & 0x1ULL ? poly : 0) ^ (rem >> 1);
82 }
83 }
84 return ~rem;
85 }
86
87 uint64_t crc64_iso_norm_base(uint64_t seed, const uint8_t * buf, uint64_t len)
88 {
89 uint64_t rem = ~seed;
90 unsigned int i, j;
91
92 uint64_t poly = 0x000000000000001BULL; // ISO standard
93
94 for (i = 0; i < len; i++) {
95 rem = rem ^ ((uint64_t) buf[i] << 56);
96 for (j = 0; j < MAX_ITER; j++) {
97 rem = (rem & 0x8000000000000000ULL ? poly : 0) ^ (rem << 1);
98 }
99 }
100 return ~rem;
101 }
102
103 // crc64_jones baseline function
104 // Slow crc64 from the definition. Can be sped up with a lookup table.
105 uint64_t crc64_jones_refl_base(uint64_t seed, const uint8_t * buf, uint64_t len)
106 {
107 uint64_t rem = ~seed;
108 unsigned int i, j;
109
110 uint64_t poly = 0x95ac9329ac4bc9b5ULL; // Jones coefficients reflected
111
112 for (i = 0; i < len; i++) {
113 rem = rem ^ (uint64_t) buf[i];
114 for (j = 0; j < MAX_ITER; j++) {
115 rem = (rem & 0x1ULL ? poly : 0) ^ (rem >> 1);
116 }
117 }
118 return ~rem;
119 }
120
121 uint64_t crc64_jones_norm_base(uint64_t seed, const uint8_t * buf, uint64_t len)
122 {
123 uint64_t rem = ~seed;
124 unsigned int i, j;
125
126 uint64_t poly = 0xad93d23594c935a9ULL; // Jones coefficients
127
128 for (i = 0; i < len; i++) {
129 rem = rem ^ ((uint64_t) buf[i] << 56);
130 for (j = 0; j < MAX_ITER; j++) {
131 rem = (rem & 0x8000000000000000ULL ? poly : 0) ^ (rem << 1);
132 }
133 }
134 return ~rem;
135 }
136
137 struct slver {
138 unsigned short snum;
139 unsigned char ver;
140 unsigned char core;
141 };
142
143 struct slver crc64_ecma_refl_base_slver_0000001c;
144 struct slver crc64_ecma_refl_base_slver = { 0x001c, 0x00, 0x00 };
145
146 struct slver crc64_ecma_norm_base_slver_00000019;
147 struct slver crc64_ecma_norm_base_slver = { 0x0019, 0x00, 0x00 };
148
149 struct slver crc64_iso_refl_base_slver_00000022;
150 struct slver crc64_iso_refl_base_slver = { 0x0022, 0x00, 0x00 };
151
152 struct slver crc64_iso_norm_base_slver_0000001f;
153 struct slver crc64_iso_norm_base_slver = { 0x001f, 0x00, 0x00 };
154
155 struct slver crc64_jones_refl_base_slver_00000028;
156 struct slver crc64_jones_refl_base_slver = { 0x0028, 0x00, 0x00 };
157
158 struct slver crc64_jones_norm_base_slver_00000025;
159 struct slver crc64_jones_norm_base_slver = { 0x0025, 0x00, 0x00 };