瀏覽代碼

Don't enable SSE4 under Emscripten (#8213, #8169, #4933)

Amend 326dc95f9
slowriot 9 月之前
父節點
當前提交
2671f68f7f
共有 2 個文件被更改,包括 9 次插入5 次删除
  1. 5 5
      imgui.cpp
  2. 4 0
      imgui_internal.h

+ 5 - 5
imgui.cpp

@@ -2150,7 +2150,7 @@ void ImFormatStringToTempBufferV(const char** out_buf, const char** out_buf_end,
     }
     }
 }
 }
 
 
-#ifndef IMGUI_ENABLE_SSE4_2
+#ifndef IMGUI_ENABLE_SSE4_2_CRC
 // CRC32 needs a 1KB lookup table (not cache friendly)
 // CRC32 needs a 1KB lookup table (not cache friendly)
 // Although the code to generate the table is simple and shorter than the table itself, using a const table allows us to easily:
 // Although the code to generate the table is simple and shorter than the table itself, using a const table allows us to easily:
 // - avoid an unnecessary branch/memory tap, - keep the ImHashXXX functions usable by static constructors, - make it thread-safe.
 // - avoid an unnecessary branch/memory tap, - keep the ImHashXXX functions usable by static constructors, - make it thread-safe.
@@ -2184,7 +2184,7 @@ ImGuiID ImHashData(const void* data_p, size_t data_size, ImGuiID seed)
     ImU32 crc = ~seed;
     ImU32 crc = ~seed;
     const unsigned char* data = (const unsigned char*)data_p;
     const unsigned char* data = (const unsigned char*)data_p;
     const unsigned char *data_end = (const unsigned char*)data_p + data_size;
     const unsigned char *data_end = (const unsigned char*)data_p + data_size;
-#ifndef IMGUI_ENABLE_SSE4_2
+#ifndef IMGUI_ENABLE_SSE4_2_CRC
     const ImU32* crc32_lut = GCrc32LookupTable;
     const ImU32* crc32_lut = GCrc32LookupTable;
     while (data < data_end)
     while (data < data_end)
         crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ *data++];
         crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ *data++];
@@ -2212,7 +2212,7 @@ ImGuiID ImHashStr(const char* data_p, size_t data_size, ImGuiID seed)
     seed = ~seed;
     seed = ~seed;
     ImU32 crc = seed;
     ImU32 crc = seed;
     const unsigned char* data = (const unsigned char*)data_p;
     const unsigned char* data = (const unsigned char*)data_p;
-#ifndef IMGUI_ENABLE_SSE4_2
+#ifndef IMGUI_ENABLE_SSE4_2_CRC
     const ImU32* crc32_lut = GCrc32LookupTable;
     const ImU32* crc32_lut = GCrc32LookupTable;
 #endif
 #endif
     if (data_size != 0)
     if (data_size != 0)
@@ -2222,7 +2222,7 @@ ImGuiID ImHashStr(const char* data_p, size_t data_size, ImGuiID seed)
             unsigned char c = *data++;
             unsigned char c = *data++;
             if (c == '#' && data_size >= 2 && data[0] == '#' && data[1] == '#')
             if (c == '#' && data_size >= 2 && data[0] == '#' && data[1] == '#')
                 crc = seed;
                 crc = seed;
-#ifndef IMGUI_ENABLE_SSE4_2
+#ifndef IMGUI_ENABLE_SSE4_2_CRC
             crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
             crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
 #else
 #else
             crc = _mm_crc32_u8(crc, c);
             crc = _mm_crc32_u8(crc, c);
@@ -2235,7 +2235,7 @@ ImGuiID ImHashStr(const char* data_p, size_t data_size, ImGuiID seed)
         {
         {
             if (c == '#' && data[0] == '#' && data[1] == '#')
             if (c == '#' && data[0] == '#' && data[1] == '#')
                 crc = seed;
                 crc = seed;
-#ifndef IMGUI_ENABLE_SSE4_2
+#ifndef IMGUI_ENABLE_SSE4_2_CRC
             crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
             crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
 #else
 #else
             crc = _mm_crc32_u8(crc, c);
             crc = _mm_crc32_u8(crc, c);

+ 4 - 0
imgui_internal.h

@@ -66,6 +66,10 @@ Index of this file:
 #include <nmmintrin.h>
 #include <nmmintrin.h>
 #endif
 #endif
 #endif
 #endif
+// Emscripten has partial SSE 4.2 support where _mm_crc32_u32 is not available. See https://emscripten.org/docs/porting/simd.html#id11 and #8213
+#if defined(IMGUI_ENABLE_SSE4_2) || !defined(__EMSCRIPTEN__)
+#define IMGUI_ENABLE_SSE4_2_CRC
+#endif
 
 
 // Visual Studio warnings
 // Visual Studio warnings
 #ifdef _MSC_VER
 #ifdef _MSC_VER