Skip to content

Commit 8a1b7ce

Browse files
authored
Merge branch 'main' into emscripten-22847
2 parents ae7511b + e6ed9d3 commit 8a1b7ce

File tree

11 files changed

+95
-55
lines changed

11 files changed

+95
-55
lines changed

src/library_browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ var LibraryBrowser = {
192192
},
193193

194194
createContext(/** @type {HTMLCanvasElement} */ canvas, useWebGL, setInModule, webGLContextAttributes) {
195-
if (useWebGL && Module.ctx && canvas == Module.canvas) return Module.ctx; // no need to recreate GL context if it's already been created for this canvas.
195+
if (useWebGL && Module.ctx && canvas == Module['canvas']) return Module.ctx; // no need to recreate GL context if it's already been created for this canvas.
196196

197197
var ctx;
198198
var contextHandle;

src/library_sdl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ var LibrarySDL = {
553553
receiveEvent(event) {
554554
function unpressAllPressedKeys() {
555555
// Un-press all pressed keys: TODO
556-
for (var keyCode of SDL.keyboardMap) {
556+
for (var keyCode of Object.values(SDL.keyboardMap)) {
557557
SDL.events.push({
558558
type: 'keyup',
559559
keyCode,

src/proxyClient.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ WebGLClient.prefetch();
153153
setTimeout(() => {
154154
worker.postMessage({
155155
target: 'worker-init',
156-
width: Module.canvas.width,
157-
height: Module.canvas.height,
158-
boundingClientRect: cloneObject(Module.canvas.getBoundingClientRect()),
156+
width: Module['canvas'].width,
157+
height: Module['canvas'].height,
158+
boundingClientRect: cloneObject(Module['canvas'].getBoundingClientRect()),
159159
URL: document.URL,
160160
currentScriptUrl: filename,
161161
preMain: true });
@@ -190,18 +190,18 @@ worker.onmessage = (event) => {
190190
case 'canvas': {
191191
switch (data.op) {
192192
case 'getContext': {
193-
Module.ctx = Module.canvas.getContext(data.type, data.attributes);
193+
Module.ctx = Module['canvas'].getContext(data.type, data.attributes);
194194
if (data.type !== '2d') {
195195
// possible GL_DEBUG entry point: Module.ctx = wrapDebugGL(Module.ctx);
196196
Module.glClient = new WebGLClient();
197197
}
198198
break;
199199
}
200200
case 'resize': {
201-
Module.canvas.width = data.width;
202-
Module.canvas.height = data.height;
201+
Module['canvas'].width = data.width;
202+
Module['canvas'].height = data.height;
203203
if (Module.ctx?.getImageData) Module.canvasData = Module.ctx.getImageData(0, 0, data.width, data.height);
204-
worker.postMessage({ target: 'canvas', boundingClientRect: cloneObject(Module.canvas.getBoundingClientRect()) });
204+
worker.postMessage({ target: 'canvas', boundingClientRect: cloneObject(Module['canvas'].getBoundingClientRect()) });
205205
break;
206206
}
207207
case 'render': {
@@ -216,7 +216,7 @@ worker.onmessage = (event) => {
216216
break;
217217
}
218218
case 'setObjectProperty': {
219-
Module.canvas[data.object][data.property] = data.value;
219+
Module['canvas'][data.object][data.property] = data.value;
220220
break;
221221
}
222222
default: throw 'eh?';
@@ -338,7 +338,7 @@ function shouldPreventDefault(event) {
338338
});
339339

340340
['mousedown', 'mouseup', 'mousemove', 'DOMMouseScroll', 'mousewheel', 'mouseout'].forEach((event) => {
341-
Module.canvas.addEventListener(event, (event) => {
341+
Module['canvas'].addEventListener(event, (event) => {
342342
worker.postMessage({ target: 'canvas', event: cloneObject(event) });
343343
event.preventDefault();
344344
}, true);

src/proxyWorker.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,14 @@ document.createElement = (what) => {
261261

262262
document.getElementById = (id) => {
263263
if (id === 'canvas' || id === 'application-canvas') {
264-
return Module.canvas;
264+
return Module['canvas'];
265265
}
266266
throw 'document.getElementById failed on ' + id;
267267
};
268268

269269
document.querySelector = (id) => {
270270
if (id === '#canvas' || id === '#application-canvas' || id === 'canvas' || id === 'application-canvas') {
271-
return Module.canvas;
271+
return Module['canvas'];
272272
}
273273
throw 'document.querySelector failed on ' + id;
274274
};
@@ -324,7 +324,7 @@ var screen = {
324324
height: 0
325325
};
326326

327-
Module.canvas = document.createElement('canvas');
327+
Module['canvas'] = document.createElement('canvas');
328328

329329
Module.setStatus = () => {};
330330

@@ -412,9 +412,9 @@ function onMessageFromMainEmscriptenThread(message) {
412412
}
413413
case 'canvas': {
414414
if (message.data.event) {
415-
Module.canvas.fireEvent(message.data.event);
415+
Module['canvas'].fireEvent(message.data.event);
416416
} else if (message.data.boundingClientRect) {
417-
Module.canvas.boundingClientRect = message.data.boundingClientRect;
417+
Module['canvas'].boundingClientRect = message.data.boundingClientRect;
418418
} else throw 'ey?';
419419
break;
420420
}
@@ -451,10 +451,10 @@ function onMessageFromMainEmscriptenThread(message) {
451451
break;
452452
}
453453
case 'worker-init': {
454-
Module.canvas = document.createElement('canvas');
455-
screen.width = Module.canvas.width_ = message.data.width;
456-
screen.height = Module.canvas.height_ = message.data.height;
457-
Module.canvas.boundingClientRect = message.data.boundingClientRect;
454+
Module['canvas'] = document.createElement('canvas');
455+
screen.width = Module['canvas'].width_ = message.data.width;
456+
screen.height = Module['canvas'].height_ = message.data.height;
457+
Module['canvas'].boundingClientRect = message.data.boundingClientRect;
458458
#if ENVIRONMENT_MAY_BE_NODE
459459
if (ENVIRONMENT_IS_NODE)
460460
#endif

src/shell.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ var Module = moduleArg;
2525
#elif USE_CLOSURE_COMPILER
2626
// if (!Module)` is crucial for Closure Compiler here as it will otherwise replace every `Module` occurrence with a string
2727
var /** @type {{
28-
canvas: HTMLCanvasElement,
2928
ctx: Object,
3029
}}
3130
*/ Module;

system/include/compat/emmintrin.h

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,11 @@ _mm_cvttpd_epi32(__m128d __a)
431431
int m[2];
432432
for(int i = 0; i < 2; ++i)
433433
{
434-
int x = lrint(__a[i]);
435-
if (x != 0 || fabs(__a[i]) < 2.0)
436-
m[i] = (int)__a[i];
434+
float elem = __a[i];
435+
if ((lrint(elem) != 0 || fabs(elem) < 2.0) && !isnanf(elem) && elem <= INT_MAX && elem >= INT_MIN)
436+
// Use the trapping instruction here since we have explicit bounds checks
437+
// above.
438+
m[i] = __builtin_wasm_trunc_s_i32_f32(elem);
437439
else
438440
m[i] = (int)0x80000000;
439441
}
@@ -444,9 +446,12 @@ static __inline__ int __attribute__((__always_inline__, __nodebug__))
444446
_mm_cvttsd_si32(__m128d __a)
445447
{
446448
// TODO: OPTIMIZE!
447-
int x = lrint(__a[0]);
448-
if (x != 0 || fabs(__a[0]) < 2.0)
449-
return (int)__a[0];
449+
float elem = __a[0];
450+
if (isnan(elem) || elem > INT_MAX || elem < INT_MIN) return (int)0x80000000;
451+
if (lrint(elem) != 0 || fabs(elem) < 2.0)
452+
// Use the trapping instruction here since we have explicit bounds checks
453+
// above.
454+
return __builtin_wasm_trunc_s_i32_f32(elem);
450455
else
451456
return (int)0x80000000;
452457
}
@@ -1013,10 +1018,13 @@ static __inline__ long long __attribute__((__always_inline__, __nodebug__))
10131018
_mm_cvttsd_si64(__m128d __a)
10141019
{
10151020
// TODO: optimize
1016-
if (isnan(__a[0]) || isinf(__a[0])) return 0x8000000000000000LL;
1017-
long long x = llrint(__a[0]);
1018-
if (x != 0xFFFFFFFF00000000ULL && (x != 0 || fabsf(__a[0]) < 2.f))
1019-
return (long long)__a[0];
1021+
float e = __a[0];
1022+
if (isnan(e) || isinf(e) || e > LLONG_MAX || e < LLONG_MIN) return 0x8000000000000000LL;
1023+
long long x = llrint(e);
1024+
if (x != 0xFFFFFFFF00000000ULL && (x != 0 || fabsf(e) < 2.f))
1025+
// Use the trapping instruction here since we have explicit bounds checks
1026+
// above
1027+
return __builtin_wasm_trunc_s_i64_f32(e);
10201028
else
10211029
return 0x8000000000000000LL;
10221030
}
@@ -1056,9 +1064,12 @@ _mm_cvttps_epi32(__m128 __a)
10561064
} u;
10571065
for(int i = 0; i < 4; ++i)
10581066
{
1059-
int x = lrint(__a[i]);
1060-
if (x != 0 || fabs(__a[i]) < 2.0)
1061-
u.x[i] = (int)__a[i];
1067+
float e = __a[i];
1068+
int x = lrint(e);
1069+
if ((x != 0 || fabs(e) < 2.0) && !isnanf(e) && e <= INT_MAX && e >= INT_MIN)
1070+
// Use the trapping instruction here since we have explicit bounds checks
1071+
// above.
1072+
u.x[i] = __builtin_wasm_trunc_s_i32_f32(e);
10621073
else
10631074
u.x[i] = (int)0x80000000;
10641075
}

system/include/compat/xmmintrin.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <wasm_simd128.h>
1111

12+
#include <limits.h>
1213
#include <math.h>
1314
#include <string.h>
1415

@@ -605,9 +606,11 @@ static __inline__ int __attribute__((__always_inline__, __nodebug__, DIAGNOSE_SL
605606

606607
static __inline__ int __attribute__((__always_inline__, __nodebug__, DIAGNOSE_SLOW)) _mm_cvttss_si32(__m128 __a)
607608
{
608-
int x = lrint(((__f32x4)__a)[0]);
609-
if (x != 0 || fabsf(((__f32x4)__a)[0]) < 2.f)
610-
return (int)((__f32x4)__a)[0];
609+
float e = ((__f32x4)__a)[0];
610+
if (isnanf(e) || e > INT_MAX || e < INT_MIN) return (int)0x80000000;
611+
int x = lrint(e);
612+
if ((x != 0 || fabsf(e) < 2.f))
613+
return (int)e;
611614
else
612615
return (int)0x80000000;
613616
}
@@ -635,10 +638,11 @@ _mm_cvtss_si64(__m128 __a)
635638
static __inline__ long long __attribute__((__always_inline__, __nodebug__, DIAGNOSE_SLOW))
636639
_mm_cvttss_si64(__m128 __a)
637640
{
638-
if (isnan(((__f32x4)__a)[0]) || isinf(((__f32x4)__a)[0])) return 0x8000000000000000LL;
639-
long long x = llrint(((__f32x4)__a)[0]);
640-
if (x != 0xFFFFFFFF00000000ULL && (x != 0 || fabsf(((__f32x4)__a)[0]) < 2.f))
641-
return (long long)((__f32x4)__a)[0];
641+
float e = ((__f32x4)__a)[0];
642+
if (isnan(e) || isinf(e) || e > LLONG_MAX || e < LLONG_MIN) return 0x8000000000000000LL;
643+
long long x = llrint(e);
644+
if (x != 0xFFFFFFFF00000000ULL && (x != 0 || fabsf(e) < 2.f))
645+
return (long long)e;
642646
else
643647
return 0x8000000000000000LL;
644648
}

test/reftest.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ function doReftest() {
2626
doReftest.done = true;
2727
var img = new Image();
2828
img.onload = () => {
29-
assert(img.width == Module.canvas.width, `Invalid width: ${Module.canvas.width}, should be ${img.width}`);
30-
assert(img.height == Module.canvas.height, `Invalid height: ${Module.canvas.height}, should be ${img.height}`);
29+
assert(img.width == Module['canvas'].width, `Invalid width: ${Module['canvas'].width}, should be ${img.width}`);
30+
assert(img.height == Module['canvas'].height, `Invalid height: ${Module['canvas'].height}, should be ${img.height}`);
3131

3232
var canvas = document.createElement('canvas');
3333
canvas.width = img.width;
@@ -36,7 +36,7 @@ function doReftest() {
3636
ctx.drawImage(img, 0, 0);
3737
var expected = ctx.getImageData(0, 0, img.width, img.height).data;
3838

39-
var actualUrl = Module.canvas.toDataURL();
39+
var actualUrl = Module['canvas'].toDataURL();
4040
var actualImage = new Image();
4141
actualImage.onload = () => {
4242
/*
@@ -69,7 +69,7 @@ function doReftest() {
6969
if (wrong || reftestRebaseline) {
7070
// Generate a png of the actual rendered image and send it back
7171
// to the server.
72-
Module.canvas.toBlob((blob) => {
72+
Module['canvas'].toBlob((blob) => {
7373
sendFileToServer('actual.png', blob);
7474
reportResultToServer(wrong);
7575
})

test/test_core.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6511,12 +6511,16 @@ def test_neon_wasm_simd(self):
65116511
@requires_native_clang
65126512
@no_safe_heap('has unaligned 64-bit operations in wasm')
65136513
@no_ubsan('test contains UB')
6514-
def test_sse1(self):
6514+
@parameterized({
6515+
'': ([],),
6516+
'nontrapping': (['-mnontrapping-fptoint'],)
6517+
})
6518+
def test_sse1(self, args):
65156519
src = test_file('sse/test_sse1.cpp')
65166520
self.run_process([shared.CLANG_CXX, src, '-msse', '-o', 'test_sse1', '-D_CRT_SECURE_NO_WARNINGS=1'] + clang_native.get_clang_native_args(), stdout=PIPE)
65176521
native_result = self.run_process('./test_sse1', stdout=PIPE).stdout
65186522

6519-
self.emcc_args += ['-I' + test_file('sse'), '-msse']
6523+
self.emcc_args += ['-I' + test_file('sse'), '-msse'] + args
65206524
self.maybe_closure()
65216525

65226526
self.do_runf(src, native_result)
@@ -6528,14 +6532,18 @@ def test_sse1(self):
65286532
@is_slow_test
65296533
@no_ubsan('https://github.com/emscripten-core/emscripten/issues/19688')
65306534
@no_asan('local count too large')
6531-
def test_sse2(self):
6535+
@parameterized({
6536+
'': ([],),
6537+
'nontrapping': (['-mnontrapping-fptoint'],)
6538+
})
6539+
def test_sse2(self, args):
65326540
if self.is_wasm64():
65336541
self.require_node_canary()
65346542
src = test_file('sse/test_sse2.cpp')
65356543
self.run_process([shared.CLANG_CXX, src, '-msse2', '-Wno-argument-outside-range', '-o', 'test_sse2', '-D_CRT_SECURE_NO_WARNINGS=1'] + clang_native.get_clang_native_args(), stdout=PIPE)
65366544
native_result = self.run_process('./test_sse2', stdout=PIPE).stdout
65376545

6538-
self.emcc_args += ['-I' + test_file('sse'), '-msse2', '-Wno-argument-outside-range', '-sSTACK_SIZE=1MB']
6546+
self.emcc_args += ['-I' + test_file('sse'), '-msse2', '-Wno-argument-outside-range', '-sSTACK_SIZE=1MB'] + args
65396547
self.maybe_closure()
65406548
self.do_runf(src, native_result)
65416549

@@ -6587,8 +6595,8 @@ def test_sse4_1(self):
65876595
@wasm_simd
65886596
@requires_native_clang
65896597
@parameterized({
6590-
'': (False,),
6591-
'2': (True,)
6598+
'': (False,),
6599+
'2': (True,)
65926600
})
65936601
def test_sse4(self, use_4_2):
65946602
msse4 = '-msse4.2' if use_4_2 else '-msse4'
@@ -6606,12 +6614,16 @@ def test_sse4(self, use_4_2):
66066614
@is_slow_test
66076615
@no_asan('local count too large')
66086616
@no_ubsan('local count too large')
6609-
def test_avx(self):
6617+
@parameterized({
6618+
'': ([],),
6619+
'nontrapping': (['-mnontrapping-fptoint'],)
6620+
})
6621+
def test_avx(self, args):
66106622
src = test_file('sse/test_avx.cpp')
66116623
self.run_process([shared.CLANG_CXX, src, '-mavx', '-Wno-argument-outside-range', '-Wpedantic', '-o', 'test_avx', '-D_CRT_SECURE_NO_WARNINGS=1'] + clang_native.get_clang_native_args(), stdout=PIPE)
66126624
native_result = self.run_process('./test_avx', stdout=PIPE).stdout
66136625

6614-
self.emcc_args += ['-I' + test_file('sse'), '-mavx', '-Wno-argument-outside-range', '-sSTACK_SIZE=1MB']
6626+
self.emcc_args += ['-I' + test_file('sse'), '-mavx', '-Wno-argument-outside-range', '-sSTACK_SIZE=1MB'] + args
66156627
self.maybe_closure()
66166628
self.do_runf(src, native_result)
66176629

test/test_other.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,11 @@ def test_log_subcommands(self):
321321

322322
def test_skip_subcommands(self):
323323
# The -### flag is like `-v` but it doesn't actaully execute the sub-commands
324-
proc = self.run_process([EMCC, '-###', test_file('hello_world.c')], stdout=PIPE, stderr=PIPE)
324+
proc = self.run_process([EMCC, '-###', '-O3', test_file('hello_world.c')], stdout=PIPE, stderr=PIPE)
325325
self.assertContained(CLANG_CC, proc.stderr)
326326
self.assertContained(WASM_LD, proc.stderr)
327+
self.assertContained('wasm-opt', proc.stderr)
328+
self.assertContained('acorn-optimizer.mjs', proc.stderr)
327329
self.assertNotExists('a.out.js')
328330

329331
def test_emcc_check(self):

0 commit comments

Comments
 (0)