- Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathCRC32C.cpp
68 lines (57 loc) · 1.73 KB
/
CRC32C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* PROGRAM: Common Library
* MODULE: CRC32C.cpp
* DESCRIPTION: Hardware-accelerated hash calculation
*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
*
* Software distributed under the License is distributed AS IS,
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
* See the License for the specific language governing rights
* and limitations under the License.
*
* The Original Code was created by Dmitry Sibiryakov
* for the Firebird Open Source RDBMS project.
*
* Copyright (c) 2015 Dmitry Sibiryakov
* and all contributors signed below.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*
*/
#include"firebird.h"
// Can be used only on x86 architectures
// WARNING: With GCC must be compiled separately with -msse4.2 flag
#if defined(_M_IX86) || defined(_M_X64) || defined(__x86_64__) || defined(__i386__)
#include<nmmintrin.h>
unsignedintCRC32C(unsignedint length, constunsignedchar* value)
{
unsignedint hash_value = 0;
if (length == 1)
return_mm_crc32_u8(hash_value, *value);
if (length == 2)
return_mm_crc32_u16(hash_value, *(unsignedshort*) value);
while (length >= 4)
{
hash_value = _mm_crc32_u32(hash_value, *(unsignedint*) value);
value += 4;
length -= 4;
}
if (length >= 2)
{
hash_value = _mm_crc32_u16(hash_value, *(unsignedshort*) value);
value += 2;
length -= 2;
}
if (length)
{
hash_value = _mm_crc32_u8(hash_value, *value);
}
return hash_value;
}
#endif// architecture check