Skip to content

Commit 3d730a7

Browse files
authored
Merge branch 'main' into main
2 parents 13989d9 + 32801b3 commit 3d730a7

File tree

11 files changed

+3641
-257
lines changed

11 files changed

+3641
-257
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ See docs/process.md for more on how version tagging works.
2020

2121
3.1.68 (in development)
2222
-----------------------
23+
- Added support for compiling 256-bit wide AVX intrinsics, emulated on top
24+
of 128-bit Wasm SIMD instruction set. (#22430). Pass `-msimd128 -mavx` to
25+
enable targeting AVX.
2326
- Pthread-based programs no longer generates `.worker.js` file. This file was
2427
made redundant back in 3.1.58 and now is completely removed. (#22598)
2528
- The freetype port was updated from v2.6 to v2.13.3. (#22585)

emrun.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ def do_POST(self):
704704
if not emrun_options.serve_after_exit:
705705
page_exit_code = int(data[6:])
706706
logv('Web page has quit with a call to exit() with return code ' + str(page_exit_code) + '. Shutting down web server. Pass --serve-after-exit to keep serving even after the page terminates with exit().')
707+
# Set server socket to nonblocking on shutdown to avoid sporadic deadlocks
708+
self.server.socket.setblocking(False)
707709
self.server.shutdown()
708710
return
709711
else:

site/source/docs/porting/simd.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Emscripten supports the `WebAssembly SIMD <https://github.com/webassembly/simd/>
1212
1. Enable LLVM/Clang SIMD autovectorizer to automatically target WebAssembly SIMD, without requiring changes to C/C++ source code.
1313
2. Write SIMD code using the GCC/Clang SIMD Vector Extensions (``__attribute__((vector_size(16)))``)
1414
3. Write SIMD code using the WebAssembly SIMD intrinsics (``#include <wasm_simd128.h>``)
15-
4. Compile existing SIMD code that uses the x86 SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2 or 128-bit subset of the AVX intrinsics (``#include <*mmintrin.h>``)
15+
4. Compile existing SIMD code that uses the x86 SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2 or AVX intrinsics (``#include <*mmintrin.h>``)
1616
5. Compile existing SIMD code that uses the ARM NEON intrinsics (``#include <arm_neon.h>``)
1717

1818
These techniques can be freely combined in a single program.
@@ -153,7 +153,7 @@ Emscripten supports compiling existing codebases that use x86 SSE instructions b
153153
* **SSE4.2**: pass ``-msse4.2`` and ``#include <nmmintrin.h>``. Use ``#ifdef __SSE4_2__`` to gate code.
154154
* **AVX**: pass ``-mavx`` and ``#include <immintrin.h>``. Use ``#ifdef __AVX__`` to gate code.
155155

156-
Currently only the SSE1, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, and 128-bit AVX instruction sets are supported. Each of these instruction sets add on top of the previous ones, so e.g. when targeting SSE3, the instruction sets SSE1 and SSE2 are also available.
156+
Currently only the SSE1, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, and AVX instruction sets are supported. Each of these instruction sets add on top of the previous ones, so e.g. when targeting SSE3, the instruction sets SSE1 and SSE2 are also available.
157157

158158
The following tables highlight the availability and expected performance of different SSE* intrinsics. This can be useful for understanding the performance limitations that the Wasm SIMD specification has when running on x86 hardware.
159159

@@ -1136,7 +1136,7 @@ The following table highlights the availability and expected performance of diff
11361136
* - _mm_testz_ps
11371137
- 💣 emulated with complex SIMD+scalar sequence
11381138

1139-
Only the 128-bit wide instructions from AVX instruction set are available. 256-bit wide AVX instructions are not provided.
1139+
Only the 128-bit wide instructions from AVX instruction set are listed. The 256-bit wide AVX instructions are emulated by two 128-bit wide instructions.
11401140

11411141

11421142
======================================================

src/library_dylink.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,22 @@ var LibraryDylink = {
526526
return customSection;
527527
},
528528

529+
#if DYNCALLS || !WASM_BIGINT
530+
$registerDynCallSymbols: (exports) => {
531+
for (var [sym, exp] of Object.entries(exports)) {
532+
if (sym.startsWith('dynCall_') && !Module.hasOwnProperty(sym)) {
533+
Module[sym] = exp;
534+
}
535+
}
536+
},
537+
#endif
538+
529539
// Module.symbols <- libModule.symbols (flags.global handler)
530540
$mergeLibSymbols__deps: ['$isSymbolDefined'],
531541
$mergeLibSymbols: (exports, libName) => {
542+
#if DYNCALLS || !WASM_BIGINT
543+
registerDynCallSymbols(exports);
544+
#endif
532545
// add symbols into global namespace TODO: weak linking etc.
533546
for (var [sym, exp] of Object.entries(exports)) {
534547
#if ASSERTIONS == 2
@@ -571,10 +584,6 @@ var LibraryDylink = {
571584
setImport('main')
572585
}
573586
#endif
574-
575-
if (sym.startsWith('dynCall_') && !Module.hasOwnProperty(sym)) {
576-
Module[sym] = exp;
577-
}
578587
}
579588
},
580589

@@ -938,6 +947,9 @@ var LibraryDylink = {
938947
'$asyncLoad',
939948
#if FILESYSTEM
940949
'$preloadedWasm',
950+
#endif
951+
#if DYNCALLS || !WASM_BIGINT
952+
'$registerDynCallSymbols',
941953
#endif
942954
],
943955
$loadDynamicLibrary__docs: `
@@ -963,6 +975,9 @@ var LibraryDylink = {
963975
if (localScope) {
964976
Object.assign(localScope, dso.exports);
965977
}
978+
#if DYNCALLS || !WASM_BIGINT
979+
registerDynCallSymbols(dso.exports);
980+
#endif
966981
} else if (!dso.global) {
967982
// The library was previously loaded only locally but not
968983
// we have a request with global=true.
@@ -1046,6 +1061,9 @@ var LibraryDylink = {
10461061
mergeLibSymbols(exports, libName);
10471062
} else if (localScope) {
10481063
Object.assign(localScope, exports);
1064+
#if DYNCALLS || !WASM_BIGINT
1065+
registerDynCallSymbols(exports);
1066+
#endif
10491067
}
10501068
dso.exports = exports;
10511069
}

src/library_sdl.js

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,10 @@ var LibrarySDL = {
291291
},
292292
loadRect(rect) {
293293
return {
294-
x: {{{ makeGetValue('rect + ' + C_STRUCTS.SDL_Rect.x, '0', 'i32') }}},
295-
y: {{{ makeGetValue('rect + ' + C_STRUCTS.SDL_Rect.y, '0', 'i32') }}},
296-
w: {{{ makeGetValue('rect + ' + C_STRUCTS.SDL_Rect.w, '0', 'i32') }}},
297-
h: {{{ makeGetValue('rect + ' + C_STRUCTS.SDL_Rect.h, '0', 'i32') }}}
294+
x: {{{ makeGetValue('rect', C_STRUCTS.SDL_Rect.x, 'i32') }}},
295+
y: {{{ makeGetValue('rect', C_STRUCTS.SDL_Rect.y, 'i32') }}},
296+
w: {{{ makeGetValue('rect', C_STRUCTS.SDL_Rect.w, 'i32') }}},
297+
h: {{{ makeGetValue('rect', C_STRUCTS.SDL_Rect.h, 'i32') }}}
298298
};
299299
},
300300

@@ -331,11 +331,11 @@ var LibrarySDL = {
331331

332332
// Load SDL color into a CSS-style color specification
333333
loadColorToCSSRGB(color) {
334-
var rgba = {{{ makeGetValue('color', '0', 'i32') }}};
334+
var rgba = {{{ makeGetValue('color', 0, 'i32') }}};
335335
return 'rgb(' + (rgba&255) + ',' + ((rgba >> 8)&255) + ',' + ((rgba >> 16)&255) + ')';
336336
},
337337
loadColorToCSSRGBA(color) {
338-
var rgba = {{{ makeGetValue('color', '0', 'i32') }}};
338+
var rgba = {{{ makeGetValue('color', 0, 'i32') }}};
339339
return 'rgba(' + (rgba&255) + ',' + ((rgba >> 8)&255) + ',' + ((rgba >> 16)&255) + ',' + (((rgba >> 24)&255)/255) + ')';
340340
},
341341

@@ -466,16 +466,16 @@ var LibrarySDL = {
466466
for (var y = startY; y < endY; ++y) {
467467
var base = y * fullWidth;
468468
for (var x = startX; x < endX; ++x) {
469-
data32[base + x] = colors32[{{{ makeGetValue('buffer + base + x', '0', 'u8') }}}];
469+
data32[base + x] = colors32[{{{ makeGetValue('buffer', 'base + x', 'u8') }}}];
470470
}
471471
}
472472
},
473473

474474
freeSurface(surf) {
475475
var refcountPointer = surf + {{{ C_STRUCTS.SDL_Surface.refcount }}};
476-
var refcount = {{{ makeGetValue('refcountPointer', '0', 'i32') }}};
476+
var refcount = {{{ makeGetValue('refcountPointer', 0, 'i32') }}};
477477
if (refcount > 1) {
478-
{{{ makeSetValue('refcountPointer', '0', 'refcount - 1', 'i32') }}};
478+
{{{ makeSetValue('refcountPointer', 0, 'refcount - 1', 'i32') }}};
479479
return;
480480
}
481481

@@ -1351,9 +1351,9 @@ var LibrarySDL = {
13511351
SDL_Linked_Version: () => {
13521352
if (SDL.version === null) {
13531353
SDL.version = _malloc({{{ C_STRUCTS.SDL_version.__size__ }}});
1354-
{{{ makeSetValue('SDL.version + ' + C_STRUCTS.SDL_version.major, '0', '1', 'i8') }}};
1355-
{{{ makeSetValue('SDL.version + ' + C_STRUCTS.SDL_version.minor, '0', '3', 'i8') }}};
1356-
{{{ makeSetValue('SDL.version + ' + C_STRUCTS.SDL_version.patch, '0', '0', 'i8') }}};
1354+
{{{ makeSetValue('SDL.version', C_STRUCTS.SDL_version.major, '1', 'i8') }}};
1355+
{{{ makeSetValue('SDL.version', C_STRUCTS.SDL_version.minor, '3', 'i8') }}};
1356+
{{{ makeSetValue('SDL.version', C_STRUCTS.SDL_version.patch, '0', 'i8') }}};
13571357
}
13581358
return SDL.version;
13591359
},
@@ -1693,7 +1693,7 @@ var LibrarySDL = {
16931693
var base = y*width*4;
16941694
for (var x = 0; x < width; x++) {
16951695
// See comment above about signs
1696-
var val = {{{ makeGetValue('s++', '0', 'u8') }}} * 4;
1696+
var val = {{{ makeGetValue('s++', 0, 'u8') }}} * 4;
16971697
var start = base + x*4;
16981698
data[start] = colors[val];
16991699
data[start+1] = colors[val+1];
@@ -1769,8 +1769,8 @@ var LibrarySDL = {
17691769

17701770
SDL_GetMouseState__proxy: 'sync',
17711771
SDL_GetMouseState: (x, y) => {
1772-
if (x) {{{ makeSetValue('x', '0', 'Browser.mouseX', 'i32') }}};
1773-
if (y) {{{ makeSetValue('y', '0', 'Browser.mouseY', 'i32') }}};
1772+
if (x) {{{ makeSetValue('x', 0, 'Browser.mouseX', 'i32') }}};
1773+
if (y) {{{ makeSetValue('y', 0, 'Browser.mouseY', 'i32') }}};
17741774
return SDL.buttonState;
17751775
},
17761776

@@ -2094,13 +2094,13 @@ var LibrarySDL = {
20942094
SDL.checkPixelFormat(fmt);
20952095
// We assume the machine is little-endian.
20962096
if (r) {
2097-
{{{ makeSetValue('r', '0', 'pixel&0xff', 'i8') }}};
2097+
{{{ makeSetValue('r', 0, 'pixel&0xff', 'i8') }}};
20982098
}
20992099
if (g) {
2100-
{{{ makeSetValue('g', '0', '(pixel>>8)&0xff', 'i8') }}};
2100+
{{{ makeSetValue('g', 0, '(pixel>>8)&0xff', 'i8') }}};
21012101
}
21022102
if (b) {
2103-
{{{ makeSetValue('b', '0', '(pixel>>16)&0xff', 'i8') }}};
2103+
{{{ makeSetValue('b', 0, '(pixel>>16)&0xff', 'i8') }}};
21042104
}
21052105
},
21062106

@@ -2109,16 +2109,16 @@ var LibrarySDL = {
21092109
SDL.checkPixelFormat(fmt);
21102110
// We assume the machine is little-endian.
21112111
if (r) {
2112-
{{{ makeSetValue('r', '0', 'pixel&0xff', 'i8') }}};
2112+
{{{ makeSetValue('r', 0, 'pixel&0xff', 'i8') }}};
21132113
}
21142114
if (g) {
2115-
{{{ makeSetValue('g', '0', '(pixel>>8)&0xff', 'i8') }}};
2115+
{{{ makeSetValue('g', 0, '(pixel>>8)&0xff', 'i8') }}};
21162116
}
21172117
if (b) {
2118-
{{{ makeSetValue('b', '0', '(pixel>>16)&0xff', 'i8') }}};
2118+
{{{ makeSetValue('b', 0, '(pixel>>16)&0xff', 'i8') }}};
21192119
}
21202120
if (a) {
2121-
{{{ makeSetValue('a', '0', '(pixel>>24)&0xff', 'i8') }}};
2121+
{{{ makeSetValue('a', 0, '(pixel>>24)&0xff', 'i8') }}};
21222122
}
21232123
},
21242124

@@ -2668,19 +2668,19 @@ var LibrarySDL = {
26682668

26692669
#if USE_SDL == 2
26702670
if (rwops === undefined) {
2671-
var type = {{{ makeGetValue('rwopsID + ' + 20 /*type*/, '0', 'i32') }}};
2671+
var type = {{{ makeGetValue('rwopsID', 20 /*type*/, 'i32') }}};
26722672

26732673
if (type === 2/*SDL_RWOPS_STDFILE*/) {
2674-
var fp = {{{ makeGetValue('rwopsID + ' + 28 /*hidden.stdio.fp*/, '0', 'i32') }}};
2674+
var fp = {{{ makeGetValue('rwopsID', 28 /*hidden.stdio.fp*/, 'i32') }}};
26752675
var fd = _fileno(fp);
26762676
var stream = FS.getStream(fd);
26772677
if (stream) {
26782678
rwops = { filename: stream.path };
26792679
}
26802680
}
26812681
else if (type === 4/*SDL_RWOPS_MEMORY*/ || type === 5/*SDL_RWOPS_MEMORY_RO*/) {
2682-
var base = {{{ makeGetValue('rwopsID + ' + 24 /*hidden.mem.base*/, '0', 'i32') }}};
2683-
var stop = {{{ makeGetValue('rwopsID + ' + 32 /*hidden.mem.stop*/, '0', 'i32') }}};
2682+
var base = {{{ makeGetValue('rwopsID', 24 /*hidden.mem.base*/, 'i32') }}};
2683+
var stop = {{{ makeGetValue('rwopsID', 32 /*hidden.mem.stop*/, 'i32') }}};
26842684

26852685
rwops = { bytes: base, count: stop - base };
26862686
}
@@ -3129,10 +3129,10 @@ var LibrarySDL = {
31293129
TTF_SizeText: (font, text, w, h) => {
31303130
var fontData = SDL.fonts[font];
31313131
if (w) {
3132-
{{{ makeSetValue('w', '0', 'SDL.estimateTextWidth(fontData, UTF8ToString(text))', 'i32') }}};
3132+
{{{ makeSetValue('w', 0, 'SDL.estimateTextWidth(fontData, UTF8ToString(text))', 'i32') }}};
31333133
}
31343134
if (h) {
3135-
{{{ makeSetValue('h', '0', 'fontData.size', 'i32') }}};
3135+
{{{ makeSetValue('h', 0, 'fontData.size', 'i32') }}};
31363136
}
31373137
return 0;
31383138
},
@@ -3143,19 +3143,19 @@ var LibrarySDL = {
31433143
var width = SDL.estimateTextWidth(fontData, String.fromCharCode(ch));
31443144

31453145
if (advance) {
3146-
{{{ makeSetValue('advance', '0', 'width', 'i32') }}};
3146+
{{{ makeSetValue('advance', 0, 'width', 'i32') }}};
31473147
}
31483148
if (minx) {
3149-
{{{ makeSetValue('minx', '0', '0', 'i32') }}};
3149+
{{{ makeSetValue('minx', 0, '0', 'i32') }}};
31503150
}
31513151
if (maxx) {
3152-
{{{ makeSetValue('maxx', '0', 'width', 'i32') }}};
3152+
{{{ makeSetValue('maxx', 0, 'width', 'i32') }}};
31533153
}
31543154
if (miny) {
3155-
{{{ makeSetValue('miny', '0', '0', 'i32') }}};
3155+
{{{ makeSetValue('miny', 0, '0', 'i32') }}};
31563156
}
31573157
if (maxy) {
3158-
{{{ makeSetValue('maxy', '0', 'fontData.size', 'i32') }}};
3158+
{{{ makeSetValue('maxy', 0, 'fontData.size', 'i32') }}};
31593159
}
31603160
},
31613161

@@ -3302,7 +3302,7 @@ var LibrarySDL = {
33023302
abort('Unknown SDL GL attribute (' + attr + '). Please check if your SDL version is supported.');
33033303
}
33043304

3305-
if (value) {{{ makeSetValue('value', '0', 'SDL.glAttributes[attr]', 'i32') }}};
3305+
if (value) {{{ makeSetValue('value', 0, 'SDL.glAttributes[attr]', 'i32') }}};
33063306

33073307
return 0;
33083308
},
@@ -3356,8 +3356,8 @@ var LibrarySDL = {
33563356
SDL_GetWindowSize: (window, width, height) => {
33573357
var w = Module['canvas'].width;
33583358
var h = Module['canvas'].height;
3359-
if (width) {{{ makeSetValue('width', '0', 'w', 'i32') }}};
3360-
if (height) {{{ makeSetValue('height', '0', 'h', 'i32') }}};
3359+
if (width) {{{ makeSetValue('width', 0, 'w', 'i32') }}};
3360+
if (height) {{{ makeSetValue('height', 0, 'h', 'i32') }}};
33613361
},
33623362

33633363
SDL_LogSetOutputFunction: (callback, userdata) => {},

0 commit comments

Comments
 (0)