Skip to content

Commit cb384b5

Browse files
committed
[wasm64]: more fixes to address >2gb using unsigned shifts
1 parent 75a9a6c commit cb384b5

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/library_html5.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ var LibraryHTML5 = {
288288
#endif
289289
{{{ makeSetValue('keyEventData', C_STRUCTS.EmscriptenKeyboardEvent.timestamp, 'e.timeStamp', 'double') }}};
290290

291-
var idx = keyEventData >> 2;
291+
var idx ={{{ getHeapOffset('keyEventData', 'i32') }}};
292292

293293
HEAP32[idx + {{{ C_STRUCTS.EmscriptenKeyboardEvent.location / 4}}}] = e.location;
294294
HEAP32[idx + {{{ C_STRUCTS.EmscriptenKeyboardEvent.ctrlKey / 4}}}] = e.ctrlKey;
@@ -462,7 +462,7 @@ var LibraryHTML5 = {
462462
assert(eventStruct % 4 == 0);
463463
#endif
464464
{{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenMouseEvent.timestamp, 'e.timeStamp', 'double') }}};
465-
var idx = eventStruct >> 2;
465+
var idx = {{{ getHeapOffset('eventStruct', 'i32') }}};
466466
HEAP32[idx + {{{ C_STRUCTS.EmscriptenMouseEvent.screenX / 4 }}}] = e.screenX;
467467
HEAP32[idx + {{{ C_STRUCTS.EmscriptenMouseEvent.screenY / 4 }}}] = e.screenY;
468468
HEAP32[idx + {{{ C_STRUCTS.EmscriptenMouseEvent.clientX / 4 }}}] = e.clientX;
@@ -2013,7 +2013,7 @@ var LibraryHTML5 = {
20132013
var touchEvent = JSEvents.touchEvent;
20142014
#endif
20152015
{{{ makeSetValue('touchEvent', C_STRUCTS.EmscriptenTouchEvent.timestamp, 'e.timeStamp', 'double') }}};
2016-
var idx = touchEvent>>2; // Pre-shift the ptr to index to HEAP32 to save code size
2016+
var idx ={{{ getHeapOffset('touchEvent', 'i32') }}};// Pre-shift the ptr to index to HEAP32 to save code size
20172017
HEAP32[idx + {{{ C_STRUCTS.EmscriptenTouchEvent.ctrlKey / 4}}}] = e.ctrlKey;
20182018
HEAP32[idx + {{{ C_STRUCTS.EmscriptenTouchEvent.shiftKey / 4}}}] = e.shiftKey;
20192019
HEAP32[idx + {{{ C_STRUCTS.EmscriptenTouchEvent.altKey / 4}}}] = e.altKey;

src/library_webgpu.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,11 +1428,12 @@ var LibraryWebGPU = {
14281428
case {{{ gpu.SType.ShaderModuleSPIRVDescriptor }}}: {
14291429
var count = {{{ gpu.makeGetU32('nextInChainPtr', C_STRUCTS.WGPUShaderModuleSPIRVDescriptor.codeSize) }}};
14301430
var start = {{{ makeGetValue('nextInChainPtr', C_STRUCTS.WGPUShaderModuleSPIRVDescriptor.code, '*') }}};
1431+
var offset = {{{ getHeapOffset('start', 'u32') }}};
14311432
#if PTHREADS
14321433
// Chrome can't currently handle a SharedArrayBuffer view here, so make a copy.
1433-
desc["code"] = HEAPU32.slice(start >> 2, (start >> 2) + count);
1434+
desc["code"] = HEAPU32.slice(offset, offset + count);
14341435
#else
1435-
desc["code"] = HEAPU32.subarray(start >> 2, (start >> 2) + count);
1436+
desc["code"] = HEAPU32.subarray(offset, offset + count);
14361437
#endif
14371438
break;
14381439
}

src/parseTools.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ function makeSetValueImpl(ptr, pos, value, type) {
425425
function makeHEAPView(which, start, end) {
426426
const size = parseInt(which.replace('U', '').replace('F', '')) / 8;
427427
const shift = Math.log2(size);
428-
const mod = size == 1 ? '' : CAN_ADDRESS_2GB ? ('>>>' + shift) : ('>>' + shift);
428+
const mod = size == 1 ? '' : (CAN_ADDRESS_2GB || MEMORY64) ? ('>>>' + shift) : ('>>' + shift);
429429
return `HEAP${which}.subarray((${start})${mod}, (${end})${mod})`;
430430
}
431431

0 commit comments

Comments
 (0)