summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2006-08-22 13:51:30 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2006-08-22 13:51:30 (GMT)
commitc17ea4461717a8065cc421980f897fa30a07f8d0 (patch)
tree45679c8bdb4e4e09b3e834e8bd15799e3e69f86a
parent7a5586ca8ea00b164b4b1aaa61617fbbd9cd0f25 (diff)
downloadhdf5-c17ea4461717a8065cc421980f897fa30a07f8d0.zip
hdf5-c17ea4461717a8065cc421980f897fa30a07f8d0.tar.gz
hdf5-c17ea4461717a8065cc421980f897fa30a07f8d0.tar.bz2
[svn-r12607] Description:
Tweak the library's new faster fletcher32 algorithm to always produce the same checksum as the previous fletcher32 code in the fletcher32 I/O pipeline filter and switch the filter to use the library's version of the algorithm. Tested on: Linux/32 2.6 (chicago) Linux/64 2.6 (chicago2) Too minor to require h5committest
-rw-r--r--src/H5Zfletcher32.c69
-rw-r--r--src/H5checksum.c9
-rw-r--r--test/tchecksum.c10
3 files changed, 14 insertions, 74 deletions
diff --git a/src/H5Zfletcher32.c b/src/H5Zfletcher32.c
index 770d05a..9092452 100644
--- a/src/H5Zfletcher32.c
+++ b/src/H5Zfletcher32.c
@@ -48,71 +48,6 @@ const H5Z_class_t H5Z_FLETCHER32[1] = {{
/*-------------------------------------------------------------------------
- * Function: H5Z_filter_fletcher32_compute
- *
- * Purpose: Implement an Fletcher32 Checksum using 1's complement.
- *
- * Return: Success: Fletcher32 value
- *
- * Failure: Can't fail
- *
- * Programmer: Raymond Lu
- * Jan 3, 2003
- *
- * Modifications: Pedro Vicente, March 10, 2004
- * defined *SRC as unsigned char for all cases
- *
- *-------------------------------------------------------------------------
- */
-static uint32_t
-H5Z_filter_fletcher32_compute(void *_src, size_t len)
-{
- unsigned char *src=(unsigned char *)_src;
- size_t count = len; /* Number of bytes left to checksum */
- uint32_t s1 = 0, s2 = 0; /* Temporary partial checksums */
-
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5Z_filter_fletcher32_compute)
-
- /* Compute checksum */
- while(count > 1) {
- unsigned short tmp_src; /*To handle unusual platforms like Cray*/
-
- tmp_src = (((unsigned short)src[0])<<8) | ((unsigned short)src[1]);
- src +=2;
- s1 += tmp_src;
-
- if(s1 & 0xFFFF0000) { /*Wrap around carry if occurred*/
- s1 &= 0xFFFF;
- s1++;
- }
- s2 += s1;
- if(s2 & 0xFFFF0000) { /*Wrap around carry if occurred*/
- s2 &= 0xFFFF;
- s2++;
- }
- count -= 2;
- }
-
- /* Check for single byte remaining */
- if(count==1) {
- s1 += *(unsigned char*)src;
- if(s1 & 0xFFFF0000) { /*Wrap around carry if occurred*/
- s1 &= 0xFFFF;
- s1++;
- }
- s2 += s1;
- if(s2 & 0xFFFF0000) { /*Wrap around carry if occurred*/
- s2 &= 0xFFFF;
- s2++;
- }
- }
-
- FUNC_LEAVE_NOAPI((s2 << 16) + s1)
-}
-
-
-
-/*-------------------------------------------------------------------------
* Function: H5Z_filter_fletcher32
*
* Purpose: Implement an I/O filter of Fletcher32 Checksum
@@ -167,7 +102,7 @@ H5Z_filter_fletcher32 (unsigned flags, size_t UNUSED cd_nelmts, const unsigned U
UINT32DECODE(tmp_src, stored_fletcher);
/* Compute checksum (can't fail) */
- fletcher = H5Z_filter_fletcher32_compute(src,src_nbytes);
+ fletcher = H5_fletcher32(src, src_nbytes);
/* The reversed checksum. There was a bug in the calculating code of
* the Fletcher32 checksum in the library before v1.6.3. The checksum
@@ -201,7 +136,7 @@ H5Z_filter_fletcher32 (unsigned flags, size_t UNUSED cd_nelmts, const unsigned U
unsigned char *dst; /* Temporary pointer to destination buffer */
/* Compute checksum (can't fail) */
- fletcher = H5Z_filter_fletcher32_compute(src,nbytes);
+ fletcher = H5_fletcher32(src, nbytes);
if (NULL==(dst=outbuf=H5MM_malloc(nbytes+FLETCHER_LEN)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "unable to allocate Fletcher32 checksum destination buffer")
diff --git a/src/H5checksum.c b/src/H5checksum.c
index 3aafd3d..9ad575d 100644
--- a/src/H5checksum.c
+++ b/src/H5checksum.c
@@ -80,6 +80,11 @@
* http://en.wikipedia.org/wiki/Fletcher%27s_checksum
* for more details, etc.
*
+ * Note #2: The algorithm below differs from that given in the Wikipedia
+ * page by copying the data into 'sum1' in a more portable way
+ * and also by initializing 'sum1' and 'sum2' to 0 instead of
+ * 0xffff (for backward compatibility reasons, mostly).
+ *
* Return: 32-bit fletcher checksum of input buffer (can't fail)
*
* Programmer: Quincey Koziol
@@ -92,7 +97,7 @@ H5_fletcher32(const void *_data, size_t _len)
{
const uint8_t *data = (const uint8_t *)_data; /* Pointer to the data to be summed */
size_t len = _len / 2; /* Length in 16-bit words */
- uint32_t sum1 = 0xffff, sum2 = 0xffff;
+ uint32_t sum1 = 0, sum2 = 0;
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5_fletcher32)
@@ -128,6 +133,6 @@ H5_fletcher32(const void *_data, size_t _len)
sum1 = (sum1 & 0xffff) + (sum1 >> 16);
sum2 = (sum2 & 0xffff) + (sum2 >> 16);
- FUNC_LEAVE_NOAPI(sum2 << 16 | sum1)
+ FUNC_LEAVE_NOAPI((sum2 << 16) | sum1)
} /* end H5_fletcher32() */
diff --git a/test/tchecksum.c b/test/tchecksum.c
index ff49294..62c0505 100644
--- a/test/tchecksum.c
+++ b/test/tchecksum.c
@@ -57,7 +57,7 @@ test_chksum_size_one(void)
/* Buffer w/zero(s) for data */
HDmemset(buf, 0, sizeof(buf));
chksum = H5_fletcher32(buf, sizeof(buf));
- VERIFY(chksum, 0xffffffff, "H5_fletcher32");
+ VERIFY(chksum, 0, "H5_fletcher32");
} /* test_chksum_size_one() */
@@ -79,7 +79,7 @@ test_chksum_size_two(void)
/* Buffer w/zero(s) for data */
HDmemset(buf, 0, sizeof(buf));
chksum = H5_fletcher32(buf, sizeof(buf));
- VERIFY(chksum, 0xffffffff, "H5_fletcher32");
+ VERIFY(chksum, 0, "H5_fletcher32");
} /* test_chksum_size_two() */
@@ -101,7 +101,7 @@ test_chksum_size_three(void)
/* Buffer w/zero(s) for data */
HDmemset(buf, 0, sizeof(buf));
chksum = H5_fletcher32(buf, sizeof(buf));
- VERIFY(chksum, 0xffffffff, "H5_fletcher32");
+ VERIFY(chksum, 0, "H5_fletcher32");
} /* test_chksum_size_three() */
@@ -123,7 +123,7 @@ test_chksum_size_four(void)
/* Buffer w/zero(s) for data */
HDmemset(buf, 0, sizeof(buf));
chksum = H5_fletcher32(buf, sizeof(buf));
- VERIFY(chksum, 0xffffffff, "H5_fletcher32");
+ VERIFY(chksum, 0, "H5_fletcher32");
} /* test_chksum_size_four() */
@@ -149,7 +149,7 @@ test_chksum_large(void)
/* Buffer w/zero(s) for data */
HDmemset(large_buf, 0, sizeof(large_buf));
chksum = H5_fletcher32(large_buf, sizeof(large_buf));
- VERIFY(chksum, 0xffffffff, "H5_fletcher32");
+ VERIFY(chksum, 0, "H5_fletcher32");
} /* test_chksum_large() */