| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Simple sanity test of memcpy, memmove, and memset intrinsics. | 2 * Simple sanity test of memcpy, memmove, and memset intrinsics. |
| 3 * (fixed length buffers, variable length buffers, etc.) | 3 * (fixed length buffers, variable length buffers, etc.) |
| 4 */ | 4 */ |
| 5 | 5 |
| 6 #include <stdint.h> /* cstdint requires -std=c++0x or higher */ | 6 #include <stdint.h> /* cstdint requires -std=c++0x or higher */ |
| 7 #include <cstdlib> | 7 #include <cstdlib> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 | 9 |
| 10 #include "mem_intrin.h" | 10 #include "mem_intrin.h" |
| 11 | 11 |
| 12 typedef int elem_t; | 12 typedef int elem_t; |
| 13 | 13 |
| 14 /* | 14 /* |
| 15 * Reset buf to the sequence of bytes: n, n+1, n+2 ... length - 1 | 15 * Reset buf to the sequence of bytes: n, n+1, n+2 ... length - 1 |
| 16 */ | 16 */ |
| 17 static void __attribute__((noinline)) reset_buf(uint8_t *buf, | 17 static void __attribute__((noinline)) |
| 18 uint8_t init, | 18 reset_buf(uint8_t *buf, uint8_t init, size_t length) { |
| 19 size_t length) { | |
| 20 size_t i; | 19 size_t i; |
| 21 size_t v = init; | 20 size_t v = init; |
| 22 for (i = 0; i < length; ++i) | 21 for (i = 0; i < length; ++i) |
| 23 buf[i] = v++; | 22 buf[i] = v++; |
| 24 } | 23 } |
| 25 | 24 |
| 26 /* Do a fletcher-16 checksum so that the order of the values matter. | 25 /* Do a fletcher-16 checksum so that the order of the values matter. |
| 27 * (Not doing a fletcher-32 checksum, since we are working with | 26 * (Not doing a fletcher-32 checksum, since we are working with |
| 28 * smaller buffers, whose total won't approach 2**16). | 27 * smaller buffers, whose total won't approach 2**16). |
| 29 */ | 28 */ |
| 30 static int __attribute__((noinline)) fletcher_checksum(uint8_t *buf, | 29 static int __attribute__((noinline)) |
| 31 size_t length) { | 30 fletcher_checksum(uint8_t *buf, size_t length) { |
| 32 size_t i; | 31 size_t i; |
| 33 int sum = 0; | 32 int sum = 0; |
| 34 int sum_of_sums = 0; | 33 int sum_of_sums = 0; |
| 35 const int kModulus = 255; | 34 const int kModulus = 255; |
| 36 for (i = 0; i < length; ++i) { | 35 for (i = 0; i < length; ++i) { |
| 37 sum = (sum + buf[i]) % kModulus; | 36 sum = (sum + buf[i]) % kModulus; |
| 38 sum_of_sums = (sum_of_sums + sum) % kModulus; | 37 sum_of_sums = (sum_of_sums + sum) % kModulus; |
| 39 } | 38 } |
| 40 return (sum_of_sums << 8) | sum; | 39 return (sum_of_sums << 8) | sum; |
| 41 } | 40 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 memmove((void *)buf2, (void *)buf, length); | 86 memmove((void *)buf2, (void *)buf, length); |
| 88 sum2 = fletcher_checksum(buf2, length); | 87 sum2 = fletcher_checksum(buf2, length); |
| 89 return sum1 + sum2; | 88 return sum1 + sum2; |
| 90 } | 89 } |
| 91 | 90 |
| 92 int memset_test(uint8_t *buf, uint8_t *buf2, uint8_t init, size_t length) { | 91 int memset_test(uint8_t *buf, uint8_t *buf2, uint8_t init, size_t length) { |
| 93 memset((void *)buf, init, length); | 92 memset((void *)buf, init, length); |
| 94 memset((void *)buf2, init + 4, length); | 93 memset((void *)buf2, init + 4, length); |
| 95 return fletcher_checksum(buf, length) + fletcher_checksum(buf2, length); | 94 return fletcher_checksum(buf, length) + fletcher_checksum(buf2, length); |
| 96 } | 95 } |
| OLD | NEW |