MIDAS
Loading...
Searching...
No Matches
crc32c.cxx File Reference
#include "crc32c.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <pthread.h>
Include dependency graph for crc32c.cxx:

Go to the source code of this file.

Macros

#define POLY   0x82f63b78
 
#define LONG   8192
 
#define LONGx1   "8192"
 
#define LONGx2   "16384"
 
#define SHORT   256
 
#define SHORTx1   "256"
 
#define SHORTx2   "512"
 

Functions

static void crc32c_init_sw (void)
 
uint32_t crc32c_sw (uint32_t crci, const void *buf, size_t len)
 
static uint32_t gf2_matrix_times (uint32_t *mat, uint32_t vec)
 
static void gf2_matrix_square (uint32_t *square, uint32_t *mat)
 
static uint32_t crc32c_shift (uint32_t zeros[][256], uint32_t crc)
 
uint32_t crc32c (uint32_t crc, const void *buf, size_t len)
 
uint32_t crc32c_hw (uint32_t crc, const void *buf, size_t len)
 

Variables

static pthread_once_t crc32c_once_sw = PTHREAD_ONCE_INIT
 
static uint32_t crc32c_table [8][256]
 

Macro Definition Documentation

◆ LONG

#define LONG   8192

Definition at line 234 of file crc32c.cxx.

◆ LONGx1

#define LONGx1   "8192"

Definition at line 235 of file crc32c.cxx.

◆ LONGx2

#define LONGx2   "16384"

Definition at line 236 of file crc32c.cxx.

◆ POLY

#define POLY   0x82f63b78

Definition at line 66 of file crc32c.cxx.

◆ SHORT

#define SHORT   256

Definition at line 237 of file crc32c.cxx.

◆ SHORTx1

#define SHORTx1   "256"

Definition at line 238 of file crc32c.cxx.

◆ SHORTx2

#define SHORTx2   "512"

Definition at line 239 of file crc32c.cxx.

Function Documentation

◆ crc32c()

uint32_t crc32c ( uint32_t  crc,
const void *  buf,
size_t  len 
)

Definition at line 399 of file crc32c.cxx.

400{
401#if defined(HAVE_AMD64_CRC32C)
402 int sse42;
403 SSE42(sse42);
404 return sse42 ? crc32c_hw_amd64(crc, buf, len) : crc32c_sw(crc, buf, len);
405#elif defined(HAVE_ARM64_CRC32C)
406 return crc32c_hw_arm64(crc, buf, len);
407#else
408#warning Hardware accelerated CRC32C is not available.
409 return crc32c_sw(crc, buf, len);
410#endif // HAVE_AMD64_CRC32C
411}
uint32_t crc32c_sw(uint32_t crci, const void *buf, size_t len)
Definition crc32c.cxx:101
Here is the call graph for this function:
Here is the caller graph for this function:

◆ crc32c_hw()

uint32_t crc32c_hw ( uint32_t  crc,
const void *  buf,
size_t  len 
)

Definition at line 413 of file crc32c.cxx.

414{
415#if defined(HAVE_AMD64_CRC32C)
416 return crc32c_hw_amd64(crc, buf, len);
417#elif defined(HAVE_ARM64_CRC32C)
418 return crc32c_hw_arm64(crc, buf, len);
419#else
420#warning Hardware accelerated CRC32C is not available.
421 abort();
422#endif // HAVE_AMD64_CRC32C
423}

◆ crc32c_init_sw()

static void crc32c_init_sw ( void  )
static

Definition at line 73 of file crc32c.cxx.

