Changeset 16897 for trunk/Mars/mcore/checksum.h
- Timestamp:
- 06/24/13 15:57:53 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mcore/checksum.h
r16670 r16897 47 47 48 48 49 bool add(const char *buf, size_t len )49 bool add(const char *buf, size_t len, bool big_endian = true) 50 50 { 51 51 // Avoid overflows in carry bits … … 73 73 uint32_t *hilo = reinterpret_cast<uint32_t*>(&buffer); 74 74 75 76 const uint16_t *end = sbuf + len/2; 77 78 if (big_endian) 79 addLoopSwapping(sbuf, end, hilo); 80 else 81 addLoop(sbuf, end, hilo); 82 /*const uint16_t *end = sbuf + len/2; 83 while (1) 84 { 85 if (sbuf==end) 86 break; 87 88 hilo[0] += ntohs(*sbuf++); 89 90 if (sbuf==end) 91 break; 92 93 hilo[1] += ntohs(*sbuf++); 94 }*/ 95 96 HandleCarryBits(); 97 98 return true; 99 } 100 101 void addLoopSwapping(const uint16_t *sbuf, const uint16_t *end, uint32_t* hilo) 102 { 75 103 /* 76 104 for (size_t i = 0; i < len/2; i++) … … 83 111 // This is about as twice as fast as the loop above 84 112 // ntohs is CPU optimized, i%2 doesn't need to be computed 85 const uint16_t *end = sbuf + len/2;86 113 while (1) 87 114 { … … 96 123 hilo[1] += ntohs(*sbuf++); 97 124 } 98 99 HandleCarryBits(); 100 101 return true; 102 } 103 104 bool add(const vector<char> &v) 105 { 106 return add(v.data(), v.size()); 125 } 126 127 void addLoop(const uint16_t *sbuf, const uint16_t *end, uint32_t* hilo) 128 { 129 while (1) 130 { 131 if (sbuf==end) 132 break; 133 134 hilo[0] += ntohs(*sbuf++); 135 136 if (sbuf==end) 137 break; 138 139 hilo[1] += ntohs(*sbuf++); 140 } 141 } 142 143 bool add(const vector<char> &v, bool big_endian = true) 144 { 145 return add(v.data(), v.size(), big_endian); 107 146 } 108 147
Note:
See TracChangeset
for help on using the changeset viewer.