summaryrefslogtreecommitdiff
path: root/src/resources/dye/dyepalette.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources/dye/dyepalette.cpp')
-rw-r--r--src/resources/dye/dyepalette.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/resources/dye/dyepalette.cpp b/src/resources/dye/dyepalette.cpp
index dfe6e95a2..5a350c8e2 100644
--- a/src/resources/dye/dyepalette.cpp
+++ b/src/resources/dye/dyepalette.cpp
@@ -38,8 +38,16 @@
#include <SDL_endian.h>
#endif // SDL_BYTEORDER
+#ifdef SIMD_SUPPORTED
+#include "utils/cpu.h"
+#endif // SIMD_SUPPORTED
+
#include "debug.h"
+DyeFunctionPtr DyePalette::funcReplaceSColor = nullptr;
+DyeFunctionPtr DyePalette::funcReplaceSColorSse2 = nullptr;
+DyeFunctionPtr DyePalette::funcReplaceSColorAvx2 = nullptr;
+
DyePalette::DyePalette(const std::string &restrict description,
const uint8_t blockSize) :
mColors()
@@ -224,3 +232,28 @@ void DyePalette::getColor(double intensity,
color[2] = CAST_S32(rest * colorI.value[2] +
intensity * colorJ.value[2]);
}
+
+void DyePalette::initFunctions()
+{
+#ifdef SIMD_SUPPORTED
+ const uint32_t flags = Cpu::getFlags();
+ if (flags & Cpu::FEATURE_AVX2)
+ {
+ funcReplaceSColor = &DyePalette::replaceSColorAvx2;
+ funcReplaceSColorAvx2 = &DyePalette::replaceSColorAvx2;
+ funcReplaceSColorSse2 = &DyePalette::replaceSColorSse2;
+ }
+ else if (flags & Cpu::FEATURE_SSE2)
+ {
+ funcReplaceSColor = &DyePalette::replaceSColorSse2;
+ funcReplaceSColorAvx2 = &DyePalette::replaceSColorSse2;
+ funcReplaceSColorSse2 = &DyePalette::replaceSColorSse2;
+ }
+ else
+#endif // SIMD_SUPPORTED
+ {
+ funcReplaceSColor = &DyePalette::replaceSColorDefault;
+ funcReplaceSColorAvx2 = &DyePalette::replaceSColorDefault;
+ funcReplaceSColorSse2 = &DyePalette::replaceSColorDefault;
+ }
+}