| 105 | // Correctness check: swap two distinct buffers, check that contents exchanged. |
| 106 | template <typename Fn> |
| 107 | void verify(const char * name, Fn fn, size_t width) { |
| 108 | std::vector<unsigned char> a(width), b(width), a0(width), b0(width); |
| 109 | std::mt19937 rng(0xBADBEEFu); |
| 110 | for (size_t i = 0; i < width; i++) { a[i] = a0[i] = (unsigned char)(rng() & 0xFF); b[i] = b0[i] = (unsigned char)(rng() & 0xFF); } |
| 111 | fn(a.data(), b.data(), width); |
| 112 | if (memcmp(a.data(), b0.data(), width) != 0 || memcmp(b.data(), a0.data(), width) != 0) { |
| 113 | std::fprintf(stderr, "FAIL: '%s' produced wrong swap at width=%zu\n", name, width); |
| 114 | std::abort(); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | template <typename Fn> |
| 119 | double time_op(Fn fn, size_t width, size_t pairs, int iters) |
no test coverage detected