Refactor code for multi architecture SIMD operations
This commit is contained in:
parent
55f0152b01
commit
8b82d09726
30 changed files with 685 additions and 418 deletions
222
CppCmds.make
222
CppCmds.make
|
@ -1,222 +0,0 @@
|
|||
# GNU Make project makefile autogenerated by Premake
|
||||
|
||||
ifndef config
|
||||
config=debug
|
||||
endif
|
||||
|
||||
ifndef verbose
|
||||
SILENT = @
|
||||
endif
|
||||
|
||||
.PHONY: clean prebuild prelink
|
||||
|
||||
ifeq ($(config),debug)
|
||||
RESCOMP = windres
|
||||
TARGETDIR = bin/Debug
|
||||
TARGET = $(TARGETDIR)/CppCmds
|
||||
OBJDIR = obj/Debug
|
||||
DEFINES += -DDEBUG -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXGTK__
|
||||
INCLUDES += -I/usr/lib/x86_64-linux-gnu/wx/include/gtk3-unicode-3.0 -I/usr/include/wx-3.0
|
||||
FORCE_INCLUDE +=
|
||||
ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
|
||||
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g
|
||||
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g
|
||||
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
|
||||
LIBS += -lwx_gtk3u_xrc-3.0 -lwx_gtk3u_html-3.0 -lwx_gtk3u_adv-3.0 -lwx_gtk3u_core-3.0 -lwx_baseu_xml-3.0 -lwx_baseu_net-3.0 -lwx_baseu-3.0 -lglfw3
|
||||
LDDEPS +=
|
||||
ALL_LDFLAGS += $(LDFLAGS)
|
||||
LINKCMD = $(CXX) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
|
||||
define PREBUILDCMDS
|
||||
endef
|
||||
define PRELINKCMDS
|
||||
endef
|
||||
define POSTBUILDCMDS
|
||||
endef
|
||||
all: prebuild prelink $(TARGET)
|
||||
@:
|
||||
|
||||
endif
|
||||
|
||||
ifeq ($(config),release)
|
||||
RESCOMP = windres
|
||||
TARGETDIR = bin/Release
|
||||
TARGET = $(TARGETDIR)/CppCmds
|
||||
OBJDIR = obj/Release
|
||||
DEFINES += -DNDEBUG -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXGTK__
|
||||
INCLUDES += -I/usr/lib/x86_64-linux-gnu/wx/include/gtk3-unicode-3.0 -I/usr/include/wx-3.0
|
||||
FORCE_INCLUDE +=
|
||||
ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
|
||||
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2
|
||||
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O2
|
||||
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
|
||||
LIBS += -lwx_gtk3u_xrc-3.0 -lwx_gtk3u_html-3.0 -lwx_gtk3u_adv-3.0 -lwx_gtk3u_core-3.0 -lwx_baseu_xml-3.0 -lwx_baseu_net-3.0 -lwx_baseu-3.0 -lglfw3
|
||||
LDDEPS +=
|
||||
ALL_LDFLAGS += $(LDFLAGS) -s
|
||||
LINKCMD = $(CXX) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
|
||||
define PREBUILDCMDS
|
||||
endef
|
||||
define PRELINKCMDS
|
||||
endef
|
||||
define POSTBUILDCMDS
|
||||
endef
|
||||
all: prebuild prelink $(TARGET)
|
||||
@:
|
||||
|
||||
endif
|
||||
|
||||
OBJECTS := \
|
||||
$(OBJDIR)/complex.o \
|
||||
$(OBJDIR)/complex1.o \
|
||||
$(OBJDIR)/math.o \
|
||||
$(OBJDIR)/math1.o \
|
||||
$(OBJDIR)/avx2.o \
|
||||
$(OBJDIR)/sse.o \
|
||||
$(OBJDIR)/naive.o \
|
||||
$(OBJDIR)/sse1.o \
|
||||
$(OBJDIR)/gui1.o \
|
||||
$(OBJDIR)/ex1.o \
|
||||
$(OBJDIR)/ex2.o \
|
||||
$(OBJDIR)/model.o \
|
||||
$(OBJDIR)/volatile.o \
|
||||
$(OBJDIR)/IndexBuffer.o \
|
||||
$(OBJDIR)/Renderer.o \
|
||||
$(OBJDIR)/Shader.o \
|
||||
$(OBJDIR)/VertexArray.o \
|
||||
$(OBJDIR)/VertexBuffer.o \
|
||||
$(OBJDIR)/VertexBufferLayout.o \
|
||||
$(OBJDIR)/gl1.o \
|
||||
$(OBJDIR)/gl2.o \
|
||||
$(OBJDIR)/gl3.o \
|
||||
$(OBJDIR)/utils.o \
|
||||
|
||||
RESOURCES := \
|
||||
|
||||
CUSTOMFILES := \
|
||||
|
||||
SHELLTYPE := posix
|
||||
ifeq (.exe,$(findstring .exe,$(ComSpec)))
|
||||
SHELLTYPE := msdos
|
||||
endif
|
||||
|
||||
$(TARGET): $(GCH) ${CUSTOMFILES} $(OBJECTS) $(LDDEPS) $(RESOURCES) | $(TARGETDIR)
|
||||
@echo Linking CppCmds
|
||||
$(SILENT) $(LINKCMD)
|
||||
$(POSTBUILDCMDS)
|
||||
|
||||
$(CUSTOMFILES): | $(OBJDIR)
|
||||
|
||||
$(TARGETDIR):
|
||||
@echo Creating $(TARGETDIR)
|
||||
ifeq (posix,$(SHELLTYPE))
|
||||
$(SILENT) mkdir -p $(TARGETDIR)
|
||||
else
|
||||
$(SILENT) mkdir $(subst /,\\,$(TARGETDIR))
|
||||
endif
|
||||
|
||||
$(OBJDIR):
|
||||
@echo Creating $(OBJDIR)
|
||||
ifeq (posix,$(SHELLTYPE))
|
||||
$(SILENT) mkdir -p $(OBJDIR)
|
||||
else
|
||||
$(SILENT) mkdir $(subst /,\\,$(OBJDIR))
|
||||
endif
|
||||
|
||||
clean:
|
||||
@echo Cleaning CppCmds
|
||||
ifeq (posix,$(SHELLTYPE))
|
||||
$(SILENT) rm -f $(TARGET)
|
||||
$(SILENT) rm -rf $(OBJDIR)
|
||||
else
|
||||
$(SILENT) if exist $(subst /,\\,$(TARGET)) del $(subst /,\\,$(TARGET))
|
||||
$(SILENT) if exist $(subst /,\\,$(OBJDIR)) rmdir /s /q $(subst /,\\,$(OBJDIR))
|
||||
endif
|
||||
|
||||
prebuild:
|
||||
$(PREBUILDCMDS)
|
||||
|
||||
prelink:
|
||||
$(PRELINKCMDS)
|
||||
|
||||
ifneq (,$(PCH))
|
||||
$(OBJECTS): $(GCH) $(PCH) | $(OBJDIR)
|
||||
$(GCH): $(PCH) | $(OBJDIR)
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) -x c++-header $(ALL_CXXFLAGS) -o "$@" -MF "$(@:%.gch=%.d)" -c "$<"
|
||||
else
|
||||
$(OBJECTS): | $(OBJDIR)
|
||||
endif
|
||||
|
||||
$(OBJDIR)/complex.o: src/bmath/complex.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/complex1.o: src/bmath/demos/complex.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/math.o: src/bmath/demos/math.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/math1.o: src/bmath/math.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/avx2.o: src/cpu/avx2.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/sse.o: src/cpu/demos/sse.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/naive.o: src/cpu/naive.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/sse1.o: src/cpu/sse.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/gui1.o: src/gui/gui1.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/ex1.o: src/misc/dec/ex1.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/ex2.o: src/misc/dec/ex2.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/model.o: src/misc/memory/model.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/volatile.o: src/misc/memory/volatile.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/IndexBuffer.o: src/opengl/IndexBuffer.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/Renderer.o: src/opengl/Renderer.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/Shader.o: src/opengl/Shader.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/VertexArray.o: src/opengl/VertexArray.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/VertexBuffer.o: src/opengl/VertexBuffer.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/VertexBufferLayout.o: src/opengl/VertexBufferLayout.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/gl1.o: src/opengl/gl1.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/gl2.o: src/opengl/gl2.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/gl3.o: src/opengl/gl3.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/utils.o: src/opengl/utils.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
|
||||
-include $(OBJECTS:%.o=%.d)
|
||||
ifneq (,$(PCH))
|
||||
-include $(OBJDIR)/$(notdir $(PCH)).d
|
||||
endif
|
|
@ -1,6 +1,6 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "../../../include/misc/memory/util.h"
|
||||
#include "../memory/util.h"
|
||||
|
||||
#define AUTO_FREE __attribute__((cleanup(scoped_free)))
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "../../../include/misc/memory/util.h"
|
||||
#include "../memory/util.h"
|
||||
|
||||
void stack_frame2(void)
|
||||
{
|
|
@ -1,5 +1,5 @@
|
|||
#include <iostream>
|
||||
#include "../complex.hpp"
|
||||
#include "../bmath/complex.hpp"
|
||||
|
||||
using BMath::Complex;
|
||||
|
|
@ -6,12 +6,12 @@
|
|||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "Shader.h"
|
||||
#include "Renderer.h"
|
||||
#include "VertexBuffer.h"
|
||||
#include "IndexBuffer.h"
|
||||
#include "VertexArray.h"
|
||||
#include "utils.h"
|
||||
#include "../opengl/Shader.h"
|
||||
#include "../opengl/Renderer.h"
|
||||
#include "../opengl/VertexBuffer.h"
|
||||
#include "../opengl/IndexBuffer.h"
|
||||
#include "../opengl/VertexArray.h"
|
||||
#include "../opengl/utils.h"
|
||||
|
||||
const std::string SHADERS_PATH = "src/opengl/res/shaders/Basic.shader";
|
||||
|
|
@ -74,8 +74,8 @@ void printString(char *s)
|
|||
void display(void)
|
||||
{
|
||||
GLfloat white[3] = {1.0, 1.0, 1.0};
|
||||
const char* p1="LINDA MERDA";
|
||||
const char* p2="PUTA MERDA";
|
||||
const char* p1="KIE KIE";
|
||||
const char* p2="DIRI RIIR";
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glColor3fv(white);
|
|
@ -1,4 +1,4 @@
|
|||
#include "../math.hpp"
|
||||
#include "../bmath/math.hpp"
|
||||
#include <iostream>
|
||||
|
||||
using namespace BMath;
|
|
@ -1,7 +1,7 @@
|
|||
#include <iostream>
|
||||
#include "../utils.hpp"
|
||||
#include "../sse.hpp"
|
||||
#include "../naive.hpp"
|
||||
#include "../src/cpu/utils.hpp"
|
||||
#include "../src/cpu/x86/sse.hpp"
|
||||
#include "../src/cpu/naive.hpp"
|
||||
#include <sys/time.h>
|
||||
|
||||
using namespace cpu;
|
||||
|
@ -17,6 +17,7 @@ long int gettime(){
|
|||
#define MAX_ITER 1000*1000*100
|
||||
|
||||
int main(int argc, char** argcv){
|
||||
SSE sse = SSE();
|
||||
UInt v1_128[INT_LEN_128] = { 0x1, 0x2,0x3,0x4 };
|
||||
UInt v2_128[INT_LEN_128] = { 0x1, 0x2,0x3,0x4 };
|
||||
|
||||
|
@ -26,7 +27,7 @@ int main(int argc, char** argcv){
|
|||
Utils::int128BitToLong(v1_128,v1_128_l);
|
||||
Utils::int128BitToLong(v2_128,v2_128_l);
|
||||
|
||||
SSE::paddw(v1_128,v2_128);
|
||||
sse.add_128(v1_128,v2_128);
|
||||
|
||||
long int start,end;
|
||||
|
||||
|
@ -45,14 +46,14 @@ int main(int argc, char** argcv){
|
|||
|
||||
start = gettime();
|
||||
for(int i=0;i<MAX_ITER;i++){
|
||||
SSE::paddw(v1_128,v2_128);
|
||||
sse.add_128(v1_128,v2_128);
|
||||
}
|
||||
end = gettime();
|
||||
cout << "SSE Approach paddw: " << end-start << endl;
|
||||
|
||||
start = gettime();
|
||||
for(int i=0;i<MAX_ITER;i++){
|
||||
SSE::paddd(v1_128_l,v2_128_l);
|
||||
sse.add_128(v1_128_l,v2_128_l);
|
||||
}
|
||||
end = gettime();
|
||||
cout << "SSE Approach paddd: " << end-start << endl;
|
150
premake/bmath.make
Normal file
150
premake/bmath.make
Normal file
|
@ -0,0 +1,150 @@
|
|||
# GNU Make project makefile autogenerated by Premake
|
||||
|
||||
ifndef config
|
||||
config=debug
|
||||
endif
|
||||
|
||||
ifndef verbose
|
||||
SILENT = @
|
||||
endif
|
||||
|
||||
.PHONY: clean prebuild prelink
|
||||
|
||||
ifeq ($(config),debug)
|
||||
RESCOMP = windres
|
||||
TARGETDIR = ../lib/Debug
|
||||
TARGET = $(TARGETDIR)/libbmath.so
|
||||
OBJDIR = ../obj/Debug/bmath
|
||||
DEFINES += -DDEBUG
|
||||
INCLUDES +=
|
||||
FORCE_INCLUDE +=
|
||||
ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
|
||||
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -fPIC -g
|
||||
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -fPIC -g
|
||||
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
|
||||
LIBS +=
|
||||
LDDEPS +=
|
||||
ALL_LDFLAGS += $(LDFLAGS) -shared -Wl,-soname=libbmath.so
|
||||
LINKCMD = $(CXX) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
|
||||
define PREBUILDCMDS
|
||||
endef
|
||||
define PRELINKCMDS
|
||||
endef
|
||||
define POSTBUILDCMDS
|
||||
endef
|
||||
all: prebuild prelink $(TARGET)
|
||||
@:
|
||||
|
||||
endif
|
||||
|
||||
ifeq ($(config),release)
|
||||
RESCOMP = windres
|
||||
TARGETDIR = ../lib/Release
|
||||
TARGET = $(TARGETDIR)/libbmath.so
|
||||
OBJDIR = ../obj/Release/bmath
|
||||
DEFINES += -DNDEBUG
|
||||
INCLUDES +=
|
||||
FORCE_INCLUDE +=
|
||||
ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
|
||||
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2 -fPIC
|
||||
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O2 -fPIC
|
||||
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
|
||||
LIBS +=
|
||||
LDDEPS +=
|
||||
ALL_LDFLAGS += $(LDFLAGS) -shared -Wl,-soname=libbmath.so -s
|
||||
LINKCMD = $(CXX) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
|
||||
define PREBUILDCMDS
|
||||
endef
|
||||
define PRELINKCMDS
|
||||
endef
|
||||
define POSTBUILDCMDS
|
||||
endef
|
||||
all: prebuild prelink $(TARGET)
|
||||
@:
|
||||
|
||||
endif
|
||||
|
||||
OBJECTS := \
|
||||
$(OBJDIR)/complex.o \
|
||||
$(OBJDIR)/math.o \
|
||||
$(OBJDIR)/avx2.o \
|
||||
$(OBJDIR)/naive.o \
|
||||
$(OBJDIR)/sse.o \
|
||||
|
||||
RESOURCES := \
|
||||
|
||||
CUSTOMFILES := \
|
||||
|
||||
SHELLTYPE := posix
|
||||
ifeq (.exe,$(findstring .exe,$(ComSpec)))
|
||||
SHELLTYPE := msdos
|
||||
endif
|
||||
|
||||
$(TARGET): $(GCH) ${CUSTOMFILES} $(OBJECTS) $(LDDEPS) $(RESOURCES) | $(TARGETDIR)
|
||||
@echo Linking bmath
|
||||
$(SILENT) $(LINKCMD)
|
||||
$(POSTBUILDCMDS)
|
||||
|
||||
$(CUSTOMFILES): | $(OBJDIR)
|
||||
|
||||
$(TARGETDIR):
|
||||
@echo Creating $(TARGETDIR)
|
||||
ifeq (posix,$(SHELLTYPE))
|
||||
$(SILENT) mkdir -p $(TARGETDIR)
|
||||
else
|
||||
$(SILENT) mkdir $(subst /,\\,$(TARGETDIR))
|
||||
endif
|
||||
|
||||
$(OBJDIR):
|
||||
@echo Creating $(OBJDIR)
|
||||
ifeq (posix,$(SHELLTYPE))
|
||||
$(SILENT) mkdir -p $(OBJDIR)
|
||||
else
|
||||
$(SILENT) mkdir $(subst /,\\,$(OBJDIR))
|
||||
endif
|
||||
|
||||
clean:
|
||||
@echo Cleaning bmath
|
||||
ifeq (posix,$(SHELLTYPE))
|
||||
$(SILENT) rm -f $(TARGET)
|
||||
$(SILENT) rm -rf $(OBJDIR)
|
||||
else
|
||||
$(SILENT) if exist $(subst /,\\,$(TARGET)) del $(subst /,\\,$(TARGET))
|
||||
$(SILENT) if exist $(subst /,\\,$(OBJDIR)) rmdir /s /q $(subst /,\\,$(OBJDIR))
|
||||
endif
|
||||
|
||||
prebuild:
|
||||
$(PREBUILDCMDS)
|
||||
|
||||
prelink:
|
||||
$(PRELINKCMDS)
|
||||
|
||||
ifneq (,$(PCH))
|
||||
$(OBJECTS): $(GCH) $(PCH) | $(OBJDIR)
|
||||
$(GCH): $(PCH) | $(OBJDIR)
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) -x c++-header $(ALL_CXXFLAGS) -o "$@" -MF "$(@:%.gch=%.d)" -c "$<"
|
||||
else
|
||||
$(OBJECTS): | $(OBJDIR)
|
||||
endif
|
||||
|
||||
$(OBJDIR)/complex.o: ../src/bmath/complex.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/math.o: ../src/bmath/math.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/avx2.o: ../src/cpu/avx2.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/naive.o: ../src/cpu/naive.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/sse.o: ../src/cpu/x86/sse.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
|
||||
-include $(OBJECTS:%.o=%.d)
|
||||
ifneq (,$(PCH))
|
||||
-include $(OBJDIR)/$(notdir $(PCH)).d
|
||||
endif
|
23
premake/libbmath.lua
Normal file
23
premake/libbmath.lua
Normal file
|
@ -0,0 +1,23 @@
|
|||
project "bmath"
|
||||
kind "SharedLib"
|
||||
language "c++"
|
||||
targetdir "../lib/%{cfg.buildcfg}"
|
||||
objdir "../obj"
|
||||
|
||||
--files {"**.hpp","**.cpp"}
|
||||
files {
|
||||
"../src/bmath/**.hpp",
|
||||
"../src/bmath/**.cpp",
|
||||
"../src/cpu/**.hpp",
|
||||
"../src/cpu/**.cpp"
|
||||
}
|
||||
|
||||
filter "configurations:Debug"
|
||||
defines { "DEBUG" }
|
||||
symbols "On"
|
||||
|
||||
filter "configurations:Release"
|
||||
defines { "NDEBUG" }
|
||||
optimize "On"
|
||||
|
||||
filter { "system:linux" }
|
150
premake/libmath.make
Normal file
150
premake/libmath.make
Normal file
|
@ -0,0 +1,150 @@
|
|||
# GNU Make project makefile autogenerated by Premake
|
||||
|
||||
ifndef config
|
||||
config=debug
|
||||
endif
|
||||
|
||||
ifndef verbose
|
||||
SILENT = @
|
||||
endif
|
||||
|
||||
.PHONY: clean prebuild prelink
|
||||
|
||||
ifeq ($(config),debug)
|
||||
RESCOMP = windres
|
||||
TARGETDIR = ../lib/Debug
|
||||
TARGET = $(TARGETDIR)/liblibmath.so
|
||||
OBJDIR = ../obj/Debug/libmath
|
||||
DEFINES += -DDEBUG
|
||||
INCLUDES +=
|
||||
FORCE_INCLUDE +=
|
||||
ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
|
||||
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -fPIC -g
|
||||
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -fPIC -g
|
||||
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
|
||||
LIBS +=
|
||||
LDDEPS +=
|
||||
ALL_LDFLAGS += $(LDFLAGS) -shared -Wl,-soname=liblibmath.so
|
||||
LINKCMD = $(CXX) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
|
||||
define PREBUILDCMDS
|
||||
endef
|
||||
define PRELINKCMDS
|
||||
endef
|
||||
define POSTBUILDCMDS
|
||||
endef
|
||||
all: prebuild prelink $(TARGET)
|
||||
@:
|
||||
|
||||
endif
|
||||
|
||||
ifeq ($(config),release)
|
||||
RESCOMP = windres
|
||||
TARGETDIR = ../lib/Release
|
||||
TARGET = $(TARGETDIR)/liblibmath.so
|
||||
OBJDIR = ../obj/Release/libmath
|
||||
DEFINES += -DNDEBUG
|
||||
INCLUDES +=
|
||||
FORCE_INCLUDE +=
|
||||
ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
|
||||
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2 -fPIC
|
||||
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O2 -fPIC
|
||||
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
|
||||
LIBS +=
|
||||
LDDEPS +=
|
||||
ALL_LDFLAGS += $(LDFLAGS) -shared -Wl,-soname=liblibmath.so -s
|
||||
LINKCMD = $(CXX) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
|
||||
define PREBUILDCMDS
|
||||
endef
|
||||
define PRELINKCMDS
|
||||
endef
|
||||
define POSTBUILDCMDS
|
||||
endef
|
||||
all: prebuild prelink $(TARGET)
|
||||
@:
|
||||
|
||||
endif
|
||||
|
||||
OBJECTS := \
|
||||
$(OBJDIR)/complex.o \
|
||||
$(OBJDIR)/math.o \
|
||||
$(OBJDIR)/avx2.o \
|
||||
$(OBJDIR)/naive.o \
|
||||
$(OBJDIR)/sse.o \
|
||||
|
||||
RESOURCES := \
|
||||
|
||||
CUSTOMFILES := \
|
||||
|
||||
SHELLTYPE := posix
|
||||
ifeq (.exe,$(findstring .exe,$(ComSpec)))
|
||||
SHELLTYPE := msdos
|
||||
endif
|
||||
|
||||
$(TARGET): $(GCH) ${CUSTOMFILES} $(OBJECTS) $(LDDEPS) $(RESOURCES) | $(TARGETDIR)
|
||||
@echo Linking libmath
|
||||
$(SILENT) $(LINKCMD)
|
||||
$(POSTBUILDCMDS)
|
||||
|
||||
$(CUSTOMFILES): | $(OBJDIR)
|
||||
|
||||
$(TARGETDIR):
|
||||
@echo Creating $(TARGETDIR)
|
||||
ifeq (posix,$(SHELLTYPE))
|
||||
$(SILENT) mkdir -p $(TARGETDIR)
|
||||
else
|
||||
$(SILENT) mkdir $(subst /,\\,$(TARGETDIR))
|
||||
endif
|
||||
|
||||
$(OBJDIR):
|
||||
@echo Creating $(OBJDIR)
|
||||
ifeq (posix,$(SHELLTYPE))
|
||||
$(SILENT) mkdir -p $(OBJDIR)
|
||||
else
|
||||
$(SILENT) mkdir $(subst /,\\,$(OBJDIR))
|
||||
endif
|
||||
|
||||
clean:
|
||||
@echo Cleaning libmath
|
||||
ifeq (posix,$(SHELLTYPE))
|
||||
$(SILENT) rm -f $(TARGET)
|
||||
$(SILENT) rm -rf $(OBJDIR)
|
||||
else
|
||||
$(SILENT) if exist $(subst /,\\,$(TARGET)) del $(subst /,\\,$(TARGET))
|
||||
$(SILENT) if exist $(subst /,\\,$(OBJDIR)) rmdir /s /q $(subst /,\\,$(OBJDIR))
|
||||
endif
|
||||
|
||||
prebuild:
|
||||
$(PREBUILDCMDS)
|
||||
|
||||
prelink:
|
||||
$(PRELINKCMDS)
|
||||
|
||||
ifneq (,$(PCH))
|
||||
$(OBJECTS): $(GCH) $(PCH) | $(OBJDIR)
|
||||
$(GCH): $(PCH) | $(OBJDIR)
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) -x c++-header $(ALL_CXXFLAGS) -o "$@" -MF "$(@:%.gch=%.d)" -c "$<"
|
||||
else
|
||||
$(OBJECTS): | $(OBJDIR)
|
||||
endif
|
||||
|
||||
$(OBJDIR)/complex.o: ../src/bmath/complex.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/math.o: ../src/bmath/math.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/avx2.o: ../src/cpu/avx2.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/naive.o: ../src/cpu/naive.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/sse.o: ../src/cpu/sse.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
|
||||
-include $(OBJECTS:%.o=%.d)
|
||||
ifneq (,$(PCH))
|
||||
-include $(OBJDIR)/$(notdir $(PCH)).d
|
||||
endif
|
26
premake/sse.lua
Normal file
26
premake/sse.lua
Normal file
|
@ -0,0 +1,26 @@
|
|||
project "sse"
|
||||
kind "ConsoleApp"
|
||||
language "c++"
|
||||
targetdir "../bin/%{cfg.buildcfg}"
|
||||
objdir "../obj"
|
||||
|
||||
--files {"**.hpp","**.cpp"}
|
||||
files {
|
||||
"../app/sse.cpp",
|
||||
"../src/bmath/**.hpp",
|
||||
"../src/bmath/**.cpp",
|
||||
"../src/misc/**.hpp",
|
||||
"../src/misc/**.cpp",
|
||||
"../src/cpu/**.hpp",
|
||||
"../src/cpu/**.cpp"
|
||||
}
|
||||
|
||||
filter "configurations:Debug"
|
||||
defines { "DEBUG" }
|
||||
symbols "On"
|
||||
|
||||
filter "configurations:Release"
|
||||
defines { "NDEBUG" }
|
||||
optimize "On"
|
||||
|
||||
filter { "system:linux" }
|
158
premake/sse.make
Normal file
158
premake/sse.make
Normal file
|
@ -0,0 +1,158 @@
|
|||
# GNU Make project makefile autogenerated by Premake
|
||||
|
||||
ifndef config
|
||||
config=debug
|
||||
endif
|
||||
|
||||
ifndef verbose
|
||||
SILENT = @
|
||||
endif
|
||||
|
||||
.PHONY: clean prebuild prelink
|
||||
|
||||
ifeq ($(config),debug)
|
||||
RESCOMP = windres
|
||||
TARGETDIR = ../bin/Debug
|
||||
TARGET = $(TARGETDIR)/sse
|
||||
OBJDIR = ../obj/Debug/sse
|
||||
DEFINES += -DDEBUG
|
||||
INCLUDES +=
|
||||
FORCE_INCLUDE +=
|
||||
ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
|
||||
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g
|
||||
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g
|
||||
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
|
||||
LIBS +=
|
||||
LDDEPS +=
|
||||
ALL_LDFLAGS += $(LDFLAGS)
|
||||
LINKCMD = $(CXX) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
|
||||
define PREBUILDCMDS
|
||||
endef
|
||||
define PRELINKCMDS
|
||||
endef
|
||||
define POSTBUILDCMDS
|
||||
endef
|
||||
all: prebuild prelink $(TARGET)
|
||||
@:
|
||||
|
||||
endif
|
||||
|
||||
ifeq ($(config),release)
|
||||
RESCOMP = windres
|
||||
TARGETDIR = ../bin/Release
|
||||
TARGET = $(TARGETDIR)/sse
|
||||
OBJDIR = ../obj/Release/sse
|
||||
DEFINES += -DNDEBUG
|
||||
INCLUDES +=
|
||||
FORCE_INCLUDE +=
|
||||
ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
|
||||
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2
|
||||
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O2
|
||||
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
|
||||
LIBS +=
|
||||
LDDEPS +=
|
||||
ALL_LDFLAGS += $(LDFLAGS) -s
|
||||
LINKCMD = $(CXX) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
|
||||
define PREBUILDCMDS
|
||||
endef
|
||||
define PRELINKCMDS
|
||||
endef
|
||||
define POSTBUILDCMDS
|
||||
endef
|
||||
all: prebuild prelink $(TARGET)
|
||||
@:
|
||||
|
||||
endif
|
||||
|
||||
OBJECTS := \
|
||||
$(OBJDIR)/sse.o \
|
||||
$(OBJDIR)/complex.o \
|
||||
$(OBJDIR)/math.o \
|
||||
$(OBJDIR)/avx2.o \
|
||||
$(OBJDIR)/naive.o \
|
||||
$(OBJDIR)/sse1.o \
|
||||
$(OBJDIR)/model.o \
|
||||
|
||||
RESOURCES := \
|
||||
|
||||
CUSTOMFILES := \
|
||||
|
||||
SHELLTYPE := posix
|
||||
ifeq (.exe,$(findstring .exe,$(ComSpec)))
|
||||
SHELLTYPE := msdos
|
||||
endif
|
||||
|
||||
$(TARGET): $(GCH) ${CUSTOMFILES} $(OBJECTS) $(LDDEPS) $(RESOURCES) | $(TARGETDIR)
|
||||
@echo Linking sse
|
||||
$(SILENT) $(LINKCMD)
|
||||
$(POSTBUILDCMDS)
|
||||
|
||||
$(CUSTOMFILES): | $(OBJDIR)
|
||||
|
||||
$(TARGETDIR):
|
||||
@echo Creating $(TARGETDIR)
|
||||
ifeq (posix,$(SHELLTYPE))
|
||||
$(SILENT) mkdir -p $(TARGETDIR)
|
||||
else
|
||||
$(SILENT) mkdir $(subst /,\\,$(TARGETDIR))
|
||||
endif
|
||||
|
||||
$(OBJDIR):
|
||||
@echo Creating $(OBJDIR)
|
||||
ifeq (posix,$(SHELLTYPE))
|
||||
$(SILENT) mkdir -p $(OBJDIR)
|
||||
else
|
||||
$(SILENT) mkdir $(subst /,\\,$(OBJDIR))
|
||||
endif
|
||||
|
||||
clean:
|
||||
@echo Cleaning sse
|
||||
ifeq (posix,$(SHELLTYPE))
|
||||
$(SILENT) rm -f $(TARGET)
|
||||
$(SILENT) rm -rf $(OBJDIR)
|
||||
else
|
||||
$(SILENT) if exist $(subst /,\\,$(TARGET)) del $(subst /,\\,$(TARGET))
|
||||
$(SILENT) if exist $(subst /,\\,$(OBJDIR)) rmdir /s /q $(subst /,\\,$(OBJDIR))
|
||||
endif
|
||||
|
||||
prebuild:
|
||||
$(PREBUILDCMDS)
|
||||
|
||||
prelink:
|
||||
$(PRELINKCMDS)
|
||||
|
||||
ifneq (,$(PCH))
|
||||
$(OBJECTS): $(GCH) $(PCH) | $(OBJDIR)
|
||||
$(GCH): $(PCH) | $(OBJDIR)
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) -x c++-header $(ALL_CXXFLAGS) -o "$@" -MF "$(@:%.gch=%.d)" -c "$<"
|
||||
else
|
||||
$(OBJECTS): | $(OBJDIR)
|
||||
endif
|
||||
|
||||
$(OBJDIR)/sse.o: ../app/sse.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/complex.o: ../src/bmath/complex.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/math.o: ../src/bmath/math.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/avx2.o: ../src/cpu/avx2.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/naive.o: ../src/cpu/naive.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/sse1.o: ../src/cpu/x86/sse.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
$(OBJDIR)/model.o: ../src/misc/memory/model.cpp
|
||||
@echo $(notdir $<)
|
||||
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
||||
|
||||
-include $(OBJECTS:%.o=%.d)
|
||||
ifneq (,$(PCH))
|
||||
-include $(OBJDIR)/$(notdir $(PCH)).d
|
||||
endif
|
40
premake5.lua
40
premake5.lua
|
@ -2,41 +2,5 @@ workspace "CppLib"
|
|||
configurations {"Debug", "Release" }
|
||||
system "linux"
|
||||
|
||||
project "CppCmds"
|
||||
kind "ConsoleApp"
|
||||
language "c++"
|
||||
targetdir "bin/%{cfg.buildcfg}"
|
||||
|
||||
files {"**.hpp","**.cpp"}
|
||||
|
||||
filter "configurations:Debug"
|
||||
defines { "DEBUG" }
|
||||
symbols "On"
|
||||
|
||||
filter "configurations:Release"
|
||||
defines { "NDEBUG" }
|
||||
optimize "On"
|
||||
|
||||
filter { "system:linux" }
|
||||
links {
|
||||
"wx_gtk3u_xrc-3.0",
|
||||
"wx_gtk3u_html-3.0",
|
||||
"wx_gtk3u_adv-3.0",
|
||||
"wx_gtk3u_core-3.0" ,
|
||||
"wx_baseu_xml-3.0",
|
||||
"wx_baseu_net-3.0",
|
||||
"wx_baseu-3.0",
|
||||
"glfw3"
|
||||
}
|
||||
includedirs {
|
||||
"/usr/lib/x86_64-linux-gnu/wx/include/gtk3-unicode-3.0" ,
|
||||
"/usr/include/wx-3.0"
|
||||
}
|
||||
defines {
|
||||
"_FILE_OFFSET_BITS=64",
|
||||
"WXUSINGDLL",
|
||||
"__WXGTK__"
|
||||
}
|
||||
|
||||
|
||||
|
||||
include("premake/sse.lua")
|
||||
include("premake/libbmath.lua")
|
|
@ -1,11 +1,11 @@
|
|||
#pragma once
|
||||
namespace cpu
|
||||
{
|
||||
class avx2
|
||||
{
|
||||
public:
|
||||
static int const AVX2_INT_SIZE = 16;
|
||||
static void avx_sum(int *a, int *b);
|
||||
static void printAVX2Num(int *num);
|
||||
};
|
||||
class avx2
|
||||
{
|
||||
public:
|
||||
static int const AVX2_INT_SIZE = 16;
|
||||
static void avx_sum(int *a, int *b);
|
||||
static void printAVX2Num(int *num);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -11,8 +11,8 @@ void cpu::Naive::sum_128_long(UInt *a,UInt *b){
|
|||
a1=a1+b1;
|
||||
a2=a2+b2;
|
||||
|
||||
a[0]=a1>>32;
|
||||
a[1]=a1;
|
||||
a[2]=a2>>32;
|
||||
a[3]=a2;
|
||||
a[0]=(UInt)a1;
|
||||
a[1]=(UInt)(a1>>32);
|
||||
a[2]=(UInt)a2;
|
||||
a[3]=(UInt)(a2>>32);
|
||||
};
|
|
@ -3,10 +3,10 @@
|
|||
#include "types.hpp"
|
||||
namespace cpu
|
||||
{
|
||||
class Naive
|
||||
{
|
||||
public:
|
||||
//Methods
|
||||
static void sum_128_long(UInt *a, UInt *b);
|
||||
};
|
||||
class Naive
|
||||
{
|
||||
public:
|
||||
// Methods
|
||||
static void sum_128_long(UInt *a, UInt *b);
|
||||
};
|
||||
};
|
13
src/cpu/simd.hpp
Normal file
13
src/cpu/simd.hpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include "types.hpp"
|
||||
|
||||
namespace cpu
|
||||
{
|
||||
class SIMD
|
||||
{
|
||||
public:
|
||||
virtual void add_128(UInt *a, UInt *b)=0;
|
||||
virtual void add_128(ULong *a, ULong *b)=0;
|
||||
};
|
||||
};
|
|
@ -1,14 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "types.hpp"
|
||||
|
||||
|
||||
namespace cpu
|
||||
{
|
||||
class SSE
|
||||
{
|
||||
public:
|
||||
static void paddw(UInt *a, UInt *b);
|
||||
static void paddd(ULong *a, ULong *b);
|
||||
};
|
||||
};
|
|
@ -1,58 +1,64 @@
|
|||
#pragma once
|
||||
|
||||
#include "../platform/platform.hpp"
|
||||
/*
|
||||
* Types for x86 architectures
|
||||
*/
|
||||
#if defined(__x86_64__)
|
||||
//Signed type alias
|
||||
typedef int Int;
|
||||
typedef long Long;
|
||||
typedef char Char;
|
||||
typedef short Short;
|
||||
* 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
|
||||
typedef union
|
||||
{
|
||||
Int value : 31;
|
||||
Int signal : 1;
|
||||
} int_with_msb;
|
||||
Int signed_int;
|
||||
} SignedInt;
|
||||
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;
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
Long value : 63;
|
||||
Int signal : 1;
|
||||
} long_with_msb;
|
||||
} SignedLong;
|
||||
|
||||
//IEEE floating point alias
|
||||
typedef float Float;
|
||||
typedef double Double;
|
||||
// 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 ULong;
|
||||
// Unsigned type alias
|
||||
typedef unsigned char UChar;
|
||||
typedef unsigned short UShort;
|
||||
typedef unsigned int UInt;
|
||||
typedef unsigned long ULong;
|
||||
|
||||
//SSE DataTypes
|
||||
#define INT_LEN_64 2
|
||||
#define INT_LEN_128 4
|
||||
#define INT_LEN_256 8
|
||||
#define INT_LEN_512 16
|
||||
// SSE DataTypes
|
||||
#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
|
||||
#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
|
||||
// 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
|
||||
|
||||
//Shifts
|
||||
#define SHIFT_32 32
|
||||
#define SHIFT_16 16
|
||||
#define SHIFT_8 8
|
||||
#endif
|
|
@ -7,44 +7,44 @@ using namespace std;
|
|||
|
||||
namespace cpu
|
||||
{
|
||||
class Utils
|
||||
{
|
||||
public:
|
||||
template <typename Number>
|
||||
static void printHex(Number *num, Int len)
|
||||
class Utils
|
||||
{
|
||||
for (int i = 0; i < len; i++)
|
||||
public:
|
||||
template <typename Number>
|
||||
static void printHex(Number *num, Int len)
|
||||
{
|
||||
cout << hex << num[i];
|
||||
if (i < len - 1)
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
cout << ",";
|
||||
cout << hex << num[i];
|
||||
if (i < len - 1)
|
||||
{
|
||||
cout << ",";
|
||||
}
|
||||
}
|
||||
}
|
||||
cout << std::dec << endl;
|
||||
};
|
||||
cout << std::dec << endl;
|
||||
};
|
||||
|
||||
/**
|
||||
* Utility method to convert a packaged 128bit int to 128bit long
|
||||
*/
|
||||
static void int128BitToLong(UInt *packedUInteger, ULong *packedULong)
|
||||
{
|
||||
packedULong[0] = (ULong)packedUInteger[1] << 32 | packedUInteger[0];
|
||||
packedULong[1] = (ULong)packedUInteger[3] << 32 | packedUInteger[2];
|
||||
};
|
||||
/**
|
||||
* Utility method to convert a packaged 128bit int to 128bit long
|
||||
*/
|
||||
static void int128BitToLong(UInt *packedUInteger, ULong *packedULong)
|
||||
{
|
||||
packedULong[0] = (ULong)packedUInteger[1] << 32 | packedUInteger[0];
|
||||
packedULong[1] = (ULong)packedUInteger[3] << 32 | packedUInteger[2];
|
||||
};
|
||||
|
||||
/**
|
||||
* Utility method to convert a packed 128bit long into a 128 int
|
||||
*/
|
||||
static void long128BitToInt(ULong *packedULong, UInt *packedUInteger)
|
||||
{
|
||||
//Unpack first long
|
||||
packedUInteger[0] = packedULong[0] & MASK_32;
|
||||
packedUInteger[1] = packedULong[0] >> SHIFT_32;
|
||||
/**
|
||||
* Utility method to convert a packed 128bit long into a 128 int
|
||||
*/
|
||||
static void long128BitToInt(ULong *packedULong, UInt *packedUInteger)
|
||||
{
|
||||
// Unpack first long
|
||||
packedUInteger[0] = packedULong[0] & MASK_32;
|
||||
packedUInteger[1] = packedULong[0] >> SHIFT_32;
|
||||
|
||||
//Unpack second long
|
||||
packedUInteger[2] = packedULong[1] & MASK_32;
|
||||
packedUInteger[3] = packedULong[1] >> SHIFT_32;
|
||||
// Unpack second long
|
||||
packedUInteger[2] = packedULong[1] & MASK_32;
|
||||
packedUInteger[3] = packedULong[1] >> SHIFT_32;
|
||||
};
|
||||
};
|
||||
};
|
||||
}; // namespace Cpu
|
|
@ -1,8 +1,9 @@
|
|||
#include "sse.hpp"
|
||||
#ifdef ARCH_X86
|
||||
#include <iostream>
|
||||
|
||||
//X86 Assembly to add two 128 bit numbers in the form of packed integers 32bit
|
||||
void cpu::SSE::paddw(UInt *a,UInt *b) {
|
||||
void cpu::SSE::add_128(UInt *a,UInt *b) {
|
||||
asm(
|
||||
"movdqa %0, %%xmm1\n"
|
||||
"paddw %1, %%xmm1\n"
|
||||
|
@ -14,7 +15,7 @@ void cpu::SSE::paddw(UInt *a,UInt *b) {
|
|||
|
||||
|
||||
//X86 Assembly to add two 128 bit numbers in the form of packed long 64bit
|
||||
void cpu::SSE::paddd(ULong *a,ULong *b) {
|
||||
void cpu::SSE::add_128(ULong *a,ULong *b) {
|
||||
asm(
|
||||
"movdqa %0, %%xmm1\n"
|
||||
"paddd %1, %%xmm1\n"
|
||||
|
@ -22,4 +23,5 @@ void cpu::SSE::paddd(ULong *a,ULong *b) {
|
|||
: "=m"(*a)
|
||||
: "m"(*b)
|
||||
);
|
||||
};
|
||||
};
|
||||
#endif
|
18
src/cpu/x86/sse.hpp
Normal file
18
src/cpu/x86/sse.hpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include "../../platform/platform.hpp"
|
||||
|
||||
#ifdef ARCH_X86
|
||||
#include "../types.hpp"
|
||||
#include "../simd.hpp"
|
||||
|
||||
namespace cpu
|
||||
{
|
||||
class SSE: public SIMD
|
||||
{
|
||||
public:
|
||||
void add_128(UInt *a, UInt *b);
|
||||
void add_128(ULong *a, ULong *b);
|
||||
};
|
||||
};
|
||||
#endif
|
|
@ -73,31 +73,4 @@ void printPointByRef(Point2D<Number> *point){
|
|||
template <typename Object>
|
||||
void printBoxContent(Box<Object> box){
|
||||
print("Box: Content: " << *box << ":" << box << ":" << box.getRefCounter())
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
print("Stack memory management")
|
||||
Point2D<int> p1={1,2};
|
||||
printPointByValue(p1);
|
||||
print("")
|
||||
|
||||
print("Heap memory management")
|
||||
Point2D<int> *p2 = new Point2D<int>{3, 4};
|
||||
printPointByRef(p2);
|
||||
delete p2;
|
||||
print("")
|
||||
|
||||
print("Heap/Stack memory management")
|
||||
Point2D<int> *ptrPt3 = new Point2D<int>(10,20);
|
||||
Box<Point2D<int>> box1(ptrPt3);
|
||||
print(box1)
|
||||
print("")print("")
|
||||
|
||||
printBoxContent(box1);
|
||||
Box<Point2D<int>> box2=box1;
|
||||
printBoxContent(box2);
|
||||
Atomic<int> atomic_int(12);
|
||||
|
||||
return 0;
|
||||
}
|
19
src/platform/platform.hpp
Normal file
19
src/platform/platform.hpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
// Check for architecture
|
||||
#ifdef __i386
|
||||
#define ARCH_X86
|
||||
#endif
|
||||
|
||||
#ifdef __x86__
|
||||
#define ARCH_X86
|
||||
#endif
|
||||
|
||||
#ifdef __x64__
|
||||
#define ARCH_X86
|
||||
#endif
|
||||
|
||||
#ifdef __x86_64__
|
||||
#define ARCH_X86
|
||||
#endif
|
||||
|
Loading…
Reference in a new issue