Added utils header file to group all utility code under the same utility class

This commit is contained in:
Balhau 2018-12-02 09:33:50 +00:00
parent 2ae4f28e7d
commit 7d0629887a
5 changed files with 49 additions and 56 deletions

View file

@ -10,20 +10,11 @@ using namespace core::cpu;
int main(int argc, char **argv) {
//Iteration over class
//blist<std::string> b = blist<std::string>(std::string("Tudor"));
//void *lol = b.current()->value;
int a[avx2::AVX2_INT_SIZE] = {0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xA,0xB,0xC,0xD,0xE,0xF,0x10};
int b[avx2::AVX2_INT_SIZE] = {0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xA,0xB,0xC,0xD,0xE,0xF,0x10,0x11};
BMath bm1 = BMath();
BMath bm2;
u_int64_t c1 = bm1.sum(1,2);
char* input[1024];
std::string str=std::string();
@ -34,17 +25,6 @@ int main(int argc, char **argv) {
}
std::cout << "Computed stuff" << std::endl;
std::cin >> str;
std::cout << "Input: " << str << std::endl;
std::cout << "Cena1: " << c1 << std::endl;
blist<int> list = blist<int>();
std::cout << "List size: " << list.getSize() <<std::endl;
list.add(1);

View file

@ -14,14 +14,4 @@ void core::cpu::Naive::sum_128_long(int *a,int *b){
a[1]=a1;
a[2]=a2>>32;
a[3]=a2;
};
void core::cpu::Naive::print(int *num, int len){
for(int i=0;i<len;i++){
cout << num[i] ;
if(i<len-1){
cout << ",";
}
}
cout << endl;
};

View file

@ -8,23 +8,9 @@ using namespace std;
namespace core {
namespace cpu {
class Naive {
private:
static const unsigned int MASK_32=0xFFFFFFFF;
public:
//Attributes
static const unsigned char INT_LEN_64 = 2;
static const unsigned char INT_LEN_128 = 4;
static const unsigned char INT_LEN_256 = 8;
static const unsigned char INT_LEN_512 = 16;
static const unsigned char LONG_LEN_64 = 1;
static const unsigned char LONG_LEN_128 = 2;
static const unsigned char LONG_LEN_256 = 4;
static const unsigned char LONG_LEN_512 = 8;
//Methods
static void sum_128_long(int* a, int* b);
static void print(int* num,int len);
};
};
};

41
src/core/cpu/utils.hpp Normal file
View file

@ -0,0 +1,41 @@
#ifndef CORE_CPU_UTILS_H
#define CORE_CPU_UTILS_H
#include <iostream>
using namespace::std;
namespace core {
namespace cpu {
class Utils {
public:
//Lengths
static const unsigned char INT_LEN_64 = 2;
static const unsigned char INT_LEN_128 = 4;
static const unsigned char INT_LEN_256 = 8;
static const unsigned char INT_LEN_512 = 16;
static const unsigned char LONG_LEN_64 = 1;
static const unsigned char LONG_LEN_128 = 2;
static const unsigned char LONG_LEN_256 = 4;
static const unsigned char LONG_LEN_512 = 8;
//Masks
static const unsigned int MASK_32=0xFFFFFFFF;
static const unsigned int MASK_16=0xFFFF;
static const unsigned int MASK_8=0xFF;
static void print(int* num,int len) {
for(int i=0;i<len;i++){
cout << num[i] ;
if(i<len-1){
cout << ",";
}
}
cout << endl;
}
};
};
};
#endif

20
sse.cpp
View file

@ -5,6 +5,7 @@
#include "src/core/cpu/naive.hpp"
#include "src/core/cpu/sse.hpp"
#include "src/core/cpu/utils.hpp"
using namespace core::cpu;
@ -18,16 +19,16 @@ long int gettime(){
#define MAX_ITER 1000*1000*100
int main(int argc, char** argcv){
int v1_128[Naive::INT_LEN_128] = { 0x1, 0x2,0x3,0x4 };
int v2_128[Naive::INT_LEN_128] = { 0x1, 0x2,0x3,0x4 };
int v1_128[Utils::INT_LEN_128] = { 0x1, 0x2,0x3,0x4 };
int v2_128[Utils::INT_LEN_128] = { 0x1, 0x2,0x3,0x4 };
long v1_128_l[Naive::LONG_LEN_128] = { (long)0x2<<32 | 0x2, (long)0x4<<32 | 0x3 };
long v2_128_l[Naive::LONG_LEN_128] = { (long)0x2<<32 | 0x2, (long)0x4<<32 | 0x3 };
long v1_128_l[Utils::LONG_LEN_128] = { (long)0x2<<32 | 0x2, (long)0x4<<32 | 0x3 };
long v2_128_l[Utils::LONG_LEN_128] = { (long)0x2<<32 | 0x2, (long)0x4<<32 | 0x3 };
long int start,end;
Naive::print(v1_128,Naive::INT_LEN_128);
Naive::print(v2_128,Naive::INT_LEN_128);
Utils::print(v1_128,Utils::INT_LEN_128);
Utils::print(v2_128,Utils::INT_LEN_128);
start = gettime();
for(int i=0;i<MAX_ITER;i++){
@ -48,11 +49,6 @@ int main(int argc, char** argcv){
SSE::sum_128(v1_128_l,v2_128_l);
}
end = gettime();
cout << "SSE Approach paddd: " << end-start << endl;
//Naive::print(v1_128,Naive::LEN_128);
//Naive::print(v2_128,Naive::LEN_128);
cout << "SSE Approach paddd: " << end-start << endl;
}