CMS 3D CMS Logo

Macros | Functions | Variables
crc32c.cc File Reference
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <unistd.h>
#include <pthread.h>

Go to the source code of this file.

Macros

#define POLY   0x82f63b78
 

Functions

uint32_t crc32c (uint32_t crc, const unsigned char *buf, size_t len)
 
bool crc32c_hw_test ()
 
static void crc32c_init_sw (void)
 
static uint32_t crc32c_sw (uint32_t crci, const unsigned char *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

◆ POLY

#define POLY   0x82f63b78

Definition at line 47 of file crc32c.cc.

Referenced by crc32c_init_sw().

Function Documentation

◆ crc32c()

uint32_t crc32c ( uint32_t  crc,
const unsigned char *  buf,
size_t  len 
)

Definition at line 332 of file crc32c.cc.

References visDQMUpload::buf, and crc32c_sw().

Referenced by DataModeFRD::checksumValid(), DataModeFRDStriped::checksumValid(), FedRawDataInputSource::getNextEvent(), FRDStreamSource::setRunAndEventInfo(), FRDOutputModule::write(), and RawEventOutputModuleForBU< Consumer >::write().

332  {
333 #if defined(__x86_64__)
334  int sse42;
335 
336  SSE42(sse42);
337  return sse42 ? crc32c_hw(crc, buf, len) : crc32c_sw(crc, buf, len);
338 #else
339  return crc32c_sw(crc, buf, len);
340 #endif
341 }
static uint32_t crc32c_sw(uint32_t crci, const unsigned char *buf, size_t len)
Definition: crc32c.cc:81

◆ crc32c_hw_test()

bool crc32c_hw_test ( )

Definition at line 343 of file crc32c.cc.

Referenced by DAQSource::DAQSource(), and FedRawDataInputSource::FedRawDataInputSource().

343  {
344 #if defined(__x86_64__)
345  int sse42;
346 
347  SSE42(sse42);
348  return sse42;
349 #else
350  return 0;
351 #endif
352 }

◆ crc32c_init_sw()

static void crc32c_init_sw ( void  )
static

Definition at line 54 of file crc32c.cc.

References crc32c_table, isotrackApplyRegressor::k, create_idmaps::n, and POLY.

Referenced by crc32c_sw().

54  {
55  uint32_t n, crc, k;
56 
57  for (n = 0; n < 256; n++) {
58  crc = n;
59  crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
60  crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
61  crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
62  crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
63  crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
64  crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
65  crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
66  crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
67  crc32c_table[0][n] = crc;
68  }
69  for (n = 0; n < 256; n++) {
70  crc = crc32c_table[0][n];
71  for (k = 1; k < 8; k++) {
72  crc = crc32c_table[0][crc & 0xff] ^ (crc >> 8);
73  crc32c_table[k][n] = crc;
74  }
75  }
76 }
static uint32_t crc32c_table[8][256]
Definition: crc32c.cc:51
#define POLY
Definition: crc32c.cc:47

◆ crc32c_sw()

static uint32_t crc32c_sw ( uint32_t  crci,
const unsigned char *  buf,
size_t  len 
)
static

Definition at line 81 of file crc32c.cc.

References visDQMUpload::buf, crc32c_init_sw(), crc32c_once_sw, crc32c_table, and GetRecoTauVFromDQM_MC_cff::next.

Referenced by crc32c().

81  {
82  const unsigned char *next = buf;
83  uint64_t crc;
84 
85  pthread_once(&crc32c_once_sw, crc32c_init_sw);
86  crc = crci ^ 0xffffffff;
87  while (len && ((const uintptr_t)next & 7) != 0) {
88  crc = crc32c_table[0][(crc ^ *next++) & 0xff] ^ (crc >> 8);
89  len--;
90  }
91  while (len >= 8) {
92  crc ^= *(uint64_t *)next;
93  crc = crc32c_table[7][crc & 0xff] ^ crc32c_table[6][(crc >> 8) & 0xff] ^ crc32c_table[5][(crc >> 16) & 0xff] ^
94  crc32c_table[4][(crc >> 24) & 0xff] ^ crc32c_table[3][(crc >> 32) & 0xff] ^
95  crc32c_table[2][(crc >> 40) & 0xff] ^ crc32c_table[1][(crc >> 48) & 0xff] ^ crc32c_table[0][crc >> 56];
96  next += 8;
97  len -= 8;
98  }
99  while (len) {
100  crc = crc32c_table[0][(crc ^ *next++) & 0xff] ^ (crc >> 8);
101  len--;
102  }
103  return (uint32_t)crc ^ 0xffffffff;
104 }
static pthread_once_t crc32c_once_sw
Definition: crc32c.cc:50
static uint32_t crc32c_table[8][256]
Definition: crc32c.cc:51
unsigned long long uint64_t
Definition: Time.h:13
static void crc32c_init_sw(void)
Definition: crc32c.cc:54

Variable Documentation

◆ crc32c_once_sw

pthread_once_t crc32c_once_sw = PTHREAD_ONCE_INIT
static

Definition at line 50 of file crc32c.cc.

Referenced by crc32c_sw().

◆ crc32c_table

uint32_t crc32c_table[8][256]
static

Definition at line 51 of file crc32c.cc.

Referenced by crc32c_init_sw(), and crc32c_sw().