From 19299adced6eae21ca635bfda7ab9d1ced59d844 Mon Sep 17 00:00:00 2001 From: "balhau@balhau.net" Date: Sun, 26 Dec 2021 13:05:35 +0000 Subject: [PATCH] Refactor * Changed types.hpp from cpu into platform package --- app/volatile.cpp | 6 ++-- src/bmath/complex.hpp | 2 +- src/bmath/math.hpp | 2 +- src/cpu/atomic.hpp | 4 +-- src/cpu/naive.cpp | 46 ++++++++++++++--------------- src/cpu/naive.hpp | 4 +-- src/cpu/simd.hpp | 16 +++++------ src/cpu/types.hpp | 67 ------------------------------------------- src/cpu/utils.hpp | 4 +-- src/cpu/x86/sse.hpp | 3 +- 10 files changed, 42 insertions(+), 112 deletions(-) delete mode 100644 src/cpu/types.hpp diff --git a/app/volatile.cpp b/app/volatile.cpp index b4a6849..ae3a549 100644 --- a/app/volatile.cpp +++ b/app/volatile.cpp @@ -1,7 +1,7 @@ #include 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 < using namespace std; diff --git a/src/bmath/math.hpp b/src/bmath/math.hpp index cfe85b7..623e51b 100644 --- a/src/bmath/math.hpp +++ b/src/bmath/math.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../cpu/types.hpp" +#include "../platform/types.hpp" namespace BMath { diff --git a/src/cpu/atomic.hpp b/src/cpu/atomic.hpp index 7b22c47..af660f1 100644 --- a/src/cpu/atomic.hpp +++ b/src/cpu/atomic.hpp @@ -1,3 +1,3 @@ -int cmp_swap(int* old_int,int new_int){ - +int cmp_swap(int *old_int, int new_int) +{ } \ No newline at end of file diff --git a/src/cpu/naive.cpp b/src/cpu/naive.cpp index 112fbc8..59c352b 100644 --- a/src/cpu/naive.cpp +++ b/src/cpu/naive.cpp @@ -1,47 +1,45 @@ #include "naive.hpp" -#include "types.hpp" #include -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); }; diff --git a/src/cpu/naive.hpp b/src/cpu/naive.hpp index 3fd16a1..d428189 100644 --- a/src/cpu/naive.hpp +++ b/src/cpu/naive.hpp @@ -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); }; }; \ No newline at end of file diff --git a/src/cpu/simd.hpp b/src/cpu/simd.hpp index 3d780e9..691873c 100644 --- a/src/cpu/simd.hpp +++ b/src/cpu/simd.hpp @@ -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; }; }; \ No newline at end of file diff --git a/src/cpu/types.hpp b/src/cpu/types.hpp deleted file mode 100644 index 4d8ca14..0000000 --- a/src/cpu/types.hpp +++ /dev/null @@ -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 - diff --git a/src/cpu/utils.hpp b/src/cpu/utils.hpp index cf73dc5..5e43c18 100644 --- a/src/cpu/utils.hpp +++ b/src/cpu/utils.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include "types.hpp" +#include "../platform/types.hpp" using namespace std; @@ -67,4 +67,4 @@ namespace cpu packedUInteger[3] = packedULong[1] >> SHIFT_32; }; }; -}; // namespace Cpu \ No newline at end of file +}; \ No newline at end of file diff --git a/src/cpu/x86/sse.hpp b/src/cpu/x86/sse.hpp index 0da13f1..ce1ff70 100644 --- a/src/cpu/x86/sse.hpp +++ b/src/cpu/x86/sse.hpp @@ -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