Coverage Report

Created: 2024-07-27 06:17

/src/lzma-fuzz/sdk/C/XzCrc64.c
Line
Count
Source (jump to first uncovered line)
1
/* XzCrc64.c -- CRC64 calculation
2
2017-05-23 : Igor Pavlov : Public domain */
3
4
#include "Precomp.h"
5
6
#include "XzCrc64.h"
7
#include "CpuArch.h"
8
9
15.9M
#define kCrc64Poly UINT64_CONST(0xC96C5795D7870F42)
10
11
#ifdef MY_CPU_LE
12
5.98M
  #define CRC64_NUM_TABLES 4
13
#else
14
  #define CRC64_NUM_TABLES 5
15
  #define CRC_UINT64_SWAP(v) \
16
      ((v >> 56) \
17
    | ((v >> 40) & ((UInt64)0xFF <<  8)) \
18
    | ((v >> 24) & ((UInt64)0xFF << 16)) \
19
    | ((v >>  8) & ((UInt64)0xFF << 24)) \
20
    | ((v <<  8) & ((UInt64)0xFF << 32)) \
21
    | ((v << 24) & ((UInt64)0xFF << 40)) \
22
    | ((v << 40) & ((UInt64)0xFF << 48)) \
23
    | ((v << 56)))
24
25
  UInt64 MY_FAST_CALL XzCrc64UpdateT1_BeT4(UInt64 v, const void *data, size_t size, const UInt64 *table);
26
#endif
27
28
#ifndef MY_CPU_BE
29
  UInt64 MY_FAST_CALL XzCrc64UpdateT4(UInt64 v, const void *data, size_t size, const UInt64 *table);
30
#endif
31
32
typedef UInt64 (MY_FAST_CALL *CRC64_FUNC)(UInt64 v, const void *data, size_t size, const UInt64 *table);
33
34
static CRC64_FUNC g_Crc64Update;
35
UInt64 g_Crc64Table[256 * CRC64_NUM_TABLES];
36
37
UInt64 MY_FAST_CALL Crc64Update(UInt64 v, const void *data, size_t size)
38
1.49k
{
39
1.49k
  return g_Crc64Update(v, data, size, g_Crc64Table);
40
1.49k
}
41
42
UInt64 MY_FAST_CALL Crc64Calc(const void *data, size_t size)
43
0
{
44
0
  return g_Crc64Update(CRC64_INIT_VAL, data, size, g_Crc64Table) ^ CRC64_INIT_VAL;
45
0
}
46
47
void MY_FAST_CALL Crc64GenerateTable()
48
7.77k
{
49
7.77k
  UInt32 i;
50
1.99M
  for (i = 0; i < 256; i++)
51
1.99M
  {
52
1.99M
    UInt64 r = i;
53
1.99M
    unsigned j;
54
17.9M
    for (j = 0; j < 8; j++)
55
15.9M
      r = (r >> 1) ^ (kCrc64Poly & ((UInt64)0 - (r & 1)));
56
1.99M
    g_Crc64Table[i] = r;
57
1.99M
  }
58
5.98M
  for (i = 256; i < 256 * CRC64_NUM_TABLES; i++)
59
5.97M
  {
60
5.97M
    UInt64 r = g_Crc64Table[(size_t)i - 256];
61
5.97M
    g_Crc64Table[i] = g_Crc64Table[r & 0xFF] ^ (r >> 8);
62
5.97M
  }
63
  
64
7.77k
  #ifdef MY_CPU_LE
65
66
7.77k
  g_Crc64Update = XzCrc64UpdateT4;
67
68
  #else
69
  {
70
    #ifndef MY_CPU_BE
71
    UInt32 k = 1;
72
    if (*(const Byte *)&k == 1)
73
      g_Crc64Update = XzCrc64UpdateT4;
74
    else
75
    #endif
76
    {
77
      for (i = 256 * CRC64_NUM_TABLES - 1; i >= 256; i--)
78
      {
79
        UInt64 x = g_Crc64Table[(size_t)i - 256];
80
        g_Crc64Table[i] = CRC_UINT64_SWAP(x);
81
      }
82
      g_Crc64Update = XzCrc64UpdateT1_BeT4;
83
    }
84
  }
85
  #endif
86
7.77k
}