Skip to content

Commit 0e28821

Browse files
committed
Add a crc32_combine function
1 parent 37059ee commit 0e28821

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/isal/crc32_combine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static inline crc_t multmodp(crc_t a, crc_t b) {
5858
}
5959

6060
// Table of x^2^n modulo p(x).
61-
static inline const crc_t x2n_table[] = {
61+
static const crc_t x2n_table[] = {
6262
0x40000000, 0x20000000, 0x08000000, 0x00800000, 0x00008000,
6363
0xedb88320, 0xb1e6b092, 0xa06a2517, 0xed627dae, 0x88d14467,
6464
0xd7bbfe6a, 0xec447f11, 0x8e7ea170, 0x6427800e, 0x4d47bae0,

src/isal/isal_zlib.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ IsalError: Exception
3636

3737
def adler32(__data, __value: int = 1) -> int: ...
3838
def crc32(__data, __value: int = 0) -> int: ...
39+
def crc32_combine(__crc1: int, __crc2: int, __crc2_length: int) -> int: ...
3940

4041
def compress(__data,
4142
level: int = ISAL_DEFAULT_COMPRESSION,

src/isal/isal_zlibmodule.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Changes compared to CPython:
2727
#include "isal_shared.h"
2828

2929
#include <isa-l/crc.h>
30+
#include "crc32_combine.h"
3031

3132
#define Z_DEFAULT_STRATEGY 0
3233
#define Z_FILTERED 1
@@ -1187,6 +1188,39 @@ isal_zlib_Decompress_flush(decompobject *self, PyObject *const *args, Py_ssize_t
11871188
return isal_zlib_Decompress_flush_impl(self, length);
11881189
}
11891190

1191+
PyDoc_STRVAR(isal_zlib_crc32_combine__doc__,
1192+
"crc32_combine($module, crc1, crc2, crc2_length /)\n"
1193+
"--\n"
1194+
"\n"
1195+
"Combine crc1 and crc2 into a new crc that is accurate for the combined data \n"
1196+
"blocks that crc1 and crc2 where calculated from.\n"
1197+
"\n"
1198+
" crc1\n"
1199+
" the first crc32 checksum\n"
1200+
" crc2\n"
1201+
" the second crc32 checksum\n"
1202+
" crc2_length\n"
1203+
" the lenght of the data block crc2 was calculated from\n"
1204+
);
1205+
1206+
1207+
#define ISAL_ZLIB_CRC32_COMBINE_METHODDEF \
1208+
{"crc32_combine", (PyCFunction)(void(*)(void))isal_zlib_crc32_combine, \
1209+
METH_VARARGS, isal_zlib_crc32_combine__doc__}
1210+
1211+
static PyObject *
1212+
isal_zlib_crc32_combine(PyObject *module, PyObject *args) {
1213+
uint32_t crc1 = 0;
1214+
uint32_t crc2 = 0;
1215+
Py_ssize_t crc2_length = 0;
1216+
static char *format = "IIn:crc32combine";
1217+
if (PyArg_ParseTuple(args, format, &crc1, &crc2, &crc2_length) < 0) {
1218+
return NULL;
1219+
}
1220+
return PyLong_FromUnsignedLong(
1221+
crc32_comb(crc1, crc2, crc2_length) & 0xFFFFFFFF);
1222+
}
1223+
11901224

11911225
typedef struct {
11921226
PyTypeObject *Comptype;
@@ -1197,6 +1231,7 @@ typedef struct {
11971231
static PyMethodDef IsalZlibMethods[] = {
11981232
ISAL_ZLIB_ADLER32_METHODDEF,
11991233
ISAL_ZLIB_CRC32_METHODDEF,
1234+
ISAL_ZLIB_CRC32_COMBINE_METHODDEF,
12001235
ISAL_ZLIB_COMPRESS_METHODDEF,
12011236
ISAL_ZLIB_DECOMPRESS_METHODDEF,
12021237
ISAL_ZLIB_COMPRESSOBJ_METHODDEF,

0 commit comments

Comments
 (0)