SABER
tools_func.c
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2017 UCAR
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  */
7 
8 #include <stdint.h>
9 #include <stdio.h>
10 #include <unistd.h>
11 
12 uint32_t fletcher32(uint32_t *n, uint16_t const *var)
13 {
14  uint32_t sum1 = 0xffff, sum2 = 0xffff;
15  size_t tlen; uint32_t words = *n;
16  while (words) {
17  tlen = ((words >= 359) ? 359 : words);
18  words -= tlen;
19  do {
20  sum2 += sum1 += *var++;
21  tlen--;
22  } while (tlen);
23  sum1 = (sum1 & 0xffff) + (sum1 >> 16);
24  sum2 = (sum2 & 0xffff) + (sum2 >> 16);
25  }
26  sum1 = (sum1 & 0xffff) + (sum1 >> 16);
27  sum2 = (sum2 & 0xffff) + (sum2 >> 16);
28  return (sum2 << 16) | sum1;
29 }
fletcher32
uint32_t fletcher32(uint32_t *n, uint16_t const *var)
Definition: tools_func.c:12