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)
 

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 230 of file crc32c.cxx.

◆ LONGx1

#define LONGx1   "8192"

Definition at line 231 of file crc32c.cxx.

◆ LONGx2

#define LONGx2   "16384"

Definition at line 232 of file crc32c.cxx.

◆ POLY

#define POLY   0x82f63b78

Definition at line 64 of file crc32c.cxx.

◆ SHORT

#define SHORT   256

Definition at line 233 of file crc32c.cxx.

◆ SHORTx1

#define SHORTx1   "256"

Definition at line 234 of file crc32c.cxx.

◆ SHORTx2

#define SHORTx2   "512"

Definition at line 235 of file crc32c.cxx.

Function Documentation

◆ crc32c()

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

Definition at line 391 of file crc32c.cxx.

392{
393#ifdef HAVE_HWCRC32C
394 int sse42;
395
396 SSE42(sse42);
397 return sse42 ? crc32c_hw(crc, buf, len) : crc32c_sw(crc, buf, len);
398#elif defined(__ARM_FEATURE_CRC32)
399 return crc32c_arm_hw(crc, buf, len);
400#else
401#warning Hardware accelerated CRC32C is not available.
402 return crc32c_sw(crc, buf, len);
403#endif // HAVE_HWCRC32C
404}
uint32_t crc32c_sw(uint32_t crci, const void *buf, size_t len)
Definition crc32c.cxx:99
uint32_t crc32c_hw(uint32_t crc, const void *buf, size_t len)
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
Here is the call graph for this function:
Here is the caller graph for this function:

◆ crc32c_init_sw()

static void crc32c_init_sw ( void  )
static

Definition at line 71 of file crc32c.cxx.

72{
73 uint32_t n, crc, k;
74
75 for (n = 0; n < 256; n++) {
76 crc = n;
77 crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
78 crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
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 crc32c_table[0][n] = crc;
86 }
87 for (n = 0; n < 256; n++) {
88 crc = crc32c_table[0][n];
89 for (k = 1; k < 8; k++) {
90 crc = crc32c_table[0][crc & 0xff] ^ (crc >> 8);
91 crc32c_table[k][n] = crc;
92 }
93 }
94}
static uint32_t crc32c_table[8][256]
Definition crc32c.cxx:68
#define POLY
Definition crc32c.cxx:64
DWORD n[4]
Definition mana.cxx:247
INT k
Definition odbhist.cxx:40
Here is the call graph for this function:
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 221 of file crc32c.cxx.

222{
223 return zeros[0][crc & 0xff] ^ zeros[1][(crc >> 8) & 0xff] ^
224 zeros[2][(crc >> 16) & 0xff] ^ zeros[3][crc >> 24];
225}
Here is the call graph for this function:

◆ crc32c_sw()

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

Definition at line 99 of file crc32c.cxx.

100{
101 const unsigned char *next = (const unsigned char*)buf;
102 uint64_t crc;
103
105 crc = crci ^ 0xffffffff;
106 while (len && ((uintptr_t)next & 7) != 0) {
107 crc = crc32c_table[0][(crc ^ *next++) & 0xff] ^ (crc >> 8);
108 len--;
109 }
110 while (len >= 8) {
111 crc ^= *(uint64_t *)next;
112 crc = crc32c_table[7][crc & 0xff] ^
113 crc32c_table[6][(crc >> 8) & 0xff] ^
114 crc32c_table[5][(crc >> 16) & 0xff] ^
115 crc32c_table[4][(crc >> 24) & 0xff] ^
116 crc32c_table[3][(crc >> 32) & 0xff] ^
117 crc32c_table[2][(crc >> 40) & 0xff] ^
118 crc32c_table[1][(crc >> 48) & 0xff] ^
119 crc32c_table[0][crc >> 56];
120 next += 8;
121 len -= 8;
122 }
123 while (len) {
124 crc = crc32c_table[0][(crc ^ *next++) & 0xff] ^ (crc >> 8);
125 len--;
126 }
127 return (uint32_t)crc ^ 0xffffffff;
128}
static pthread_once_t crc32c_once_sw
Definition crc32c.cxx:67
static void crc32c_init_sw(void)
Definition crc32c.cxx:71
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 150 of file crc32c.cxx.

151{
152 int n;
153
154 for (n = 0; n < 32; n++)
156}
static uint32_t gf2_matrix_times(uint32_t *mat, uint32_t vec)
Definition crc32c.cxx:134
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 134 of file crc32c.cxx.

135{
136 uint32_t sum;
137
138 sum = 0;
139 while (vec) {
140 if (vec & 1)
141 sum ^= *mat;
142 vec >>= 1;
143 mat++;
144 }
145 return sum;
146}
Here is the call graph for this function:
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 67 of file crc32c.cxx.

◆ crc32c_table

uint32_t crc32c_table[8][256]
static

Definition at line 68 of file crc32c.cxx.