Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

fxadler32.h
1 /********************************************************************************
2 * *
3 * A d l e r 3 2 S u p p o r t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2024 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXADLER32_H
22 #define FXADLER32_H
23 
24 namespace FX {
25 
26 namespace ADLER32 {
27 
28 
45 static inline FXuint SUM(FXuint sum,FXuchar byte){
47  FXuint s1=(sum&65535)+byte;
48  FXuint s2=(sum>>16)+s1;
49  return ((s1%65521)<<16)|(s2%65521);
50  }
51 
52 
54 static inline FXuint SUM(FXuint sum,FXushort x){
55  union{ FXushort s; FXuchar b[2]; } z={x};
56  FXuint s1=sum&65535;
57  FXuint s2=sum>>16;
58 #if FOX_BIGENDIAN == 1
59  s2+=(s1+=z.b[0]);
60  s2+=(s1+=z.b[1]);
61 #else
62  s2+=(s1+=z.b[1]);
63  s2+=(s1+=z.b[0]);
64 #endif
65  return ((s1%65521)<<16)|(s2%65521);
66  }
67 
68 
70 static inline FXuint SUM(FXuint sum,FXuint x){
71  union{ FXuint i; FXuchar b[4]; } z={x};
72  FXuint s1=sum&65535;
73  FXuint s2=sum>>16;
74 #if FOX_BIGENDIAN == 1
75  s2+=(s1+=z.b[0]);
76  s2+=(s1+=z.b[1]);
77  s2+=(s1+=z.b[2]);
78  s2+=(s1+=z.b[3]);
79 #else
80  s2+=(s1+=z.b[3]);
81  s2+=(s1+=z.b[2]);
82  s2+=(s1+=z.b[1]);
83  s2+=(s1+=z.b[0]);
84 #endif
85  return ((s1%65521)<<16)|(s2%65521);
86  }
87 
88 
90 static inline FXuint SUM(FXuint sum,FXulong x){
91  union{ FXulong l; FXuchar b[8]; } z={x};
92  FXuint s1=sum&65535;
93  FXuint s2=sum>>16;
94 #if FOX_BIGENDIAN == 1
95  s2+=(s1+=z.b[0]);
96  s2+=(s1+=z.b[1]);
97  s2+=(s1+=z.b[2]);
98  s2+=(s1+=z.b[3]);
99  s2+=(s1+=z.b[4]);
100  s2+=(s1+=z.b[5]);
101  s2+=(s1+=z.b[6]);
102  s2+=(s1+=z.b[7]);
103 #else
104  s2+=(s1+=z.b[7]);
105  s2+=(s1+=z.b[6]);
106  s2+=(s1+=z.b[5]);
107  s2+=(s1+=z.b[4]);
108  s2+=(s1+=z.b[3]);
109  s2+=(s1+=z.b[2]);
110  s2+=(s1+=z.b[1]);
111  s2+=(s1+=z.b[0]);
112 #endif
113  return ((s1%65521)<<16)|(s2%65521);
114  }
115 
116 
118 static inline FXuint SUM(FXuint sum,const FXuchar *buf,FXival len){
119  FXuint s1=sum&65535;
120  FXuint s2=sum>>16;
121  FXival cnt;
122  while(0<len){
123  len-=(cnt=FXMIN(len,5552));
124  while(8<=cnt){
125  s2+=(s1+=*buf++);
126  s2+=(s1+=*buf++);
127  s2+=(s1+=*buf++);
128  s2+=(s1+=*buf++);
129  s2+=(s1+=*buf++);
130  s2+=(s1+=*buf++);
131  s2+=(s1+=*buf++);
132  s2+=(s1+=*buf++);
133  cnt-=8;
134  }
135  while(cnt){
136  s2+=(s1+=*buf++);
137  cnt--;
138  }
139  s1%=65521;
140  s2%=65521;
141  }
142  return (s2<<16)|s1;
143  }
144 
145 }
146 
147 }
148 
149 #endif
Definition: FX4Splitter.h:28

Copyright © 1997-2022 Jeroen van der Zijp