74{
75 uint32_t n, crc, k;
76
77 for (n = 0; n < 256; n++) {
78 crc = n;
79 crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
80 crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
81 crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
82 crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
83 crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
84 crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
85 crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
86 crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
87 crc32c_table[0][n] = crc;
88 }
89 for (n = 0; n < 256; n++) {
90 crc = crc32c_table[0][n];
91 for (k = 1; k < 8; k++) {
92 crc = crc32c_table[0][crc & 0xff] ^ (crc >> 8);
93 crc32c_table[k][n] = crc;
94 }
95 }
96}
static uint32_t crc32c_table[8][256]
Definition crc32c.cxx:70
#define POLY
Definition crc32c.cxx:66
DWORD n[4]
Definition mana.cxx:247
INT k
Definition odbhist.cxx:40
Here is the caller graph for this function:

◆ crc32c_shift()

static uint32_t crc32c_shift ( uint32_t  zeros[][256],
uint32_t  crc 
)
inlinestatic

Definition at line 225 of file crc32c.cxx.

226{
227 return zeros[0][crc & 0xff] ^ zeros[1][(crc >> 8) & 0xff] ^
228 zeros[2][(crc >> 16) & 0xff] ^ zeros[3][crc >> 24];
229}

◆ crc32c_sw()

uint32_t crc32c_sw ( uint32_t  crci,
const void *  buf,
size_t  len 
)

Definition at line 101 of file crc32c.cxx.

102{
103 const unsigned char *next = (const unsigned char*)buf;
104 uint64_t crc;
105
106 //printf("crc32c_sw!\n");
107
108 pthread_once(&crc32c_once_sw, crc32c_init_sw);
109 crc = crci ^ 0xffffffff;
110 while (len && ((uintptr_t)next & 7) != 0) {
111 crc = crc32c_table[0][(crc ^ *next++) & 0xff] ^ (crc >> 8);
112 len--;
113 }
114 while (len >= 8) {
115 crc ^= *(uint64_t *)next;
116 crc = crc32c_table[7][crc & 0xff] ^
117 crc32c_table[6][(crc >> 8) & 0xff] ^
118 crc32c_table[5][(crc >> 16) & 0xff] ^
119 crc32c_table[4][(crc >> 24) & 0xff] ^
120 crc32c_table[3][(crc >> 32) & 0xff] ^
121 crc32c_table[2][(crc >> 40) & 0xff] ^
122 crc32c_table[1][(crc >> 48) & 0xff] ^
123 crc32c_table[0][crc >> 56];
124 next += 8;
125 len -= 8;
126 }
127 while (len) {
128 crc = crc32c_table[0][(crc ^ *next++) & 0xff] ^ (crc >> 8);
129 len--;
130 }
131 return (uint32_t)crc ^ 0xffffffff;
132}
static pthread_once_t crc32c_once_sw
Definition crc32c.cxx:69
static void crc32c_init_sw(void)
Definition crc32c.cxx:73
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gf2_matrix_square()

static void gf2_matrix_square ( uint32_t *  square,
uint32_t *  mat 
)
inlinestatic

Definition at line 154 of file crc32c.cxx.

155{
156 int n;
157
158 for (n = 0; n < 32; n++)
159 square[n] = gf2_matrix_times(mat, mat[n]);
160}
static uint32_t gf2_matrix_times(uint32_t *mat, uint32_t vec)
Definition crc32c.cxx:138
Here is the call graph for this function:

◆ gf2_matrix_times()

static uint32_t gf2_matrix_times ( uint32_t *  mat,
uint32_t  vec 
)
inlinestatic

Definition at line 138 of file crc32c.cxx.

139{
140 uint32_t sum;
141
142 sum = 0;
143 while (vec) {
144 if (vec & 1)
145 sum ^= *mat;
146 vec >>= 1;
147 mat++;
148 }
149 return sum;
150}
Here is the caller graph for this function:

Variable Documentation

◆ crc32c_once_sw

pthread_once_t crc32c_once_sw = PTHREAD_ONCE_INIT
static

Definition at line 69 of file crc32c.cxx.

◆ crc32c_table

uint32_t crc32c_table[8][256]
static

Definition at line 70 of file crc32c.cxx.