1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1996-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
19 ***********************************************************************/
26 #define att_description \
27 "The system 5 release 4 checksum. This is the default for \bsum\b \
28 when \bgetconf UNIVERSE\b is \batt\b. This is the only true sum; \
29 all of the other methods are order dependent."
31 #define att_match "att|sys5|s5|default"
32 #define att_open long_open
33 #define att_init long_init
34 #define att_print long_print
35 #define att_data long_data
38 #if defined(__SUNPRO_C) || defined(__GNUC__)
40 #if defined(__SUNPRO_C)
41 # include <sun_prefetch.h>
42 # define sum_prefetch(addr) sun_prefetch_read_many((void *)(addr))
43 #elif defined(__GNUC__)
44 # define sum_prefetch(addr) __builtin_prefetch((addr), 0, 3)
46 # error Unknown compiler
49 #define CBLOCK_SIZE (64)
52 /* Inmos transputer would love this algorithm */
54 att_block(register Sum_t
* p
, const void* s
, size_t n
)
56 register uint32_t c
= ((Integral_t
*)p
)->sum
;
57 register const unsigned char* b
= (const unsigned char*)s
;
58 register const unsigned char* e
= b
+ n
;
59 register uint32_t s0
, s1
, s2
, s3
, s4
, s5
, s6
, s7
;
60 register unsigned int i
;
62 s0
=s1
=s2
=s3
=s4
=s5
=s6
=s7
=0U;
64 sum_prefetch((void *)b
);
66 while (n
> CBLOCK_SIZE
)
68 sum_prefetch((b
+CBLOCK_SIZE
));
70 /* Compiler will unroll for() loops per #pragma unroll */
71 for (i
=0 ; i
< (CBLOCK_SIZE
/8) ; i
++)
74 * use s0-s7 to decouple calculations (this improves pipelining)
75 * because each operation is completely independent from it's
92 c
+=s0
+s1
+s2
+s3
+s4
+s5
+s6
+s7
;
96 ((Integral_t
*)p
)->sum
= c
;
102 att_block(register Sum_t
* p
, const void* s
, size_t n
)
104 register uint32_t c
= ((Integral_t
*)p
)->sum
;
105 register unsigned char* b
= (unsigned char*)s
;
106 register unsigned char* e
= b
+ n
;
110 ((Integral_t
*)p
)->sum
= c
;
113 #endif /* defined(__SUNPRO_C) || defined(__GNUC__) */
118 register uint32_t c
= ((Integral_t
*)p
)->sum
;
120 c
= (c
& 0xffff) + ((c
>> 16) & 0xffff);
121 c
= (c
& 0xffff) + (c
>> 16);
122 ((Integral_t
*)p
)->sum
= c
& 0xffff;
123 return short_done(p
);