| 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 test_fixed_len(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 |
| 101 test_fixed_len(1); |
| 102 test_fixed_len(2); |
| 103 test_fixed_len(3); |
| 104 test_fixed_len(4); |
| 105 test_fixed_len(5); |
| 106 test_fixed_len(6); |
| 107 test_fixed_len(7); |
| 108 test_fixed_len(8); |
| 109 test_fixed_len(9); |
| 110 test_fixed_len(10); |
| 111 test_fixed_len(11); |
| 112 test_fixed_len(12); |
| 113 test_fixed_len(13); |
| 114 test_fixed_len(14); |
| 115 test_fixed_len(15); |
| 116 test_fixed_len(16); |
| 117 test_fixed_len(17); |
| 118 test_fixed_len(18); |
| 119 test_fixed_len(19); |
| 120 test_fixed_len(20); |
| 121 test_fixed_len(21); |
| 122 test_fixed_len(22); |
| 123 test_fixed_len(23); |
| 124 test_fixed_len(24); |
| 125 test_fixed_len(25); |
| 126 test_fixed_len(26); |
| 127 test_fixed_len(27); |
| 128 test_fixed_len(28); |
| 129 test_fixed_len(29); |
| 130 test_fixed_len(30); |
| 131 test_fixed_len(31); |
| 132 test_fixed_len(32); |
| 133 test_fixed_len(33); |
| 134 test_fixed_len(34); |
| 135 test_fixed_len(35); |
| 136 test_fixed_len(36); |
| 137 test_fixed_len(37); |
| 138 test_fixed_len(38); |
| 139 test_fixed_len(39); |
| 140 test_fixed_len(40); |
| 141 test_fixed_len(41); |
| 142 test_fixed_len(42); |
| 143 test_fixed_len(43); |
| 144 test_fixed_len(44); |
| 145 test_fixed_len(45); |
| 146 test_fixed_len(46); |
| 147 test_fixed_len(47); |
| 148 test_fixed_len(48); |
| 149 test_fixed_len(49); |
| 150 test_fixed_len(50); |
| 151 test_fixed_len(51); |
| 152 test_fixed_len(52); |
| 153 test_fixed_len(53); |
| 154 test_fixed_len(54); |
| 155 test_fixed_len(55); |
| 156 test_fixed_len(56); |
| 157 test_fixed_len(57); |
| 158 test_fixed_len(58); |
| 159 test_fixed_len(59); |
| 160 test_fixed_len(60); |
| 161 test_fixed_len(61); |
| 162 test_fixed_len(62); |
| 163 test_fixed_len(63); |
| 164 test_fixed_len(64); |
| 165 test_fixed_len(65); |
| 166 test_fixed_len(66); |
| 167 test_fixed_len(67); |
| 168 test_fixed_len(68); |
| 169 test_fixed_len(69); |
| 170 test_fixed_len(70); |
| 171 test_fixed_len(71); |
| 172 test_fixed_len(72); |
| 173 test_fixed_len(73); |
| 174 test_fixed_len(74); |
| 175 test_fixed_len(75); |
| 176 test_fixed_len(76); |
| 177 test_fixed_len(77); |
| 178 test_fixed_len(78); |
| 179 test_fixed_len(79); |
| 180 test_fixed_len(80); |
| 181 test_fixed_len(81); |
| 182 test_fixed_len(82); |
| 183 test_fixed_len(83); |
| 184 test_fixed_len(84); |
| 185 test_fixed_len(85); |
| 186 test_fixed_len(86); |
| 187 test_fixed_len(87); |
| 188 test_fixed_len(88); |
| 189 test_fixed_len(89); |
| 190 test_fixed_len(90); |
| 191 test_fixed_len(91); |
| 192 test_fixed_len(92); |
| 193 test_fixed_len(93); |
| 194 test_fixed_len(94); |
| 195 test_fixed_len(95); |
| 196 test_fixed_len(96); |
| 197 test_fixed_len(97); |
| 198 test_fixed_len(98); |
| 199 test_fixed_len(99); |
| 200 test_fixed_len(100); |
| 201 test_fixed_len(101); |
| 202 test_fixed_len(102); |
| 203 test_fixed_len(103); |
| 204 test_fixed_len(104); |
| 205 test_fixed_len(105); |
| 206 test_fixed_len(106); |
| 207 test_fixed_len(107); |
| 208 test_fixed_len(108); |
| 209 test_fixed_len(109); |
| 210 test_fixed_len(110); |
| 211 test_fixed_len(111); |
| 212 test_fixed_len(112); |
| 213 test_fixed_len(113); |
| 214 test_fixed_len(114); |
| 215 test_fixed_len(115); |
| 216 test_fixed_len(116); |
| 217 test_fixed_len(117); |
| 218 test_fixed_len(118); |
| 219 test_fixed_len(119); |
| 220 test_fixed_len(120); |
| 221 test_fixed_len(121); |
| 222 test_fixed_len(122); |
| 223 test_fixed_len(123); |
| 224 test_fixed_len(124); |
| 225 test_fixed_len(125); |
| 226 test_fixed_len(126); |
| 227 test_fixed_len(127); |
| 228 test_fixed_len(128); |
| 229 test_fixed_len(129); |
| 230 test_fixed_len(130); |
| 231 test_fixed_len(131); |
| 232 test_fixed_len(132); |
| 233 test_fixed_len(133); |
| 234 test_fixed_len(134); |
| 235 test_fixed_len(135); |
| 236 test_fixed_len(136); |
| 237 test_fixed_len(137); |
| 238 test_fixed_len(138); |
| 239 test_fixed_len(139); |
| 240 test_fixed_len(140); |
| 241 test_fixed_len(141); |
| 242 test_fixed_len(142); |
| 243 test_fixed_len(143); |
| 244 test_fixed_len(144); |
| 245 test_fixed_len(145); |
| 246 test_fixed_len(146); |
| 247 test_fixed_len(147); |
| 248 test_fixed_len(148); |
| 249 test_fixed_len(149); |
| 250 test_fixed_len(150); |
| 251 test_fixed_len(151); |
| 252 test_fixed_len(152); |
| 253 test_fixed_len(153); |
| 254 test_fixed_len(154); |
| 255 test_fixed_len(155); |
| 256 test_fixed_len(156); |
| 257 test_fixed_len(157); |
| 258 test_fixed_len(158); |
| 259 test_fixed_len(159); |
| 260 test_fixed_len(160); |
| 261 test_fixed_len(161); |
| 262 test_fixed_len(162); |
| 263 test_fixed_len(163); |
| 264 test_fixed_len(164); |
| 265 test_fixed_len(165); |
| 266 test_fixed_len(166); |
| 267 test_fixed_len(167); |
| 268 test_fixed_len(168); |
| 269 test_fixed_len(169); |
| 270 test_fixed_len(170); |
| 271 test_fixed_len(171); |
| 272 test_fixed_len(172); |
| 273 test_fixed_len(173); |
| 274 test_fixed_len(174); |
| 275 test_fixed_len(175); |
| 276 test_fixed_len(176); |
| 277 test_fixed_len(177); |
| 278 test_fixed_len(178); |
| 279 test_fixed_len(179); |
| 280 test_fixed_len(180); |
| 281 test_fixed_len(181); |
| 282 test_fixed_len(182); |
| 283 test_fixed_len(183); |
| 284 test_fixed_len(184); |
| 285 test_fixed_len(185); |
| 286 test_fixed_len(186); |
| 287 test_fixed_len(187); |
| 288 test_fixed_len(188); |
| 289 test_fixed_len(189); |
| 290 test_fixed_len(190); |
| 291 test_fixed_len(191); |
| 292 test_fixed_len(192); |
| 293 test_fixed_len(193); |
| 294 test_fixed_len(194); |
| 295 test_fixed_len(195); |
| 296 test_fixed_len(196); |
| 297 test_fixed_len(197); |
| 298 test_fixed_len(198); |
| 299 test_fixed_len(199); |
| 300 test_fixed_len(200); |
| 301 test_fixed_len(201); |
| 302 test_fixed_len(202); |
| 303 test_fixed_len(203); |
| 304 test_fixed_len(204); |
| 305 test_fixed_len(205); |
| 306 test_fixed_len(206); |
| 307 test_fixed_len(207); |
| 308 test_fixed_len(208); |
| 309 test_fixed_len(209); |
| 310 test_fixed_len(210); |
| 311 test_fixed_len(211); |
| 312 test_fixed_len(212); |
| 313 test_fixed_len(213); |
| 314 test_fixed_len(214); |
| 315 test_fixed_len(215); |
| 316 test_fixed_len(216); |
| 317 test_fixed_len(217); |
| 318 test_fixed_len(218); |
| 319 test_fixed_len(219); |
| 320 test_fixed_len(220); |
| 321 test_fixed_len(221); |
| 322 test_fixed_len(222); |
| 323 test_fixed_len(223); |
| 324 test_fixed_len(224); |
| 325 test_fixed_len(225); |
| 326 test_fixed_len(226); |
| 327 test_fixed_len(227); |
| 328 test_fixed_len(228); |
| 329 test_fixed_len(229); |
| 330 test_fixed_len(230); |
| 331 test_fixed_len(231); |
| 332 test_fixed_len(232); |
| 333 test_fixed_len(233); |
| 334 test_fixed_len(234); |
| 335 test_fixed_len(235); |
| 336 test_fixed_len(236); |
| 337 test_fixed_len(237); |
| 338 test_fixed_len(238); |
| 339 test_fixed_len(239); |
| 340 test_fixed_len(240); |
| 341 test_fixed_len(241); |
| 342 test_fixed_len(242); |
| 343 test_fixed_len(243); |
| 344 test_fixed_len(244); |
| 345 test_fixed_len(245); |
| 346 test_fixed_len(246); |
| 347 test_fixed_len(247); |
| 348 test_fixed_len(248); |
| 349 test_fixed_len(249); |
| 350 test_fixed_len(250); |
| 351 test_fixed_len(251); |
| 352 test_fixed_len(252); |
| 353 test_fixed_len(253); |
| 354 test_fixed_len(254); |
| 355 test_fixed_len(255); |
| 356 test_fixed_len(256); |
| 357 |
| 358 #undef test_fixed_len |
| OLD | NEW |