* @internal Calculate a sum of all words in the buffer. * Helper routine for the rte_raw_cksum(). * * @param buf * Pointer to the buffer. * @param len * Length of the buffer. * @param sum * Initial value of the sum. * @return * sum += Sum of all words in the buffer. */
| 158 | * sum += Sum of all words in the buffer. |
| 159 | */ |
| 160 | static inline uint32_t |
| 161 | __rte_raw_cksum(const void *buf, size_t len, uint32_t sum) |
| 162 | { |
| 163 | const void *end; |
| 164 | |
| 165 | for (end = RTE_PTR_ADD(buf, RTE_ALIGN_FLOOR(len, sizeof(uint16_t))); |
| 166 | buf != end; buf = RTE_PTR_ADD(buf, sizeof(uint16_t))) { |
| 167 | uint16_t v; |
| 168 | |
| 169 | memcpy(&v, buf, sizeof(uint16_t)); |
| 170 | sum += v; |
| 171 | } |
| 172 | |
| 173 | /* if length is odd, keeping it byte order independent */ |
| 174 | if (unlikely(len % 2)) { |
| 175 | uint16_t left = 0; |
| 176 | |
| 177 | memcpy(&left, end, 1); |
| 178 | sum += left; |
| 179 | } |
| 180 | |
| 181 | return sum; |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * @internal Reduce a sum to the non-complemented checksum. |
no test coverage detected