ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/String-CRC32C/crc32csb8.c
Revision: 1.1
Committed: Mon Mar 24 11:15:00 2025 UTC (18 months, 2 weeks ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-0_01
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 // Copyright 2024 Marc A. Lehmann
2     // Copyright 2008,2009,2010 Massachusetts Institute of Technology.
3     // All rights reserved. Use of this source code is governed by a
4     // BSD-style license that can be found in the LICENSE file.
5    
6     #include "crc32ctables.c"
7    
8     // Implementations adapted from Intel's Slicing By 8 Sourceforge Project
9     // http://sourceforge.net/projects/slicing-by-8/
10     /*++
11     *
12     * Copyright (c) 2004-2006 Intel Corporation - All Rights Reserved
13     *
14     * This software program is licensed subject to the BSD License,
15     * available at http://www.opensource.org/licenses/bsd-license.html
16     *
17     * Abstract: The main routine
18     *
19     --*/
20    
21     static uint32_t crc32cSlicingBy8(uint32_t crc, const void* data, size_t length) {
22     const char* p_buf = (const char*) data;
23    
24     // Handle leading misaligned bytes
25     size_t initial_bytes = (sizeof(int32_t) - (intptr_t)p_buf) & (sizeof(int32_t) - 1);
26     if (length < initial_bytes) initial_bytes = length;
27     for (size_t li = 0; li < initial_bytes; li++) {
28     crc = crc_tableil8_o32[(crc ^ *p_buf++) & 0x000000FF] ^ (crc >> 8);
29     }
30    
31     length -= initial_bytes;
32     size_t running_length = length & ~(sizeof(uint64_t) - 1);
33     size_t end_bytes = length - running_length;
34    
35     for (size_t li = 0; li < running_length/8; li++) {
36     crc ^= *(uint32_t*) p_buf;
37     p_buf += 4;
38     uint32_t term1 = crc_tableil8_o88[crc & 0x000000FF] ^
39     crc_tableil8_o80[(crc >> 8) & 0x000000FF];
40     uint32_t term2 = crc >> 16;
41     crc = term1 ^
42     crc_tableil8_o72[term2 & 0x000000FF] ^
43     crc_tableil8_o64[(term2 >> 8) & 0x000000FF];
44     term1 = crc_tableil8_o56[(*(uint32_t *)p_buf) & 0x000000FF] ^
45     crc_tableil8_o48[((*(uint32_t *)p_buf) >> 8) & 0x000000FF];
46    
47     term2 = (*(uint32_t *)p_buf) >> 16;
48     crc = crc ^ term1 ^
49     crc_tableil8_o40[term2 & 0x000000FF] ^
50     crc_tableil8_o32[(term2 >> 8) & 0x000000FF];
51     p_buf += 4;
52     }
53    
54     for (size_t li=0; li < end_bytes; li++) {
55     crc = crc_tableil8_o32[(crc ^ *p_buf++) & 0x000000FF] ^ (crc >> 8);
56     }
57    
58     return crc;
59     }
60