-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopyFunctionTests.cpp
More file actions
51 lines (46 loc) · 1.14 KB
/
Copy pathCopyFunctionTests.cpp
File metadata and controls
51 lines (46 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "memcpy_impl.h"
#include <iostream>
#include <vector>
#include <cstring>
typedef std::vector<uint8_t> buffer_t;
buffer_t GenerateBuffer()
{
buffer_t tmp(0xFFFF);
for(size_t pos = 0; pos < tmp.size(); ++pos)
{
tmp[pos] = static_cast<uint8_t>(pos &0xFF);
}
return tmp;
}
bool TestBuffer( const buffer_t &dst, const buffer_t &src, size_t start)
{
bool errors = false;
for( size_t pos = start; pos < src.size(); ++pos)
{
if(src[pos] != dst[pos])
{
std::cout<<"compare error at pos "<< pos <<" src " << src[pos]<< " dst " <<dst[pos]<<"\n";
errors = true;
}
}
return errors;
}
template <typename FUNCTION>
void TestCopyFunction( FUNCTION fun)
{
auto buffer = GenerateBuffer();
for( size_t start = 0; start < 32; ++start)
{
buffer_t dst(buffer.size());
fun(dst.data()+start, buffer.data()+start, buffer.size()-start);
TestBuffer(dst, buffer, start);
}
}
int main()
{
TestCopyFunction<>(std::memcpy);
TestCopyFunction<>(rep_movsb);
TestCopyFunction<>(sse_memcpy);
TestCopyFunction<>(avx_memcpy);
return 0;
}