Changeset 16546 for trunk/Mars
- Timestamp:
- 06/01/13 13:38:04 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mcore/checksum.h
r13988 r16546 1 1 #ifndef MARS_checksum 2 2 #define MARS_checksum 3 4 #include <arpa/inet.h> 3 5 4 6 namespace std … … 65 67 } 66 68 67 const u nsigned short *sbuf = reinterpret_cast<const unsigned short*>(buf);69 const uint32_t *sbuf = reinterpret_cast<const uint32_t*>(buf); 68 70 69 71 uint32_t *hilo = reinterpret_cast<uint32_t*>(&buffer); 70 72 73 /* 71 74 for (size_t i = 0; i < len/2; i++) 72 75 { 73 76 //swap the bytes of the 32 bits value. but... 74 77 //the hi and lo values are stored in fits-like order. do not swap them 75 hilo[i%2] += (sbuf[i]&0xff00)>>8 | (sbuf[i]&0x00ff)<<8; 76 } 78 hilo[i%2] += ntohs(sbuf[i]); //(sbuf[i]&0xff00)>>8 | (sbuf[i]&0x00ff)<<8; 79 }*/ 80 81 // This is about as twice as fast as the loop above 82 // ntohs is CPU optimized, hilo[n] doesn't need to be computed 83 const uint32_t *end = sbuf + len/2; 84 while (1) 85 { 86 hilo[0] += ntohs(*sbuf++); 87 if (sbuf==end) 88 break; 89 90 hilo[1] += ntohs(*sbuf++); 91 if (sbuf==end) 92 break; 93 } 94 77 95 HandleCarryBits(); 78 96
Note:
See TracChangeset
for help on using the changeset viewer.