Skip to content

Commit b8bdd3b

Browse files
authored
Use unsigned types for POINTER_TYPE (#16874)
This seems to be slight codesize win because the generated code for `makeGetValue`/`makeSetValue` I guess is slightly smaller for unsigned types.
1 parent 2254fbe commit b8bdd3b

File tree

6 files changed

+24
-20
lines changed

6 files changed

+24
-20
lines changed

src/library.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3524,13 +3524,13 @@ LibraryManager.library = {
35243524
// mode are created here and imported by the module.
35253525
// Mark with `__import` so these are usable from native code. This is needed
35263526
// because, by default, only functions can be be imported.
3527-
__stack_pointer: "new WebAssembly.Global({'value': '{{{ POINTER_TYPE }}}', 'mutable': true}, {{{ to64(STACK_BASE) }}})",
3527+
__stack_pointer: "new WebAssembly.Global({'value': '{{{ POINTER_WASM_TYPE }}}', 'mutable': true}, {{{ to64(STACK_BASE) }}})",
35283528
__stack_pointer__import: true,
35293529
// tell the memory segments where to place themselves
3530-
__memory_base: "new WebAssembly.Global({'value': '{{{ POINTER_TYPE }}}', 'mutable': false}, {{{ to64(GLOBAL_BASE) }}})",
3530+
__memory_base: "new WebAssembly.Global({'value': '{{{ POINTER_WASM_TYPE }}}', 'mutable': false}, {{{ to64(GLOBAL_BASE) }}})",
35313531
__memory_base__import: true,
35323532
// the wasm backend reserves slot 0 for the NULL function pointer
3533-
__table_base: "new WebAssembly.Global({'value': '{{{ POINTER_TYPE }}}', 'mutable': false}, {{{ to64(1) }}})",
3533+
__table_base: "new WebAssembly.Global({'value': '{{{ POINTER_WASM_TYPE }}}', 'mutable': false}, {{{ to64(1) }}})",
35343534
__table_base__import: true,
35353535
#if MEMORY64
35363536
__table_base32: 1,
@@ -3544,11 +3544,11 @@ LibraryManager.library = {
35443544
__heap_base__import: true,
35453545
#if EXCEPTION_HANDLING
35463546
// In dynamic linking we define tags here and feed them to each module
3547-
__cpp_exception: "new WebAssembly.Tag({'parameters': ['{{{ POINTER_TYPE }}}']})",
3547+
__cpp_exception: "new WebAssembly.Tag({'parameters': ['{{{ POINTER_WASM_TYPE }}}']})",
35483548
__cpp_exception__import: true,
35493549
#endif
35503550
#if SUPPORT_LONGJMP == 'wasm'
3551-
__c_longjmp: "new WebAssembly.Tag({'parameters': ['{{{ POINTER_TYPE }}}']})",
3551+
__c_longjmp: "new WebAssembly.Tag({'parameters': ['{{{ POINTER_WASM_TYPE }}}']})",
35523552
__c_longjmp_import: true,
35533553
#endif
35543554
#endif

src/library_dylink.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var LibraryDylink = {
5252
$GOTHandler: {
5353
'get': function(obj, symName) {
5454
if (!GOT[symName]) {
55-
GOT[symName] = new WebAssembly.Global({'value': '{{{ POINTER_TYPE }}}', 'mutable': true});
55+
GOT[symName] = new WebAssembly.Global({'value': '{{{ POINTER_WASM_TYPE }}}', 'mutable': true});
5656
#if DYLINK_DEBUG
5757
err("new GOT entry: " + symName);
5858
#endif

src/library_pthread.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ var LibraryPThread = {
676676
// Proxied canvases string pointer -1 is used as a special token to fetch
677677
// whatever canvases were passed to build in -s
678678
// OFFSCREENCANVASES_TO_PTHREAD= command line.
679-
if (transferredCanvasNames == -1) transferredCanvasNames = '{{{ OFFSCREENCANVASES_TO_PTHREAD }}}';
679+
if (transferredCanvasNames == (-1 >>> 0)) transferredCanvasNames = '{{{ OFFSCREENCANVASES_TO_PTHREAD }}}';
680680
else
681681
#endif
682682
if (transferredCanvasNames) transferredCanvasNames = UTF8ToString(transferredCanvasNames).trim();

src/parseTools.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,15 @@ function needsQuoting(ident) {
176176

177177
const POINTER_SIZE = MEMORY64 ? 8 : 4;
178178
const POINTER_BITS = POINTER_SIZE * 8;
179-
const POINTER_TYPE = 'i' + POINTER_BITS;
180-
179+
const POINTER_TYPE = 'u' + POINTER_BITS;
181180
const SIZE_TYPE = POINTER_TYPE;
182181

182+
// Similar to POINTER_TYPE, but this is the actual wasm type that is
183+
// used in practice, while POINTER_TYPE is the more refined internal
184+
// type (that is unsigned, where as core wasm does not have unsigned
185+
// types).
186+
const POINTER_WASM_TYPE = 'i' + POINTER_BITS;
187+
183188
function isPointerType(type) {
184189
return type[type.length - 1] == '*';
185190
}
@@ -196,7 +201,7 @@ function isIntImplemented(type) {
196201
function getBits(type, allowPointers) {
197202
if (allowPointers && isPointerType(type)) return POINTER_SIZE;
198203
if (!type) return 0;
199-
if (type[0] == 'i') {
204+
if (type[0] == 'i' || type[0] == 'u') {
200205
const left = type.substr(1);
201206
if (!isNumber(left)) return 0;
202207
return parseInt(left);
@@ -660,8 +665,7 @@ function calcFastOffset(ptr, pos, noNeedFirst) {
660665
function getHeapForType(type) {
661666
assert(type);
662667
if (isPointerType(type)) {
663-
// TODO(sbc): Make POINTER_TYPE u32/u64 rather than i32/i64
664-
type = 'u' + POINTER_TYPE.slice(1);
668+
type = POINTER_TYPE;
665669
}
666670
if (WASM_BIGINT) {
667671
switch (type) {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"a.html": 12888,
3-
"a.html.gz": 6990,
4-
"total": 12888,
5-
"total_gz": 6990
2+
"a.html": 12866,
3+
"a.html.gz": 6978,
4+
"total": 12866,
5+
"total_gz": 6978
66
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"a.html": 17413,
3-
"a.html.gz": 7530,
4-
"total": 17413,
5-
"total_gz": 7530
2+
"a.html": 17393,
3+
"a.html.gz": 7522,
4+
"total": 17393,
5+
"total_gz": 7522
66
}

0 commit comments

Comments
 (0)