91 static ib_uint32_t ut_crc32_slice8_table[8][256];
92 static ibool ut_crc32_slice8_table_initialized = FALSE;
95 UNIV_INTERN
bool ut_crc32_sse2_enabled =
false;
102 ut_crc32_slice8_table_init()
106 static const ib_uint32_t poly = 0x82f63b78;
111 for (n = 0; n < 256; n++) {
113 for (k = 0; k < 8; k++) {
114 c = (c & 1) ? (poly ^ (c >> 1)) : (c >> 1);
116 ut_crc32_slice8_table[0][
n] = c;
119 for (n = 0; n < 256; n++) {
120 c = ut_crc32_slice8_table[0][
n];
121 for (k = 1; k < 8; k++) {
122 c = ut_crc32_slice8_table[0][c & 0xFF] ^ (c >> 8);
123 ut_crc32_slice8_table[k][
n] = c;
127 ut_crc32_slice8_table_initialized = TRUE;
130 #if defined(__GNUC__) && defined(__x86_64__)
140 ib_uint32_t* stepping,
141 ib_uint32_t* features_ecx,
142 ib_uint32_t* features_edx)
145 asm(
"cpuid" :
"=b" (vend[0]),
"=c" (vend[2]),
"=d" (vend[1]) :
"a" (0));
146 asm(
"cpuid" :
"=a" (sig),
"=c" (*features_ecx),
"=d" (*features_edx)
150 *model = ((sig >> 4) & 0xF);
151 *family = ((sig >> 8) & 0xF);
152 *stepping = (sig & 0xF);
154 if (memcmp(vend,
"GenuineIntel", 12) == 0
155 || (memcmp(vend,
"AuthenticAMD", 12) == 0 && *family == 0xF)) {
157 *model += (((sig >> 16) & 0xF) << 4);
158 *family += ((sig >> 20) & 0xFF);
164 #define ut_crc32_sse42_byte \
165 asm(".byte 0xf2, 0x48, 0x0f, 0x38, 0xf0, 0x0a" \
166 : "=c"(crc) : "c"(crc), "d"(buf)); \
171 #define ut_crc32_sse42_quadword \
172 asm(".byte 0xf2, 0x48, 0x0f, 0x38, 0xf1, 0x0a" \
173 : "=c"(crc) : "c"(crc), "d"(buf)); \
187 #if defined(__GNUC__) && defined(__x86_64__)
188 ib_uint64_t crc = (ib_uint32_t) (-1);
190 ut_a(ut_crc32_sse2_enabled);
192 while (len && ((ulint) buf & 7)) {
197 ut_crc32_sse42_quadword;
198 ut_crc32_sse42_quadword;
199 ut_crc32_sse42_quadword;
200 ut_crc32_sse42_quadword;
204 ut_crc32_sse42_quadword;
211 return((ib_uint32_t) ((~crc) & 0xFFFFFFFF));
215 return((ib_uint32_t) buf[len]);
219 #define ut_crc32_slice8_byte \
220 crc = (crc >> 8) ^ ut_crc32_slice8_table[0][(crc ^ *buf++) & 0xFF]; \
223 #define ut_crc32_slice8_quadword \
224 crc ^= *(ib_uint64_t*) buf; \
225 crc = ut_crc32_slice8_table[7][(crc ) & 0xFF] ^ \
226 ut_crc32_slice8_table[6][(crc >> 8) & 0xFF] ^ \
227 ut_crc32_slice8_table[5][(crc >> 16) & 0xFF] ^ \
228 ut_crc32_slice8_table[4][(crc >> 24) & 0xFF] ^ \
229 ut_crc32_slice8_table[3][(crc >> 32) & 0xFF] ^ \
230 ut_crc32_slice8_table[2][(crc >> 40) & 0xFF] ^ \
231 ut_crc32_slice8_table[1][(crc >> 48) & 0xFF] ^ \
232 ut_crc32_slice8_table[0][(crc >> 56)]; \
245 ib_uint64_t crc = (ib_uint32_t) (-1);
247 ut_a(ut_crc32_slice8_table_initialized);
249 while (len && ((ulint) buf & 7)) {
250 ut_crc32_slice8_byte;
254 ut_crc32_slice8_quadword;
255 ut_crc32_slice8_quadword;
256 ut_crc32_slice8_quadword;
257 ut_crc32_slice8_quadword;
261 ut_crc32_slice8_quadword;
265 ut_crc32_slice8_byte;
268 return((ib_uint32_t) ((~crc) & 0xFFFFFFFF));
279 #if defined(__GNUC__) && defined(__x86_64__)
283 ib_uint32_t stepping;
284 ib_uint32_t features_ecx;
285 ib_uint32_t features_edx;
287 ut_cpuid(vend, &model, &family, &stepping,
288 &features_ecx, &features_edx);
306 #ifndef UNIV_DEBUG_VALGRIND
307 ut_crc32_sse2_enabled = (features_ecx >> 20) & 1;
312 if (ut_crc32_sse2_enabled) {
315 ut_crc32_slice8_table_init();