diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-12-23 01:31:10 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-12-23 01:48:42 +0300 |
commit | f3ebfff841aafc0aac6186243606e1b2ea381e71 (patch) | |
tree | e32fb5267f9776c460e7e38d0e544fed383d25e7 /src | |
parent | 1129a3f3047fc5acd917e9a352b0e266677e0640 (diff) | |
download | manaplus-f3ebfff841aafc0aac6186243606e1b2ea381e71.tar.gz manaplus-f3ebfff841aafc0aac6186243606e1b2ea381e71.tar.bz2 manaplus-f3ebfff841aafc0aac6186243606e1b2ea381e71.tar.xz manaplus-f3ebfff841aafc0aac6186243606e1b2ea381e71.zip |
Add a color dye function for sse2 (software).
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/resources/dye/dyepalette.h | 34 | ||||
-rw-r--r-- | src/resources/dye/dyepalette_replaceacolor.cpp | 189 | ||||
-rw-r--r-- | src/resources/dye/dyepalette_replaceacolor_avx2.hpp | 85 | ||||
-rw-r--r-- | src/resources/dye/dyepalette_replaceacolor_default.hpp | 109 | ||||
-rw-r--r-- | src/resources/dye/dyepalette_replaceacolor_sse2.hpp | 85 | ||||
-rw-r--r-- | src/test/testlauncher.cpp | 106 |
8 files changed, 395 insertions, 219 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 98b8f9d98..71558ca39 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -644,6 +644,9 @@ SET(SRCS resources/dye/dyepalette.cpp resources/dye/dyepalette.h resources/dye/dyepalette_replaceacolor.cpp + resources/dye/dyepalette_replaceacolor_avx2.hpp + resources/dye/dyepalette_replaceacolor_default.hpp + resources/dye/dyepalette_replaceacolor_sse2.hpp resources/dye/dyepalette_replaceaoglcolor.cpp resources/dye/dyepalette_replacescolor.cpp resources/dye/dyepalette_replacesoglcolor.cpp diff --git a/src/Makefile.am b/src/Makefile.am index ea40cb1ba..cbf3ae4b3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -366,6 +366,9 @@ SRC += events/actionevent.h \ resources/dye/dyepalette.cpp \ resources/dye/dyepalette.h \ resources/dye/dyepalette_replaceacolor.cpp \ + resources/dye/dyepalette_replaceacolor_avx2.hpp \ + resources/dye/dyepalette_replaceacolor_default.hpp \ + resources/dye/dyepalette_replaceacolor_sse2.hpp \ resources/dye/dyepalette_replaceaoglcolor.cpp \ resources/dye/dyepalette_replacescolor.cpp \ resources/dye/dyepalette_replacesoglcolor.cpp \ diff --git a/src/resources/dye/dyepalette.h b/src/resources/dye/dyepalette.h index 4cbfa3efc..19a406097 100644 --- a/src/resources/dye/dyepalette.h +++ b/src/resources/dye/dyepalette.h @@ -106,13 +106,47 @@ class DyePalette final void replaceAColorSimd(uint32_t *restrict pixels, const int bufSize) const restrict2; + /** + * replace colors for SDL for A dye. + */ + FUNCTION_SIMD_DEFAULT + void replaceAColorSse2(uint32_t *restrict pixels, + const int bufSize) const restrict2; + + /** + * replace colors for SDL for A dye. + */ + FUNCTION_SIMD_DEFAULT + void replaceAColorAvx2(uint32_t *restrict pixels, + const int bufSize) const restrict2; + #ifdef SIMD_SUPPORTED /** * replace colors for SDL for A dye. */ + __attribute__ ((target ("sse2"))) + void replaceAColorSimd(uint32_t *restrict pixels, + const int bufSize) const restrict2; + + /** + * replace colors for SDL for A dye. + */ __attribute__ ((target ("avx2"))) void replaceAColorSimd(uint32_t *restrict pixels, const int bufSize) const restrict2; + /** + * replace colors for SDL for A dye. + */ + __attribute__ ((target ("sse2"))) + void replaceAColorSse2(uint32_t *restrict pixels, + const int bufSize) const restrict2; + + /** + * replace colors for SDL for A dye. + */ + __attribute__ ((target ("avx2"))) + void replaceAColorAvx2(uint32_t *restrict pixels, + const int bufSize) const restrict2; #endif // SIMD_SUPPORTED #ifdef USE_OPENGL diff --git a/src/resources/dye/dyepalette_replaceacolor.cpp b/src/resources/dye/dyepalette_replaceacolor.cpp index b2693912b..b5b77f770 100644 --- a/src/resources/dye/dyepalette_replaceacolor.cpp +++ b/src/resources/dye/dyepalette_replaceacolor.cpp @@ -39,100 +39,14 @@ void DyePalette::replaceAColor(uint32_t *restrict pixels, #ifdef SIMD_SUPPORTED replaceAColorSimd(pixels, bufSize); #else // SIMD_SUPPORTED - replaceAColorDefault(pixels, bufSize); +#include "resources/dye/dyepalette_replaceacolor_default.hpp" #endif // SIMD_SUPPORTED } void DyePalette::replaceAColorDefault(uint32_t *restrict pixels, const int bufSize) const restrict2 { - std::vector<DyeColor>::const_iterator it_end = mColors.end(); - const size_t sz = mColors.size(); - if (!sz || !pixels) - return; - if (sz % 2) - -- it_end; - -#ifdef ENABLE_CILKPLUS - cilk_for (int ptr = 0; ptr < bufSize; ptr ++) - { - uint8_t *const p = reinterpret_cast<uint8_t *>(&pixels[ptr]); - const unsigned int data = pixels[ptr]; - - std::vector<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[3] << 24U) - | (col.value[2] << 16U) - | (col.value[1] << 8U) - | (col.value[0]); -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int coldata = (col.value[3]) - | (col.value[2] << 8U) - | (col.value[1] << 16U) | - (col.value[0] << 24U); -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (data == coldata) - { - p[3] = col2.value[0]; - p[2] = col2.value[1]; - p[1] = col2.value[2]; - p[0] = col2.value[3]; - break; - } - - ++ it; - } - } - -#else // ENABLE_CILKPLUS - - for (const uint32_t *const p_end = pixels + CAST_SIZE(bufSize); - pixels != p_end; - ++pixels) - { - uint8_t *const p = reinterpret_cast<uint8_t *>(pixels); - const unsigned int data = *pixels; - - std::vector<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[3] << 24U) - | (col.value[2] << 16U) - | (col.value[1] << 8U) - | (col.value[0]); -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[3]) - | (col.value[2] << 8U) - | (col.value[1] << 16U) | - (col.value[0] << 24U); -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (data == coldata) - { - p[3] = col2.value[0]; - p[2] = col2.value[1]; - p[1] = col2.value[2]; - p[0] = col2.value[3]; - break; - } - - ++ it; - } - } -#endif // ENABLE_CILKPLUS +#include "resources/dye/dyepalette_replaceacolor_default.hpp" } #ifdef SIMD_SUPPORTED @@ -144,75 +58,32 @@ static void print256(const char *const text, const __m256i &val) } */ -__attribute__ ((target ("avx2"))) +__attribute__ ((target ("sse2"))) void DyePalette::replaceAColorSimd(uint32_t *restrict pixels, const int bufSize) const restrict2 { - std::vector<DyeColor>::const_iterator it_end = mColors.end(); - const size_t sz = mColors.size(); - if (!sz || !pixels) - return; - if (sz % 2) - -- it_end; - const int mod = bufSize % 8; - const int bufEnd = bufSize - mod; - - for (int ptr = 0; ptr < bufEnd; ptr += 8) - { -// __m256i base = _mm256_load_si256(reinterpret_cast<__m256i*>(pixels)); - __m256i base = _mm256_loadu_si256(reinterpret_cast<__m256i*>( - &pixels[ptr])); - - std::vector<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - - __m256i newMask = _mm256_set1_epi32(col2.valueA); - __m256i cmpMask = _mm256_set1_epi32(col.valueA); - __m256i cmpRes = _mm256_cmpeq_epi32(base, cmpMask); - __m256i srcAnd = _mm256_andnot_si256(cmpRes, base); - __m256i dstAnd = _mm256_and_si256(cmpRes, newMask); - base = _mm256_or_si256(srcAnd, dstAnd); - - ++ it; - } -// _mm256_store_si256(reinterpret_cast<__m256i*>(pixels), base); - _mm256_storeu_si256(reinterpret_cast<__m256i*>(&pixels[ptr]), base); - } - - // complete end without simd - for (int ptr = bufSize - mod; ptr < bufSize; ptr ++) - { - uint8_t *const p = reinterpret_cast<uint8_t *>(&pixels[ptr]); - const unsigned int data = pixels[ptr]; - - std::vector<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; +#include "resources/dye/dyepalette_replaceacolor_sse2.hpp" +} - const unsigned int coldata = (col.value[3]) | - (col.value[2] << 8U) | - (col.value[1] << 16U) | - (col.value[0] << 24U); +__attribute__ ((target ("avx2"))) +void DyePalette::replaceAColorSimd(uint32_t *restrict pixels, + const int bufSize) const restrict2 +{ +#include "resources/dye/dyepalette_replaceacolor_avx2.hpp" +} - if (data == coldata) - { - p[3] = col2.value[0]; - p[2] = col2.value[1]; - p[1] = col2.value[2]; - p[0] = col2.value[3]; - break; - } +__attribute__ ((target ("sse2"))) +void DyePalette::replaceAColorSse2(uint32_t *restrict pixels, + const int bufSize) const restrict2 +{ +#include "resources/dye/dyepalette_replaceacolor_sse2.hpp" +} - ++ it; - } - } +__attribute__ ((target ("avx2"))) +void DyePalette::replaceAColorAvx2(uint32_t *restrict pixels, + const int bufSize) const restrict2 +{ +#include "resources/dye/dyepalette_replaceacolor_avx2.hpp" } #endif // SIMD_SUPPORTED @@ -221,5 +92,19 @@ FUNCTION_SIMD_DEFAULT void DyePalette::replaceAColorSimd(uint32_t *restrict pixels, const int bufSize) const restrict2 { - replaceAColorDefault(pixels, bufSize); +#include "resources/dye/dyepalette_replaceacolor_default.hpp" +} + +FUNCTION_SIMD_DEFAULT +void DyePalette::replaceAColorSse2(uint32_t *restrict pixels, + const int bufSize) const restrict2 +{ +#include "resources/dye/dyepalette_replaceacolor_default.hpp" +} + +FUNCTION_SIMD_DEFAULT +void DyePalette::replaceAColorAvx2(uint32_t *restrict pixels, + const int bufSize) const restrict2 +{ +#include "resources/dye/dyepalette_replaceacolor_default.hpp" } diff --git a/src/resources/dye/dyepalette_replaceacolor_avx2.hpp b/src/resources/dye/dyepalette_replaceacolor_avx2.hpp new file mode 100644 index 000000000..4fdb403b8 --- /dev/null +++ b/src/resources/dye/dyepalette_replaceacolor_avx2.hpp @@ -0,0 +1,85 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2016 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + std::vector<DyeColor>::const_iterator it_end = mColors.end(); + const size_t sz = mColors.size(); + if (!sz || !pixels) + return; + if (sz % 2) + -- it_end; + const int mod = bufSize % 8; + const int bufEnd = bufSize - mod; + + for (int ptr = 0; ptr < bufEnd; ptr += 8) + { +// __m256i base = _mm256_load_si256(reinterpret_cast<__m256i*>(pixels)); + __m256i base = _mm256_loadu_si256(reinterpret_cast<__m256i*>( + &pixels[ptr])); + + std::vector<DyeColor>::const_iterator it = mColors.begin(); + while (it != it_end) + { + const DyeColor &col = *it; + ++ it; + const DyeColor &col2 = *it; + + __m256i newMask = _mm256_set1_epi32(col2.valueA); + __m256i cmpMask = _mm256_set1_epi32(col.valueA); + __m256i cmpRes = _mm256_cmpeq_epi32(base, cmpMask); + __m256i srcAnd = _mm256_andnot_si256(cmpRes, base); + __m256i dstAnd = _mm256_and_si256(cmpRes, newMask); + base = _mm256_or_si256(srcAnd, dstAnd); + + ++ it; + } +// _mm256_store_si256(reinterpret_cast<__m256i*>(pixels), base); + _mm256_storeu_si256(reinterpret_cast<__m256i*>(&pixels[ptr]), base); + } + + // complete end without simd + for (int ptr = bufSize - mod; ptr < bufSize; ptr ++) + { + uint8_t *const p = reinterpret_cast<uint8_t *>(&pixels[ptr]); + const unsigned int data = pixels[ptr]; + + std::vector<DyeColor>::const_iterator it = mColors.begin(); + while (it != it_end) + { + const DyeColor &col = *it; + ++ it; + const DyeColor &col2 = *it; + + const unsigned int coldata = (col.value[3]) | + (col.value[2] << 8U) | + (col.value[1] << 16U) | + (col.value[0] << 24U); + + if (data == coldata) + { + p[3] = col2.value[0]; + p[2] = col2.value[1]; + p[1] = col2.value[2]; + p[0] = col2.value[3]; + break; + } + + ++ it; + } + } diff --git a/src/resources/dye/dyepalette_replaceacolor_default.hpp b/src/resources/dye/dyepalette_replaceacolor_default.hpp new file mode 100644 index 000000000..cbe01a50d --- /dev/null +++ b/src/resources/dye/dyepalette_replaceacolor_default.hpp @@ -0,0 +1,109 @@ +/* + * The ManaPlus Client + * Copyright (C) 2007-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2016 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + std::vector<DyeColor>::const_iterator it_end = mColors.end(); + const size_t sz = mColors.size(); + if (!sz || !pixels) + return; + if (sz % 2) + -- it_end; + +#ifdef ENABLE_CILKPLUS + cilk_for (int ptr = 0; ptr < bufSize; ptr ++) + { + uint8_t *const p = reinterpret_cast<uint8_t *>(&pixels[ptr]); + const unsigned int data = pixels[ptr]; + + std::vector<DyeColor>::const_iterator it = mColors.begin(); + while (it != it_end) + { + const DyeColor &col = *it; + ++ it; + const DyeColor &col2 = *it; + +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + const unsigned int coldata = (col.value[3] << 24U) + | (col.value[2] << 16U) + | (col.value[1] << 8U) + | (col.value[0]); +#else // SDL_BYTEORDER == SDL_BIG_ENDIAN + + const unsigned int coldata = (col.value[3]) + | (col.value[2] << 8U) + | (col.value[1] << 16U) | + (col.value[0] << 24U); +#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN + + if (data == coldata) + { + p[3] = col2.value[0]; + p[2] = col2.value[1]; + p[1] = col2.value[2]; + p[0] = col2.value[3]; + break; + } + + ++ it; + } + } + +#else // ENABLE_CILKPLUS + + for (const uint32_t *const p_end = pixels + CAST_SIZE(bufSize); + pixels != p_end; + ++pixels) + { + uint8_t *const p = reinterpret_cast<uint8_t *>(pixels); + const unsigned int data = *pixels; + + std::vector<DyeColor>::const_iterator it = mColors.begin(); + while (it != it_end) + { + const DyeColor &col = *it; + ++ it; + const DyeColor &col2 = *it; + +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + const unsigned int coldata = (col.value[3] << 24U) + | (col.value[2] << 16U) + | (col.value[1] << 8U) + | (col.value[0]); +#else // SDL_BYTEORDER == SDL_BIG_ENDIAN + const unsigned int coldata = (col.value[3]) + | (col.value[2] << 8U) + | (col.value[1] << 16U) | + (col.value[0] << 24U); +#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN + + if (data == coldata) + { + p[3] = col2.value[0]; + p[2] = col2.value[1]; + p[1] = col2.value[2]; + p[0] = col2.value[3]; + break; + } + + ++ it; + } + } +#endif // ENABLE_CILKPLUS diff --git a/src/resources/dye/dyepalette_replaceacolor_sse2.hpp b/src/resources/dye/dyepalette_replaceacolor_sse2.hpp new file mode 100644 index 000000000..98aadae57 --- /dev/null +++ b/src/resources/dye/dyepalette_replaceacolor_sse2.hpp @@ -0,0 +1,85 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2016 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + std::vector<DyeColor>::const_iterator it_end = mColors.end(); + const size_t sz = mColors.size(); + if (!sz || !pixels) + return; + if (sz % 2) + -- it_end; + const int mod = bufSize % 4; + const int bufEnd = bufSize - mod; + + for (int ptr = 0; ptr < bufEnd; ptr += 4) + { +// __m128i base = _mm_load_si128(reinterpret_cast<__m128i*>(pixels)); + __m128i base = _mm_loadu_si128(reinterpret_cast<__m128i*>( + &pixels[ptr])); + + std::vector<DyeColor>::const_iterator it = mColors.begin(); + while (it != it_end) + { + const DyeColor &col = *it; + ++ it; + const DyeColor &col2 = *it; + + __m128i newMask = _mm_set1_epi32(col2.valueA); + __m128i cmpMask = _mm_set1_epi32(col.valueA); + __m128i cmpRes = _mm_cmpeq_epi32(base, cmpMask); + __m128i srcAnd = _mm_andnot_si128(cmpRes, base); + __m128i dstAnd = _mm_and_si128(cmpRes, newMask); + base = _mm_or_si128(srcAnd, dstAnd); + + ++ it; + } +// _mm_store_si128(reinterpret_cast<__m128i*>(pixels), base); + _mm_storeu_si128(reinterpret_cast<__m128i*>(&pixels[ptr]), base); + } + + // complete end without simd + for (int ptr = bufSize - mod; ptr < bufSize; ptr ++) + { + uint8_t *const p = reinterpret_cast<uint8_t *>(&pixels[ptr]); + const unsigned int data = pixels[ptr]; + + std::vector<DyeColor>::const_iterator it = mColors.begin(); + while (it != it_end) + { + const DyeColor &col = *it; + ++ it; + const DyeColor &col2 = *it; + + const unsigned int coldata = (col.value[3]) | + (col.value[2] << 8U) | + (col.value[1] << 16U) | + (col.value[0] << 24U); + + if (data == coldata) + { + p[3] = col2.value[0]; + p[2] = col2.value[1]; + p[1] = col2.value[2]; + p[0] = col2.value[3]; + break; + } + + ++ it; + } + } diff --git a/src/test/testlauncher.cpp b/src/test/testlauncher.cpp index 661960b1d..bd0908a73 100644 --- a/src/test/testlauncher.cpp +++ b/src/test/testlauncher.cpp @@ -479,51 +479,55 @@ int TestLauncher::testDye() return 0; } -int TestLauncher::testDyeSSpeed() -{ #if defined __linux__ || defined __linux - const int sz = 100000; - uint32_t buf[sz]; - timespec time1; - timespec time2; - - DyePalette pal("#0000ff,000000,000020,706050", 6); - +static void initBuffer(uint32_t *const buf, + const int sz) +{ for (int f = 0; f < sz; f ++) buf[f] = f; +} - pal.replaceSColor(buf, sz); - - clock_gettime(CLOCK_MONOTONIC, &time1); - - for (int f = 0; f < 50000; f ++) - pal.replaceSColorDefault(buf, sz); - +static void calcTime(const char *const msg1, + const char *const msg2, + timespec &time1, + timespec &time2, + uint32_t *const buf) +{ clock_gettime(CLOCK_MONOTONIC, &time2); long diff = ((static_cast<long int>(time2.tv_sec) * 1000000000L + static_cast<long int>(time2.tv_nsec)) / 1) - ((static_cast<long int>(time1.tv_sec) * 1000000000L + static_cast<long int>(time1.tv_nsec)) / 1); - printf("dye s salt: %u\n", buf[0]); - printf("default time: %011ld\n", diff); + printf("%s: %u\n", msg1, buf[0]); + printf("%s: %011ld\n", msg2, diff); +} - for (int f = 0; f < sz; f ++) - buf[f] = f; +#define runDyeTest(msg1, msg2, func) \ + initBuffer(buf, sz); \ + pal.func(buf, sz); \ + clock_gettime(CLOCK_MONOTONIC, &time1); \ + for (int f = 0; f < 50000; f ++) \ + pal.func(buf, sz); \ + calcTime(msg1, \ + msg2, \ + time1, \ + time2, \ + buf) - pal.replaceSColor(buf, sz); +#endif // defined __linux__ || defined __linux - clock_gettime(CLOCK_MONOTONIC, &time1); +int TestLauncher::testDyeSSpeed() +{ +#if defined __linux__ || defined __linux + const int sz = 100000; + uint32_t buf[sz]; + timespec time1; + timespec time2; - for (int f = 0; f < 50000; f ++) - pal.replaceSColorSimd(buf, sz); + DyePalette pal("#0000ff,000000,000020,706050", 6); - clock_gettime(CLOCK_MONOTONIC, &time2); - diff = ((static_cast<long int>(time2.tv_sec) * 1000000000L - + static_cast<long int>(time2.tv_nsec)) / 1) - - ((static_cast<long int>(time1.tv_sec) * 1000000000L - + static_cast<long int>(time1.tv_nsec)) / 1); - printf("dye s salt: %u\n", buf[0]); - printf("simd time : %011ld\n", diff); + runDyeTest("dye s salt", "default time", replaceSColorDefault); + runDyeTest("dye s salt", "simd time ", replaceSColorSimd); #endif // defined __linux__ || defined __linux return 0; @@ -539,42 +543,10 @@ int TestLauncher::testDyeASpeed() DyePalette pal("#0000ffff,00000000,000020ff,70605040", 8); - for (int f = 0; f < sz; f ++) - buf[f] = f; - - pal.replaceAColor(buf, sz); - - clock_gettime(CLOCK_MONOTONIC, &time1); - - for (int f = 0; f < 50000; f ++) - pal.replaceSColorDefault(buf, sz); - - clock_gettime(CLOCK_MONOTONIC, &time2); - long diff = ((static_cast<long int>(time2.tv_sec) * 1000000000L - + static_cast<long int>(time2.tv_nsec)) / 1) - - ((static_cast<long int>(time1.tv_sec) * 1000000000L - + static_cast<long int>(time1.tv_nsec)) / 1); - printf("dye a salt: %u\n", buf[0]); - printf("default time: %011ld\n", diff); - - for (int f = 0; f < sz; f ++) - buf[f] = f; - - pal.replaceAColor(buf, sz); - - clock_gettime(CLOCK_MONOTONIC, &time1); - - for (int f = 0; f < 50000; f ++) - pal.replaceSColorSimd(buf, sz); - - clock_gettime(CLOCK_MONOTONIC, &time2); - diff = ((static_cast<long int>(time2.tv_sec) * 1000000000L - + static_cast<long int>(time2.tv_nsec)) / 1) - - ((static_cast<long int>(time1.tv_sec) * 1000000000L - + static_cast<long int>(time1.tv_nsec)) / 1); - printf("dye a salt: %u\n", buf[0]); - printf("simd time : %011ld\n", diff); - + runDyeTest("dye a salt", "default time", replaceAColorDefault); + runDyeTest("dye a salt", "simd time ", replaceAColorSimd); + runDyeTest("dye a salt", "sse2 time ", replaceAColorSse2); + runDyeTest("dye a salt", "avx2 time ", replaceAColorAvx2); #endif // defined __linux__ || defined __linux return 0; |