commit 1b26a5d437e28b3cac0057ea084d608857270549
parent 82c85c8c84aa13d49cabbcc81264085f5a88beb1
Author: samuriddle@gmail.com <samuriddle@gmail.com>
Date: Sun, 7 Aug 2016 07:24:11 +0300
new test: multiarch
Diffstat:
4 files changed, 104 insertions(+), 3 deletions(-)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
@@ -19,18 +19,25 @@ cmake_minimum_required(VERSION 3.0)
if (NOT MSVC)
add_compile_options(-fno-exceptions -fno-rtti -ftemplate-backtrace-limit=0)
+ link_libraries(stdc++ pthread m)
+endif ()
+
+include_directories(../include)
+
+add_executable(multiarch multiarch.cpp multiarch_fir_sse2.cpp multiarch_fir_avx.cpp ${KFR_SRC})
+set_source_files_properties(multiarch_fir_sse2.cpp PROPERTIES COMPILE_FLAGS "-mno-avx -mno-sse3 -msse2")
+set_source_files_properties(multiarch_fir_avx.cpp PROPERTIES COMPILE_FLAGS -mavx)
+
+if (NOT MSVC)
if (NOT ARCH_FLAGS)
add_compile_options(-march=native)
else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARCH_FLAGS}")
endif ()
- link_libraries(stdc++ pthread m)
else ()
add_compile_options(/arch:AVX)
endif ()
-include_directories(../include)
-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/tests/cmake/")
find_package(MPFR)
@@ -70,5 +77,7 @@ add_test(NAME vec_test
COMMAND ${PROJECT_BINARY_DIR}/tests/vec_test)
add_test(NAME stat_test
COMMAND ${PROJECT_BINARY_DIR}/tests/stat_test)
+add_test(NAME multiarch
+ COMMAND ${PROJECT_BINARY_DIR}/tests/multiarch)
add_test(NAME dft_test
COMMAND ${PROJECT_BINARY_DIR}/tests/dft_test)
diff --git a/tests/multiarch.cpp b/tests/multiarch.cpp
@@ -0,0 +1,56 @@
+/**
+ * KFR (http://kfrlib.com)
+ * Copyright (C) 2016 D Levin
+ * See LICENSE.txt for details
+ */
+
+#include <kfr/io/tostring.hpp>
+
+#include "testo/testo.hpp"
+#include <kfr/dsp.hpp>
+
+using namespace kfr;
+
+cpu_t fir_sse2(univector<double, 0> data, univector<double, 4>& taps);
+cpu_t fir_avx(univector<double, 0> data, univector<double, 4>& taps);
+
+TEST(test_fir_sse2)
+{
+ univector<double, 8> data = counter();
+ univector<double, 4> taps({ 0.5, 1.0, 1.0, 0.5 });
+ cpu_t c = fir_sse2(data, taps);
+ CHECK(c == cpu_t::sse2);
+ CHECK(data[0] == 0);
+ CHECK(data[1] == 0.5);
+ CHECK(data[2] == 2);
+ CHECK(data[3] == 4.5);
+ CHECK(data[4] == 7.5);
+ CHECK(data[5] == 10.5);
+ CHECK(data[6] == 13.5);
+ CHECK(data[7] == 16.5);
+}
+
+TEST(test_fir_avx)
+{
+ if (get_cpu() >= cpu_t::avx1)
+ {
+ univector<double, 8> data = counter();
+ univector<double, 4> taps({ 0.5, 1.0, 1.0, 0.5 });
+ cpu_t c = fir_avx(data, taps);
+ CHECK(c == cpu_t::avx);
+ CHECK(data[0] == 0);
+ CHECK(data[1] == 0.5);
+ CHECK(data[2] == 2);
+ CHECK(data[3] == 4.5);
+ CHECK(data[4] == 7.5);
+ CHECK(data[5] == 10.5);
+ CHECK(data[6] == 13.5);
+ CHECK(data[7] == 16.5);
+ }
+ else
+ {
+ println("No AVX");
+ }
+}
+
+int main(int argc, char** argv) { return testo::run_all("", true); }
diff --git a/tests/multiarch_fir_avx.cpp b/tests/multiarch_fir_avx.cpp
@@ -0,0 +1,18 @@
+/**
+ * KFR (http://kfrlib.com)
+ * Copyright (C) 2016 D Levin
+ * See LICENSE.txt for details
+ */
+
+#include <kfr/dsp.hpp>
+#include <kfr/io/tostring.hpp>
+#include <kfr/version.hpp>
+
+using namespace kfr;
+
+cpu_t fir_avx(univector<double, 0> data, univector<double, 4>& taps)
+{
+ println(library_version());
+ data = short_fir(data, taps);
+ return cpu_t::native;
+}
diff --git a/tests/multiarch_fir_sse2.cpp b/tests/multiarch_fir_sse2.cpp
@@ -0,0 +1,18 @@
+/**
+ * KFR (http://kfrlib.com)
+ * Copyright (C) 2016 D Levin
+ * See LICENSE.txt for details
+ */
+
+#include <kfr/dsp.hpp>
+#include <kfr/io/tostring.hpp>
+#include <kfr/version.hpp>
+
+using namespace kfr;
+
+cpu_t fir_sse2(univector<double, 0> data, univector<double, 4>& taps)
+{
+ println(library_version());
+ data = short_fir(data, taps);
+ return cpu_t::native;
+}