Refactoring
This commit is contained in:
parent
7a4a07dd8a
commit
306f84115c
1 changed files with 88 additions and 80 deletions
168
app/sse.cpp
168
app/sse.cpp
|
@ -2,21 +2,87 @@
|
||||||
#include "../src/cpu/utils.hpp"
|
#include "../src/cpu/utils.hpp"
|
||||||
#include "../src/cpu/x86/sse.hpp"
|
#include "../src/cpu/x86/sse.hpp"
|
||||||
#include "../src/cpu/naive.hpp"
|
#include "../src/cpu/naive.hpp"
|
||||||
|
#include "../src/platform/timer.hpp"
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
using namespace cpu;
|
using namespace cpu;
|
||||||
|
using namespace platform;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
long int gettime()
|
|
||||||
{
|
|
||||||
struct timeval tp;
|
|
||||||
gettimeofday(&tp, NULL);
|
|
||||||
long int ms = tp.tv_sec * 1000 + tp.tv_usec / 1000;
|
|
||||||
return ms;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define MAX_ITER 1000 * 1000 * 100
|
#define MAX_ITER 1000 * 1000 * 100
|
||||||
|
|
||||||
|
void naive128(UInt *v1_128, UInt *v2_128)
|
||||||
|
{
|
||||||
|
Timer("Naive 128: ");
|
||||||
|
for (int i = 0; i < MAX_ITER; i++)
|
||||||
|
{
|
||||||
|
Naive::add_128(v1_128, v2_128);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void int128(SSE *sse, UInt *v1_128, UInt *v2_128)
|
||||||
|
{
|
||||||
|
Timer("SIMD(Int) 128: ");
|
||||||
|
for (int i = 0; i < MAX_ITER; i++)
|
||||||
|
{
|
||||||
|
sse->add_128(v1_128, v2_128);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void long128(SSE *sse, ULong *v1_128_l, ULong *v2_128_l)
|
||||||
|
{
|
||||||
|
Timer("SIMD(Long) 128: ");
|
||||||
|
for (int i = 0; i < MAX_ITER; i++)
|
||||||
|
{
|
||||||
|
sse->add_128(v1_128_l, v2_128_l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void byte128(SSE *sse, UChar *c1_128, UChar *c2_128)
|
||||||
|
{
|
||||||
|
Timer("SIMD(Byte) 128: ");
|
||||||
|
for (int i = 0; i < MAX_ITER; i++)
|
||||||
|
{
|
||||||
|
sse->add_128(c1_128, c2_128);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void naive256(UInt *v1_256, UInt *v2_256)
|
||||||
|
{
|
||||||
|
Timer("Naive 256: ");
|
||||||
|
for (int i = 0; i < MAX_ITER; i++)
|
||||||
|
{
|
||||||
|
Naive::add_256(v1_256, v2_256);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void int256(SSE *sse, UInt *v1_256, UInt *v2_256)
|
||||||
|
{
|
||||||
|
Timer("SIMD(Int) 256: ");
|
||||||
|
for (int i = 0; i < MAX_ITER; i++)
|
||||||
|
{
|
||||||
|
sse->add_256(v1_256, v2_256);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void long256(SSE *sse, ULong *v1_256, ULong *v2_256)
|
||||||
|
{
|
||||||
|
Timer("SIMD(Long) 256: ");
|
||||||
|
for (int i = 0; i < MAX_ITER; i++)
|
||||||
|
{
|
||||||
|
sse->add_256(v1_256, v2_256);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void byte256(SSE *sse, UChar *v1_256, UChar *v2_256)
|
||||||
|
{
|
||||||
|
Timer("SIMD(Byte) 256: ");
|
||||||
|
for (int i = 0; i < MAX_ITER; i++)
|
||||||
|
{
|
||||||
|
sse->add_256(v1_256, v2_256);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argcv)
|
int main(int argc, char **argcv)
|
||||||
{
|
{
|
||||||
SSE sse = SSE();
|
SSE sse = SSE();
|
||||||
|
@ -32,16 +98,14 @@ int main(int argc, char **argcv)
|
||||||
|
|
||||||
UChar c1_256[CHAR_LEN_256] = {
|
UChar c1_256[CHAR_LEN_256] = {
|
||||||
0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF, 0x10,
|
0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF, 0x10,
|
||||||
0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF, 0x10
|
0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF, 0x10};
|
||||||
};
|
|
||||||
|
|
||||||
UChar c2_256[CHAR_LEN_256] = {
|
UChar c2_256[CHAR_LEN_256] = {
|
||||||
0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF, 0x10,
|
0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF, 0x10,
|
||||||
0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF, 0x10
|
0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF, 0x10};
|
||||||
};
|
|
||||||
|
|
||||||
UInt v1_256[INT_LEN_256] = {0x1, 0x2, 0x3, 0x4,0x1, 0x2, 0x3, 0x4};
|
UInt v1_256[INT_LEN_256] = {0x1, 0x2, 0x3, 0x4, 0x1, 0x2, 0x3, 0x4};
|
||||||
UInt v2_256[INT_LEN_256] = {0x1, 0x2, 0x3, 0x4,0x1, 0x2, 0x3, 0x4};
|
UInt v2_256[INT_LEN_256] = {0x1, 0x2, 0x3, 0x4, 0x1, 0x2, 0x3, 0x4};
|
||||||
|
|
||||||
ULong v1_256_l[LONG_LEN_256];
|
ULong v1_256_l[LONG_LEN_256];
|
||||||
ULong v2_256_l[LONG_LEN_256];
|
ULong v2_256_l[LONG_LEN_256];
|
||||||
|
@ -49,8 +113,8 @@ int main(int argc, char **argcv)
|
||||||
Utils::int128ToLong(v1_128, v1_128_l);
|
Utils::int128ToLong(v1_128, v1_128_l);
|
||||||
Utils::int128ToLong(v2_128, v2_128_l);
|
Utils::int128ToLong(v2_128, v2_128_l);
|
||||||
|
|
||||||
Utils::int256ToLong(v1_256,v1_256_l);
|
Utils::int256ToLong(v1_256, v1_256_l);
|
||||||
Utils::int256ToLong(v2_256,v2_256_l);
|
Utils::int256ToLong(v2_256, v2_256_l);
|
||||||
|
|
||||||
sse.add_128(v1_128, v2_128);
|
sse.add_128(v1_128, v2_128);
|
||||||
|
|
||||||
|
@ -62,69 +126,13 @@ int main(int argc, char **argcv)
|
||||||
Utils::printHex(v1_128_l, LONG_LEN_128);
|
Utils::printHex(v1_128_l, LONG_LEN_128);
|
||||||
Utils::printHex(v2_128_l, LONG_LEN_128);
|
Utils::printHex(v2_128_l, LONG_LEN_128);
|
||||||
|
|
||||||
start = gettime();
|
naive128(v1_128, v2_128);
|
||||||
for (int i = 0; i < MAX_ITER; i++)
|
int128(&sse, v1_128, v2_128);
|
||||||
{
|
long128(&sse, v1_128_l, v2_128_l);
|
||||||
Naive::add_128(v1_128, v2_128);
|
byte128(&sse, c1_128, c2_128);
|
||||||
}
|
|
||||||
end = gettime();
|
|
||||||
cout << "Naive Approach 128: " << end - start << endl;
|
|
||||||
|
|
||||||
start = gettime();
|
naive256(v1_256, v2_256);
|
||||||
for (int i = 0; i < MAX_ITER; i++)
|
byte256(&sse, c1_256, c2_256);
|
||||||
{
|
int256(&sse, v1_256, v2_256);
|
||||||
sse.add_128(v1_128, v2_128);
|
long256(&sse, v1_256_l, v2_256_l);
|
||||||
}
|
|
||||||
end = gettime();
|
|
||||||
cout << "128 Approach paddw: " << end - start << endl;
|
|
||||||
|
|
||||||
start = gettime();
|
|
||||||
for (int i = 0; i < MAX_ITER; i++)
|
|
||||||
{
|
|
||||||
sse.add_128(v1_128_l, v2_128_l);
|
|
||||||
}
|
|
||||||
end = gettime();
|
|
||||||
cout << "128 Approach paddd: " << end - start << endl;
|
|
||||||
|
|
||||||
start = gettime();
|
|
||||||
for (int i = 0; i < MAX_ITER; i++)
|
|
||||||
{
|
|
||||||
sse.add_128(c1_128, c2_128);
|
|
||||||
}
|
|
||||||
end = gettime();
|
|
||||||
cout << "128 Approach paddb: " << end - start << endl;
|
|
||||||
|
|
||||||
|
|
||||||
start = gettime();
|
|
||||||
for (int i = 0; i < MAX_ITER; i++)
|
|
||||||
{
|
|
||||||
Naive::add_256(v1_256, v2_256);
|
|
||||||
}
|
|
||||||
end = gettime();
|
|
||||||
cout << "Naive Approach 256: " << end - start << endl;
|
|
||||||
|
|
||||||
start = gettime();
|
|
||||||
for (int i = 0; i < MAX_ITER; i++)
|
|
||||||
{
|
|
||||||
sse.add_256(v1_256, v2_256);
|
|
||||||
}
|
|
||||||
end = gettime();
|
|
||||||
cout << "256 Approach vpaddw: " << end - start << endl;
|
|
||||||
|
|
||||||
start = gettime();
|
|
||||||
for (int i = 0; i < MAX_ITER; i++)
|
|
||||||
{
|
|
||||||
sse.add_256(v1_256_l, v2_256_l);
|
|
||||||
}
|
|
||||||
end = gettime();
|
|
||||||
cout << "256 Approach vpaddd: " << end - start << endl;
|
|
||||||
|
|
||||||
start = gettime();
|
|
||||||
for (int i = 0; i < MAX_ITER; i++)
|
|
||||||
{
|
|
||||||
sse.add_256(c1_256, c2_256);
|
|
||||||
}
|
|
||||||
end = gettime();
|
|
||||||
cout << "256 Approach vpaddb: " << end - start << endl;
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue