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