| 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" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 int sum = 0; | 32 int sum = 0; |
| 33 int sum_of_sums = 0; | 33 int sum_of_sums = 0; |
| 34 const int kModulus = 255; | 34 const int kModulus = 255; |
| 35 for (i = 0; i < length; ++i) { | 35 for (i = 0; i < length; ++i) { |
| 36 sum = (sum + buf[i]) % kModulus; | 36 sum = (sum + buf[i]) % kModulus; |
| 37 sum_of_sums = (sum_of_sums + sum) % kModulus; | 37 sum_of_sums = (sum_of_sums + sum) % kModulus; |
| 38 } | 38 } |
| 39 return (sum_of_sums << 8) | sum; | 39 return (sum_of_sums << 8) | sum; |
| 40 } | 40 } |
| 41 | 41 |
| 42 #define NWORDS 32 | |
| 43 #define BYTE_LENGTH (NWORDS * sizeof(elem_t)) | |
| 44 | |
| 45 int memcpy_test_fixed_len(uint8_t init) { | |
| 46 elem_t buf[NWORDS]; | |
| 47 elem_t buf2[NWORDS]; | |
| 48 reset_buf((uint8_t *)buf, init, BYTE_LENGTH); | |
| 49 memcpy((void *)buf2, (void *)buf, BYTE_LENGTH); | |
| 50 return fletcher_checksum((uint8_t *)buf2, BYTE_LENGTH); | |
| 51 } | |
| 52 | |
| 53 int memmove_test_fixed_len(uint8_t init) { | |
| 54 elem_t buf[NWORDS]; | |
| 55 reset_buf((uint8_t *)buf, init, BYTE_LENGTH); | |
| 56 memmove((void *)(buf + 4), (void *)buf, BYTE_LENGTH - (4 * sizeof(elem_t))); | |
| 57 return fletcher_checksum((uint8_t *)buf + 4, BYTE_LENGTH - 4); | |
| 58 } | |
| 59 | |
| 60 int memset_test_fixed_len(uint8_t init) { | |
| 61 elem_t buf[NWORDS]; | |
| 62 memset((void *)buf, init, BYTE_LENGTH); | |
| 63 return fletcher_checksum((uint8_t *)buf, BYTE_LENGTH); | |
| 64 } | |
| 65 | |
| 66 int memcpy_test(uint8_t *buf, uint8_t *buf2, uint8_t init, size_t length) { | 42 int memcpy_test(uint8_t *buf, uint8_t *buf2, uint8_t init, size_t length) { |
| 67 reset_buf(buf, init, length); | 43 reset_buf(buf, init, length); |
| 68 memcpy((void *)buf2, (void *)buf, length); | 44 memcpy((void *)buf2, (void *)buf, length); |
| 69 return fletcher_checksum(buf2, length); | 45 return fletcher_checksum(buf2, length); |
| 70 } | 46 } |
| 71 | 47 |
| 72 int memmove_test(uint8_t *buf, uint8_t *buf2, uint8_t init, size_t length) { | 48 int memmove_test(uint8_t *buf, uint8_t *buf2, uint8_t init, size_t length) { |
| 73 int sum1; | 49 int sum1; |
| 74 int sum2; | 50 int sum2; |
| 75 const int overlap_bytes = 4 * sizeof(elem_t); | 51 const int overlap_bytes = 4 * sizeof(elem_t); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 86 memmove((void *)buf2, (void *)buf, length); | 62 memmove((void *)buf2, (void *)buf, length); |
| 87 sum2 = fletcher_checksum(buf2, length); | 63 sum2 = fletcher_checksum(buf2, length); |
| 88 return sum1 + sum2; | 64 return sum1 + sum2; |
| 89 } | 65 } |
| 90 | 66 |
| 91 int memset_test(uint8_t *buf, uint8_t *buf2, uint8_t init, size_t length) { | 67 int memset_test(uint8_t *buf, uint8_t *buf2, uint8_t init, size_t length) { |
| 92 memset((void *)buf, init, length); | 68 memset((void *)buf, init, length); |
| 93 memset((void *)buf2, init + 4, length); | 69 memset((void *)buf2, init + 4, length); |
| 94 return fletcher_checksum(buf, length) + fletcher_checksum(buf2, length); | 70 return fletcher_checksum(buf, length) + fletcher_checksum(buf2, length); |
| 95 } | 71 } |
| 72 |
| 73 #define X(NBYTES) \ |
| 74 int memcpy_test_fixed_len_##NBYTES(uint8_t init) { \ |
| 75 uint8_t buf[NBYTES]; \ |
| 76 uint8_t buf2[NBYTES]; \ |
| 77 reset_buf(buf, init, NBYTES); \ |
| 78 memcpy((void *)buf2, (void *)buf, NBYTES); \ |
| 79 return fletcher_checksum(buf2, NBYTES); \ |
| 80 } \ |
| 81 \ |
| 82 int memmove_test_fixed_len_##NBYTES(uint8_t init) { \ |
| 83 uint8_t buf[NBYTES + 16]; \ |
| 84 uint8_t buf2[NBYTES + 16]; \ |
| 85 reset_buf(buf, init, NBYTES + 16); \ |
| 86 reset_buf(buf2, init, NBYTES + 16); \ |
| 87 /* Move up */ \ |
| 88 memmove((void *)(buf + 16), (void *)buf, NBYTES); \ |
| 89 /* Move down */ \ |
| 90 memmove((void *)buf2, (void *)(buf2 + 16), NBYTES); \ |
| 91 return fletcher_checksum(buf, NBYTES + 16) + \ |
| 92 fletcher_checksum(buf2, NBYTES + 16); \ |
| 93 } \ |
| 94 \ |
| 95 int memset_test_fixed_len_##NBYTES(uint8_t init) { \ |
| 96 uint8_t buf[NBYTES]; \ |
| 97 memset((void *)buf, init, NBYTES); \ |
| 98 return fletcher_checksum(buf, NBYTES); \ |
| 99 } |
| 100 VALUES |
| 101 #undef X |
| OLD | NEW |