Refactor
* Changed types.hpp from cpu into platform package
This commit is contained in:
parent
98e52f2579
commit
19299adced
10 changed files with 42 additions and 112 deletions
|
@ -1,7 +1,7 @@
|
|||
#include <iostream>
|
||||
|
||||
inline unsigned long getTimestamp(){
|
||||
unsigned hi,lo;
|
||||
unsigned long hi,lo;
|
||||
asm ("rdtsc": "=a" (lo), "=d" (hi) );
|
||||
return ((unsigned long) lo ) | ((unsigned long) hi << 32);
|
||||
}
|
||||
|
@ -17,6 +17,6 @@ int main(void){
|
|||
unsigned long t2=getTimestamp();
|
||||
std::cout << "Hello 1 -- " << t1 <<std::endl;
|
||||
std::cout << "Hello 2 -- " << t2 <<std::endl;
|
||||
std::cout << "Hello 3 -- " << getTimestamp() <<std::endl;
|
||||
std::cout << "Hello 4 -- " << getTimestamp() <<std::endl;
|
||||
//std::cout << "Hello 3 -- " << getTimestamp() <<std::endl;
|
||||
//std::cout << "Hello 4 -- " << getTimestamp() <<std::endl;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "../cpu/types.hpp"
|
||||
#include "../platform/types.hpp"
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "../cpu/types.hpp"
|
||||
#include "../platform/types.hpp"
|
||||
|
||||
namespace BMath
|
||||
{
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
int cmp_swap(int* old_int,int new_int){
|
||||
|
||||
int cmp_swap(int *old_int, int new_int)
|
||||
{
|
||||
}
|
|
@ -1,47 +1,45 @@
|
|||
#include "naive.hpp"
|
||||
#include "types.hpp"
|
||||
#include <iostream>
|
||||
|
||||
void cpu::Naive::add_128(UInt *a,UInt *b){
|
||||
void cpu::Naive::add_128(UInt *a, UInt *b)
|
||||
{
|
||||
ULong a1 = ((ULong)a[0] << 32) | a[1];
|
||||
ULong a2 = ((ULong)a[2] << 32) | a[3];
|
||||
ULong b1 = ((ULong)b[0] << 32) | b[1];
|
||||
ULong b2 = ((ULong)b[2] << 32) | b[3];
|
||||
|
||||
a1=a1+b1;
|
||||
a2=a2+b2;
|
||||
a1 = a1 + b1;
|
||||
a2 = a2 + b2;
|
||||
|
||||
a[0]=(UInt)a1;
|
||||
a[1]=(UInt)(a1>>32);
|
||||
a[2]=(UInt)a2;
|
||||
a[3]=(UInt)(a2>>32);
|
||||
a[0] = (UInt)a1;
|
||||
a[1] = (UInt)(a1 >> 32);
|
||||
a[2] = (UInt)a2;
|
||||
a[3] = (UInt)(a2 >> 32);
|
||||
};
|
||||
|
||||
void cpu::Naive::add_256(UInt *a,UInt *b){
|
||||
void cpu::Naive::add_256(UInt *a, UInt *b)
|
||||
{
|
||||
ULong a1 = ((ULong)a[0] << 32) | a[1];
|
||||
ULong a2 = ((ULong)a[2] << 32) | a[3];
|
||||
ULong a3 = ((ULong)a[4] << 32) | a[5];
|
||||
ULong a4 = ((ULong)a[6] << 32) | a[7];
|
||||
|
||||
|
||||
ULong b1 = ((ULong)b[0] << 32) | b[1];
|
||||
ULong b2 = ((ULong)b[2] << 32) | b[3];
|
||||
ULong b3 = ((ULong)b[4] << 32) | b[5];
|
||||
ULong b4 = ((ULong)b[6] << 32) | b[7];
|
||||
|
||||
a1 = a1 + b1;
|
||||
a2 = a2 + b2;
|
||||
a3 = a3 + b3;
|
||||
a4 = a4 + b4;
|
||||
|
||||
|
||||
a1=a1+b1;
|
||||
a2=a2+b2;
|
||||
a3=a3+b3;
|
||||
a4=a4+b4;
|
||||
|
||||
a[0]=(UInt)a1;
|
||||
a[1]=(UInt)(a1>>32);
|
||||
a[2]=(UInt)a2;
|
||||
a[3]=(UInt)(a2>>32);
|
||||
a[4]=(UInt)a3;
|
||||
a[5]=(UInt)(a3>>32);
|
||||
a[6]=(UInt)a4;
|
||||
a[7]=(UInt)(a4>>32);
|
||||
a[0] = (UInt)a1;
|
||||
a[1] = (UInt)(a1 >> 32);
|
||||
a[2] = (UInt)a2;
|
||||
a[3] = (UInt)(a2 >> 32);
|
||||
a[4] = (UInt)a3;
|
||||
a[5] = (UInt)(a3 >> 32);
|
||||
a[6] = (UInt)a4;
|
||||
a[7] = (UInt)(a4 >> 32);
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "types.hpp"
|
||||
#include "../platform/types.hpp"
|
||||
namespace cpu
|
||||
{
|
||||
class Naive
|
||||
|
@ -8,6 +8,6 @@ namespace cpu
|
|||
public:
|
||||
// Methods
|
||||
static void add_128(UInt *a, UInt *b);
|
||||
static void add_256(UInt *a,UInt *b);
|
||||
static void add_256(UInt *a, UInt *b);
|
||||
};
|
||||
};
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "types.hpp"
|
||||
#include "../platform/types.hpp"
|
||||
|
||||
namespace cpu
|
||||
{
|
||||
|
@ -12,36 +12,36 @@ namespace cpu
|
|||
* @param a 16 byte vector
|
||||
* @param b 16 byte vector
|
||||
*/
|
||||
virtual void add_128(UChar *a,UChar *b)=0;
|
||||
virtual void add_128(UChar *a, UChar *b) = 0;
|
||||
/**
|
||||
* @brief Add two packed 128 bits number (4 int array)
|
||||
* @param a 4 int vector
|
||||
* @param b 4 int vector
|
||||
*/
|
||||
virtual void add_128(UInt *a, UInt *b)=0;
|
||||
/**
|
||||
virtual void add_128(UInt *a, UInt *b) = 0;
|
||||
/**
|
||||
* @brief Add two packed 128 bits number (2 long array)
|
||||
* @param a 2 long vector
|
||||
* @param b 2 long vector
|
||||
*/
|
||||
virtual void add_128(ULong *a, ULong *b)=0;
|
||||
virtual void add_128(ULong *a, ULong *b) = 0;
|
||||
/**
|
||||
* @brief Add two packed 256 bits number (32 byte array)
|
||||
* @param a 32 byte vector
|
||||
* @param b 32 byte vector
|
||||
*/
|
||||
virtual void add_256(UChar *a,UChar *b)=0;
|
||||
virtual void add_256(UChar *a, UChar *b) = 0;
|
||||
/**
|
||||
* @brief Add two packed 256 bits number (8 int array)
|
||||
* @param a 8 int vector
|
||||
* @param b 8 int vector
|
||||
*/
|
||||
virtual void add_256(UInt *a,UInt *b)=0;
|
||||
virtual void add_256(UInt *a, UInt *b) = 0;
|
||||
/**
|
||||
* @brief Add two packed 256 bits number (4 long array)
|
||||
* @param a 4 long vector
|
||||
* @param b 4 long vector
|
||||
*/
|
||||
virtual void add_256(ULong *a,ULong *b)=0;
|
||||
virtual void add_256(ULong *a, ULong *b) = 0;
|
||||
};
|
||||
};
|
|
@ -1,67 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "../platform/platform.hpp"
|
||||
/*
|
||||
* Types for x86 architectures
|
||||
*/
|
||||
#ifdef ARCH_X86
|
||||
// Signed type alias
|
||||
typedef int Int;
|
||||
typedef long Long;
|
||||
typedef char Char;
|
||||
typedef short Short;
|
||||
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
Int value : 31;
|
||||
Int signal : 1;
|
||||
} int_with_msb;
|
||||
Int signed_int;
|
||||
} SignedInt;
|
||||
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
Long value : 63;
|
||||
Int signal : 1;
|
||||
} long_with_msb;
|
||||
} SignedLong;
|
||||
|
||||
// IEEE floating point alias
|
||||
typedef float Float;
|
||||
typedef double Double;
|
||||
|
||||
// Unsigned type alias
|
||||
typedef unsigned char UChar;
|
||||
typedef unsigned short UShort;
|
||||
typedef unsigned int UInt;
|
||||
typedef unsigned long int ULong;
|
||||
|
||||
// SSE DataTypes
|
||||
#define CHAR_LEN_128 16
|
||||
#define CHAR_LEN_256 32
|
||||
|
||||
#define INT_LEN_64 2
|
||||
#define INT_LEN_128 4
|
||||
#define INT_LEN_256 8
|
||||
#define INT_LEN_512 16
|
||||
|
||||
#define LONG_LEN_64 1
|
||||
#define LONG_LEN_128 2
|
||||
#define LONG_LEN_256 4
|
||||
#define LONG_LEN_512 8
|
||||
|
||||
// Masks
|
||||
#define MASK_32 0xFFFFFFFF
|
||||
#define MASK_16 0xFFFF
|
||||
#define MASK_8 0xFF
|
||||
|
||||
// Shifts
|
||||
#define SHIFT_32 32
|
||||
#define SHIFT_16 16
|
||||
#define SHIFT_8 8
|
||||
#endif
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include "types.hpp"
|
||||
#include "../platform/types.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -67,4 +67,4 @@ namespace cpu
|
|||
packedUInteger[3] = packedULong[1] >> SHIFT_32;
|
||||
};
|
||||
};
|
||||
}; // namespace Cpu
|
||||
};
|
|
@ -3,9 +3,8 @@
|
|||
#include "../../platform/platform.hpp"
|
||||
|
||||
#ifdef ARCH_X86
|
||||
#include "../types.hpp"
|
||||
#include "../../platform/types.hpp"
|
||||
#include "../simd.hpp"
|
||||
|
||||
namespace cpu
|
||||
{
|
||||
class SSE: public SIMD
|
||||
|
|
Loading…
Reference in a new issue