Browse Source

(#90) Make SSE disablable

rexim 5 years ago
parent
commit
da3081815b
3 changed files with 22 additions and 7 deletions
  1. 7 1
      Makefile
  2. 2 0
      src/vodus.cpp
  3. 13 6
      src/vodus_image32.cpp

+ 7 - 1
Makefile

@@ -1,6 +1,12 @@
+VODUS_EXTRA_CXXFLAGS=
+
+ifdef VODUS_SSE
+VODUS_EXTRA_CXXFLAGS += -DVODUS_SSE -msse4
+endif
+
 # TODO(#87): we need an option to build with system libraries
 VODUS_PKGS=freetype2
-VODUS_CXXFLAGS=-Wall -fno-exceptions -std=c++17 -msse4 -ggdb `pkg-config --cflags $(VODUS_PKGS)` -I./third_party/ffmpeg-4.3-dist/usr/local/include/ -I./third_party/giflib-5.2.1-dist/usr/local/include/
+VODUS_CXXFLAGS=-Wall -fno-exceptions -std=c++17 $(VODUS_EXTRA_CXXFLAGS) -ggdb `pkg-config --cflags $(VODUS_PKGS)` -I./third_party/ffmpeg-4.3-dist/usr/local/include/ -I./third_party/giflib-5.2.1-dist/usr/local/include/
 VODUS_LIBS=`pkg-config --libs $(VODUS_PKGS)` -L./third_party/giflib-5.2.1-dist/usr/local/lib/ -l:libgif.a -L./third_party/ffmpeg-4.3-dist/usr/local/lib/ -lavcodec -lavutil -lswresample -pthread -lm -llzma -lz
 
 EMOTE_DOWNLOADER_PKGS=libcurl

+ 2 - 0
src/vodus.cpp

@@ -23,8 +23,10 @@ extern "C" {
 #include "./aids.hpp"
 using namespace aids;
 
+#ifdef VODUS_SSE
 #include <tmmintrin.h>
 #include <smmintrin.h>
+#endif // VODUS_SSE
 
 const size_t VODUS_MESSAGES_CAPACITY = 1024;
 

+ 13 - 6
src/vodus_image32.cpp

@@ -40,6 +40,7 @@ struct Animat32
     size_t count;
 };
 
+#ifdef VODUS_SSE
 // NOTE: Stolen from https://stackoverflow.com/a/53707227
 void mix_pixels_sse(Pixel32 *src, Pixel32 *dst, Pixel32 *c)
 {
@@ -116,6 +117,7 @@ void mix_pixels_sse(Pixel32 *src, Pixel32 *dst, Pixel32 *c)
 
     _mm_storeu_si128( (__m128i_u*) c, _ret );
 }
+#endif // VODUS_SSE
 
 Pixel32 mix_pixels(Pixel32 dst, Pixel32 src)
 {
@@ -160,7 +162,11 @@ void slap_ftbitmap_onto_image32(Image32 dest, FT_Bitmap *src, Pixel32 color, int
 void slap_image32_onto_image32(Image32 dst, Image32 src,
                                int x0, int y0)
 {
+#ifdef VODUS_SSE
     const size_t SIMD_PIXEL_PACK_SIZE = 4;
+#else
+    const size_t SIMD_PIXEL_PACK_SIZE = 1;
+#endif // VODUS_SSE
 
     size_t x1 = std::min(x0 + src.width, dst.width);
     size_t y1 = std::min(y0 + src.height, dst.height);
@@ -177,17 +183,18 @@ void slap_image32_onto_image32(Image32 dst, Image32 src,
             assert(x - x0 < src.width);
             assert(y - y0 < src.height);
 
-            // TODO(#90): SSE is not disablable
             // TODO(#91): SSE rendering is slightly different from non SSE version
+#ifdef VODUS_SSE
             mix_pixels_sse(
                 &src.pixels[(y - y0) * src.width + (x - x0)],
                 &dst.pixels[y * dst.width + x],
                 &dst.pixels[y * dst.width + x]);
-
-            // dst.pixels[y * dst.width + x] =
-            //     mix_pixels(
-            //         dst.pixels[y * dst.width + x],
-            //         src.pixels[(y - y0) * src.width + (x - x0)]);
+#else
+            dst.pixels[y * dst.width + x] =
+                mix_pixels(
+                    dst.pixels[y * dst.width + x],
+                    src.pixels[(y - y0) * src.width + (x - x0)]);
+#endif // VODUS_SSE
         }
     }
 }