Fix copyright lines
[folly.git] / folly / hash / detail / ChecksumDetail.h
1 /*
2  * Copyright 2013-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #pragma once
18
19 #include <folly/Portability.h>
20
21 #if FOLLY_SSE_PREREQ(4, 2)
22 #include <immintrin.h>
23 #endif
24
25 #include <stdint.h>
26 #include <cstddef>
27
28 namespace folly { namespace detail {
29
30 /**
31  * Compute a CRC-32C checksum of a buffer using a hardware-accelerated
32  * implementation.
33  *
34  * @note This function is exposed to support special cases where the
35  *       calling code is absolutely certain it ought to invoke a hardware-
36  *       accelerated CRC-32C implementation - unit tests, for example.  For
37  *       all other scenarios, please call crc32c() and let it pick an
38  *       implementation based on the capabilities of the underlying CPU.
39  */
40 uint32_t crc32c_hw(const uint8_t* data, size_t nbytes,
41     uint32_t startingChecksum = ~0U);
42
43 /**
44  * Check whether a hardware-accelerated CRC-32C implementation is
45  * supported on the current CPU.
46  */
47 bool crc32c_hw_supported();
48
49 /**
50  * Compute a CRC-32C checksum of a buffer using a portable,
51  * software-only implementation.
52  *
53  * @note This function is exposed to support special cases where the
54  *       calling code is absolutely certain it wants to use the software
55  *       implementation instead of the hardware-accelerated code - unit
56  *       tests, for example.  For all other scenarios, please call crc32c()
57  *       and let it pick an implementation based on the capabilities of
58  *       the underlying CPU.
59  */
60 uint32_t crc32c_sw(const uint8_t* data, size_t nbytes,
61     uint32_t startingChecksum = ~0U);
62
63 /**
64  * Compute a CRC-32 checksum of a buffer using a hardware-accelerated
65  * implementation.
66  *
67  * @note This function is exposed to support special cases where the
68  *       calling code is absolutely certain it ought to invoke a hardware-
69  *       accelerated CRC-32 implementation - unit tests, for example.  For
70  *       all other scenarios, please call crc32() and let it pick an
71  *       implementation based on the capabilities of the underlying CPU.
72  */
73 uint32_t
74 crc32_hw(const uint8_t* data, size_t nbytes, uint32_t startingChecksum = ~0U);
75
76 #if FOLLY_SSE_PREREQ(4, 2)
77 uint32_t
78 crc32_hw_aligned(uint32_t remainder, const __m128i* p, size_t vec_count);
79 #endif
80
81 /**
82  * Check whether a hardware-accelerated CRC-32 implementation is
83  * supported on the current CPU.
84  */
85 bool crc32_hw_supported();
86
87 /**
88  * Compute a CRC-32 checksum of a buffer using a portable,
89  * software-only implementation.
90  *
91  * @note This function is exposed to support special cases where the
92  *       calling code is absolutely certain it wants to use the software
93  *       implementation instead of the hardware-accelerated code - unit
94  *       tests, for example.  For all other scenarios, please call crc32()
95  *       and let it pick an implementation based on the capabilities of
96  *       the underlying CPU.
97  */
98 uint32_t
99 crc32_sw(const uint8_t* data, size_t nbytes, uint32_t startingChecksum = ~0U);
100 } // namespace detail
101 } // namespace folly