Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor makeHEAPView to use getHeapOffset. NFC #21332

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions src/parseTools.js
Original file line number Diff line number Diff line change
@@ -297,14 +297,17 @@ function getNativeTypeSize(type) {

function getHeapOffset(offset, type) {
const sz = getNativeTypeSize(type);
const shifts = Math.log(sz) / Math.LN2;
if (sz == 1) {
return offset;
}
if (MEMORY64 == 1) {
return `((${offset})/${2 ** shifts})`;
} else if (CAN_ADDRESS_2GB) {
return `((${offset})/${sz})`;
}
const shifts = Math.log(sz) / Math.LN2;
if (CAN_ADDRESS_2GB) {
return `((${offset})>>>${shifts})`;
} else {
return `((${offset})>>${shifts})`;
}
return `((${offset})>>${shifts})`;
}

function ensureDot(value) {
@@ -427,19 +430,24 @@ function makeSetValueImpl(ptr, pos, value, type) {
}

function makeHEAPView(which, start, end) {
const size = parseInt(which.replace('U', '').replace('F', '')) / 8;
const shift = Math.log2(size);
let mod = '';
if (size != 1) {
if (MEMORY64) {
mod = '/' + size;
} else if (CAN_ADDRESS_2GB) {
mod = '>>>' + shift;
} else {
mod = '>>' + shift;
}
}
return `HEAP${which}.subarray((${start})${mod}, (${end})${mod})`;
// The makeHEAPView, for legacy reasons, takes a heap "suffix"
// rather than the heap "type" that used by other APIs here.
const type = {
'8': 'i8',
'U8': 'u8',
'16': 'i16',
'U16': 'u16',
'32': 'i32',
'U32': 'u32',
'64': 'i64',
'U64': 'u64',
'F32': 'float',
'F64': 'double',
}[which];
const heap = getHeapForType(type);
start = getHeapOffset(start, type);
end = getHeapOffset(end, type);
return `${heap}.subarray((${start}), ${end})`;
}

// Given two values and an operation, returns the result of that operation.
8 changes: 4 additions & 4 deletions test/code_size/embind_val_wasm.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.html": 673,
"a.html.gz": 431,
"a.js": 7086,
"a.js.gz": 3000,
"a.js": 7080,
"a.js.gz": 2999,
"a.wasm": 11433,
"a.wasm.gz": 5725,
"total": 19192,
"total_gz": 9156
"total": 19186,
"total_gz": 9155
}
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_ctors1.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9959
9953
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_ctors1.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24516
24510
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_ctors2.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9944
9939
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_ctors2.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24484
24478
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_except.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11032
11034
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_except.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
28406
28382
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_except_wasm.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9925
9921
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_except_wasm.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24409
24403
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_mangle.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
28407
28383
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_noexcept.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9959
9953
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_noexcept.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24516
24510
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_wasmfs.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5250
5245
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_wasmfs.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12128
12122
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2448
2445
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5212
5206
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_mem_O3_standalone.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2415
2411
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_mem_O3_standalone.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5142
5136
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size.js.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
58128
58100
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size_no_asserts.js.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
31591
31563
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size_strict.js.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
57039
57011