提交 0adfe3dc 编写于 作者: S Shengliang Guan

crc32

上级 9df1fed6
......@@ -13,24 +13,23 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_UTIL_CHECKSUM_H
#define _TD_UTIL_CHECKSUM_H
#ifndef _TD_UTIL_CHECKSUM_H_
#define _TD_UTIL_CHECKSUM_H_
#include "tcrc32c.h"
#include "tutil.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "os.h"
#include "tcrc32c.h"
#include "tutil.h"
typedef uint32_t TSCKSUM;
static FORCE_INLINE TSCKSUM taosCalcChecksum(TSCKSUM csi, const uint8_t *stream, uint32_t ssize) {
return (*crc32c)(csi, stream, (size_t)ssize);
}
static FORCE_INLINE int taosCalcChecksumAppend(TSCKSUM csi, uint8_t *stream, uint32_t ssize) {
static FORCE_INLINE int32_t taosCalcChecksumAppend(TSCKSUM csi, uint8_t *stream, uint32_t ssize) {
if (ssize < sizeof(TSCKSUM)) return -1;
*((TSCKSUM *)(stream + ssize - sizeof(TSCKSUM))) = (*crc32c)(csi, stream, (size_t)(ssize - sizeof(TSCKSUM)));
......@@ -38,11 +37,11 @@ static FORCE_INLINE int taosCalcChecksumAppend(TSCKSUM csi, uint8_t *stream, uin
return 0;
}
static FORCE_INLINE int taosCheckChecksum(const uint8_t *stream, uint32_t ssize, TSCKSUM checksum) {
static FORCE_INLINE int32_t taosCheckChecksum(const uint8_t *stream, uint32_t ssize, TSCKSUM checksum) {
return (checksum != (*crc32c)(0, stream, (size_t)ssize));
}
static FORCE_INLINE int taosCheckChecksumWhole(const uint8_t *stream, uint32_t ssize) {
static FORCE_INLINE int32_t taosCheckChecksumWhole(const uint8_t *stream, uint32_t ssize) {
if (ssize < sizeof(TSCKSUM)) return 0;
#if (_WIN64)
......@@ -56,4 +55,4 @@ static FORCE_INLINE int taosCheckChecksumWhole(const uint8_t *stream, uint32_t s
}
#endif
#endif /*_TD_UTIL_CHECKSUM_H*/
#endif /*_TD_UTIL_CHECKSUM_H_*/
......@@ -18,8 +18,10 @@
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef _TD_UTIL_CRC32_H
#define _TD_UTIL_CRC32_H
#ifndef _TD_UTIL_CRC32_H_
#define _TD_UTIL_CRC32_H_
#include "os.h"
#ifdef __cplusplus
extern "C" {
......@@ -39,4 +41,4 @@ void taosResolveCRC();
}
#endif
#endif /*_TD_UTIL_CRC32_H*/
#endif /*_TD_UTIL_CRC32_H_*/
......@@ -18,7 +18,7 @@
3. This notice may not be removed or altered from any source distribution.
*/
#include "os.h"
#define _DEFAULT_SOURCE
#include "tcrc32c.h"
#include "tdef.h"
......@@ -26,8 +26,6 @@
#include <nmmintrin.h>
#endif
#define POLY 0x82f63b78
#define LONG_SHIFT 8192
#define SHORT_SHIFT 256
......@@ -1097,7 +1095,7 @@ static uint32_t short_shifts[4][256] = {
static uint32_t append_trivial(uint32_t crc, crc_stream input, size_t length) {
for (size_t i = 0; i < length; ++i) {
crc = crc ^ input[i];
for (int j = 0; j < 8; j++)
for (int32_t j = 0; j < 8; j++)
crc = (crc >> 1) ^ 0x80000000 ^ ((~crc & 1) * POLY);
}
return crc;
......@@ -1358,7 +1356,7 @@ void taosResolveCRC() {
#if defined _TD_ARM_ || defined _TD_MIPS_ || defined WINDOWS
crc32c = crc32c_sf;
#else
int sse42;
int32_t sse42;
SSE42(sse42);
crc32c = sse42 ? crc32c_hw : crc32c_sf;
#endif
......@@ -1371,10 +1369,10 @@ void taosResolveCRC() {
#include <string.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
int32_t main(int32_t argc, char *argv[]) {
char str[1024] = "\0";
char *ptr = str;
int count = 0;
int32_t count = 0;
while ((count = read(0, ptr, 10)) > 0) {
ptr += count;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册