Skip to content

More cleanup of heap access code in parseTools.js. NFC #13292

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

Merged
merged 1 commit into from
Jan 22, 2021
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
20 changes: 10 additions & 10 deletions src/parseTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,15 +509,15 @@ function asmFloatToInt(x) {
function makeGetTempDouble(i, type, forSet) { // get an aliased part of the tempDouble temporary storage
// Cannot use makeGetValue because it uses us
// this is a unique case where we *can* use HEAPF64
var slab = type == 'double' ? 'HEAPF64' : makeGetSlabs(null, type)[0];
var heap = getHeapForType(type);
var ptr = getFastValue('tempDoublePtr', '+', Runtime.getNativeTypeSize(type)*i);
var offset;
if (type == 'double') {
offset = '(' + ptr + ')>>3';
} else {
offset = getHeapOffset(ptr, type);
}
var ret = slab + '[' + offset + ']';
var ret = heap + '[' + offset + ']';
if (!forSet) ret = asmCoercion(ret, type);
return ret;
}
Expand Down Expand Up @@ -582,7 +582,7 @@ function makeGetValue(ptr, pos, type, noNeedFirst, unsigned, ignore, align, noSa
return asmCoercion('SAFE_HEAP_LOAD' + ((type in Compiletime.FLOAT_TYPES) ? '_D' : '') + '(' + asmCoercion(offset, 'i32') + ', ' + Runtime.getNativeTypeSize(type) + ', ' + (!!unsigned+0) + ')', type, unsigned ? 'u' : undefined);
}
}
return makeGetSlabs(ptr, type, false, unsigned)[0] + '[' + getHeapOffset(offset, type) + ']';
return getHeapForType(type, unsigned) + '[' + getHeapOffset(offset, type) + ']';
}

//! @param ptr The pointer. Used to find both the slab and the offset in that slab. If the pointer
Expand Down Expand Up @@ -656,7 +656,7 @@ function makeSetValue(ptr, pos, value, type, noNeedFirst, ignore, align, noSafe,
return 'SAFE_HEAP_STORE' + ((type in Compiletime.FLOAT_TYPES) ? '_D' : '') + '(' + asmCoercion(offset, 'i32') + ', ' + asmCoercion(value, type) + ', ' + Runtime.getNativeTypeSize(type) + ')';
}
}
return makeGetSlabs(ptr, type, true).map(function(slab) { return slab + '[' + getHeapOffset(offset, type) + ']=' + value }).join(sep);
return getHeapForType(type) + '[' + getHeapOffset(offset, type) + '] = ' + value;
}

var UNROLL_LOOP_MAX = 8;
Expand Down Expand Up @@ -809,26 +809,26 @@ function calcFastOffset(ptr, pos, noNeedFirst) {
return getFastValue(ptr, '+', pos, 'i32');
}

function makeGetSlabs(ptr, type, allowMultiple, unsigned) {
function getHeapForType(type, unsigned) {
assert(type);
if (isPointerType(type)) {
type = 'i32'; // Hardcoded 32-bit
}
switch (type) {
case 'i1':
case 'i8':
return [unsigned ? 'HEAPU8' : 'HEAP8'];
return unsigned ? 'HEAPU8' : 'HEAP8';
case 'i16':
return [unsigned ? 'HEAPU16' : 'HEAP16'];
return unsigned ? 'HEAPU16' : 'HEAP16';
case '<4 x i32>':
case 'i32':
case 'i64':
return [unsigned ? 'HEAPU32' : 'HEAP32'];
return unsigned ? 'HEAPU32' : 'HEAP32';
case 'double':
return ['HEAPF64'];
return 'HEAPF64';
case '<4 x float>':
case 'float':
return ['HEAPF32'];
return 'HEAPF32';
}
assert(false, 'bad heap type: ' + type);
}
Expand Down