From 2db72850bc8609c8fe961a9579fc1977a8c75954 Mon Sep 17 00:00:00 2001 From: Balhau Date: Sat, 1 Dec 2018 22:56:44 +0000 Subject: [PATCH] Added sse files to implement sse assembly instructions in inline code --- CMakeLists.txt | 1 + src/core/cpu/sse.cpp | 13 +++++++++++++ src/core/cpu/sse.hpp | 17 +++++++++++++++++ sse.cpp | 7 +++++-- 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 src/core/cpu/sse.cpp create mode 100644 src/core/cpu/sse.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 774eab6..3bef207 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ add_executable(cpplab main.cpp) add_executable( sse + src/core/cpu/sse.cpp src/core/cpu/naive.cpp src/core/cpu/avx2.cpp sse.cpp diff --git a/src/core/cpu/sse.cpp b/src/core/cpu/sse.cpp new file mode 100644 index 0000000..8054d70 --- /dev/null +++ b/src/core/cpu/sse.cpp @@ -0,0 +1,13 @@ +#include "sse.hpp" +#include + +//X86 Assembly to add two 128 bit numbers +void core::cpu::SSE::sum_128(int *a,int *b) { + asm( + "movdqa %0, %%xmm1\n" + "paddw %1, %%xmm1\n" + "movdqa %%xmm1, %0" + : "=m"(*a) + : "m"(*b) + ); +} \ No newline at end of file diff --git a/src/core/cpu/sse.hpp b/src/core/cpu/sse.hpp new file mode 100644 index 0000000..fd56426 --- /dev/null +++ b/src/core/cpu/sse.hpp @@ -0,0 +1,17 @@ +#ifndef CORE_CPU_SSE_H +#define CORE_CPU_SSE_H + +using namespace std; +/** + * This will define a set of functions + */ +namespace core { + namespace cpu { + class SSE { + public: + static void sum_128(int *a,int *b); + }; + }; +}; + +#endif \ No newline at end of file diff --git a/sse.cpp b/sse.cpp index 7be0245..a0f7446 100644 --- a/sse.cpp +++ b/sse.cpp @@ -3,19 +3,22 @@ #include #include "src/core/cpu/naive.hpp" +#include "src/core/cpu/sse.hpp" using namespace core::cpu; int main(int argc, char** argcv){ - int v1_128[Naive::LEN_128] = { 0x100, 0x2,0x3,0x4 }; - int v2_128[Naive::LEN_128] = { 0x10, 0x2,0x3,0x4 }; + int v1_128[Naive::LEN_128] = { 0x1, 0x2,0x3,0x4 }; + int v2_128[Naive::LEN_128] = { 0x1, 0x2,0x3,0x4 }; Naive::print(v1_128,Naive::LEN_128); Naive::print(v2_128,Naive::LEN_128); Naive::sum_128_long(v1_128,v2_128); + SSE::sum_128(v1_128,v2_128); Naive::print(v1_128,Naive::LEN_128); Naive::print(v2_128,Naive::LEN_128); + } \ No newline at end of file