-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
Hi @traffaillac,
Thanks for creating this great library.
In case you're interested, to build this as a WebAssembly module, a few very minor changes were needed:
diff --git c/edge264.c w/edge264.c
index 9b47a57..38ddd04 100644
--- c/edge264.c
+++ w/edge264.c
@@ -135,7 +135,7 @@ Edge264Decoder *edge264_alloc(int n_threads, void (*log_cb)(const char *str, voi
dec->taskPics_v = set8(-1);
// select parser functions based on CPU capabilities and logs mode
- #if defined(__SSE2__) // if compiled for Intel
+ #if defined(__SSE2__) && !defined(__wasm__) // if compiled for Intel
__builtin_cpu_init();
if (!__builtin_cpu_supports("cmov") || !__builtin_cpu_supports("sse2"))
return free(dec), NULL;
diff --git c/edge264_internal.h w/edge264_internal.h
index 337f4ca..2c0f7c5 100644
--- c/edge264_internal.h
+++ w/edge264_internal.h
@@ -660,7 +660,11 @@ static always_inline const char *unsup_if(int cond) { return cond ? " # unsuppor
* _ ziphiN - interleave the high N-bit elements from two vectors
*/
#if defined(__SSE2__)
+#if defined(__wasm__)
+ #include <immintrin.h>
+#else
#include <x86intrin.h>
+#endif
#define adds16(a, b) (i16x8)_mm_adds_epi16(a, b)
#define addu8(a, b) (i8x16)_mm_adds_epu8(a, b)
#define avgu8(a, b) (i8x16)_mm_avg_epu8(a, b)
@@ -714,7 +718,11 @@ static always_inline const char *unsup_if(int cond) { return cond ? " # unsuppor
#define ziphi16(a, b) (i16x8)_mm_unpackhi_epi16(a, b)
#define ziphi32(a, b) (i32x4)_mm_unpackhi_epi32(a, b)
#define ziphi64(a, b) (i64x2)_mm_unpackhi_epi64(a, b)
+#if defined(__wasm__)
+ static always_inline size_t shld(size_t l, size_t h, int i) {return (size_t)((uint64_t)h << (uint64_t)i) | ((uint64_t)l >> (uint64_t)(SIZE_BIT - i));}
+#else
static always_inline size_t shld(size_t l, size_t h, int i) {asm("shld %%cl, %1, %0" : "+rm" (h) : "r" (l), "c" (i)); return h;}
+#endif
#ifdef __SSE4_1__
#define cvtlo8u16(a) (i16x8)_mm_cvtepu8_epi16(a)
#define cvtlo8s16(a) (i16x8)_mm_cvtepi8_epi16(a)
And more substantial changes were required for the make file, so I ended up creating a new CMake file instead, which I can provide if you like. I'm also happy to create a pull request for the above compilation fixes.
-Benbuck
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels