Skip to content

Kill QUANTUM_SIZE setting variable #5826

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,6 @@ def check(input_file):
assert shared.Settings.UNALIGNED_MEMORY == 0, 'forced unaligned memory not supported in fastcomp'
assert shared.Settings.FORCE_ALIGNED_MEMORY == 0, 'forced aligned memory is not supported in fastcomp'
assert shared.Settings.PGO == 0, 'pgo not supported in fastcomp'
assert shared.Settings.QUANTUM_SIZE == 4, 'altering the QUANTUM_SIZE is not supported'
except Exception as e:
logging.error('Compiler settings are incompatible with fastcomp. You can fall back to the older compiler core, although that is not recommended, see http://kripken.github.io/emscripten-site/docs/building_from_source/LLVM-Backend.html')
raise e
Expand Down
1 change: 0 additions & 1 deletion src/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ load('modules.js');
load('parseTools.js');
load('jsifier.js');
globalEval(processMacros(preprocess(read('runtime.js'), 'runtime.js')));
Runtime.QUANTUM_SIZE = QUANTUM_SIZE;

//===============================
// Main
Expand Down
25 changes: 12 additions & 13 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,7 @@ LibraryManager.library = {
ENV['_'] = Module['thisProgram'];
// Allocate memory.
poolPtr = allocate(TOTAL_ENV_SIZE, 'i8', ALLOC_STATIC);
envPtr = allocate(MAX_ENV_VALUES * {{{ Runtime.QUANTUM_SIZE }}},
'i8*', ALLOC_STATIC);
envPtr = allocate(MAX_ENV_VALUES * 4, 'i8*', ALLOC_STATIC);
{{{ makeSetValue('envPtr', '0', 'poolPtr', 'i8*') }}};
{{{ makeSetValue(makeGlobalUse('_environ'), 0, 'envPtr', 'i8*') }}};
} else {
Expand Down Expand Up @@ -1001,17 +1000,17 @@ LibraryManager.library = {
llvm_va_start__inline: function(ptr) {
// varargs - we received a pointer to the varargs as a final 'extra' parameter called 'varrp'
// 2-word structure: struct { void* start; void* currentOffset; }
return makeSetValue(ptr, 0, 'varrp', 'void*') + ';' + makeSetValue(ptr, Runtime.QUANTUM_SIZE, 0, 'void*');
return makeSetValue(ptr, 0, 'varrp', 'void*') + ';' + makeSetValue(ptr, 4, 0, 'void*');
},

llvm_va_end: function() {},

llvm_va_copy: function(ppdest, ppsrc) {
// copy the list start
{{{ makeCopyValues('ppdest', 'ppsrc', Runtime.QUANTUM_SIZE, 'null', null, 1) }}};
{{{ makeCopyValues('ppdest', 'ppsrc', 4, 'null', null, 1) }}};

// copy the list's current offset (will be advanced with each call to va_arg)
{{{ makeCopyValues('(ppdest+'+Runtime.QUANTUM_SIZE+')', '(ppsrc+'+Runtime.QUANTUM_SIZE+')', Runtime.QUANTUM_SIZE, 'null', null, 1) }}};
{{{ makeCopyValues('(ppdest+'+4+')', '(ppsrc+'+4+')', 4, 'null', null, 1) }}};
},

llvm_bswap_i16__asm: true,
Expand Down Expand Up @@ -1840,9 +1839,9 @@ LibraryManager.library = {
// report all function pointers as coming from this program itself XXX not really correct in any way
var fname = allocate(intArrayFromString(Module['thisProgram'] || './this.program'), 'i8', ALLOC_NORMAL); // XXX leak
{{{ makeSetValue('addr', 0, 'fname', 'i32') }}};
{{{ makeSetValue('addr', QUANTUM_SIZE, '0', 'i32') }}};
{{{ makeSetValue('addr', QUANTUM_SIZE*2, '0', 'i32') }}};
{{{ makeSetValue('addr', QUANTUM_SIZE*3, '0', 'i32') }}};
{{{ makeSetValue('addr', 4, '0', 'i32') }}};
{{{ makeSetValue('addr', 8, '0', 'i32') }}};
{{{ makeSetValue('addr', 12, '0', 'i32') }}};
return 1;
},

Expand Down Expand Up @@ -2000,7 +1999,7 @@ LibraryManager.library = {
var dst = (summerOffset != winterOffset && date.getTimezoneOffset() == Math.min(winterOffset, summerOffset))|0;
{{{ makeSetValue('tmPtr', C_STRUCTS.tm.tm_isdst, 'dst', 'i32') }}};

var zonePtr = {{{ makeGetValue(makeGlobalUse('_tzname'), 'dst ? Runtime.QUANTUM_SIZE : 0', 'i32') }}};
var zonePtr = {{{ makeGetValue(makeGlobalUse('_tzname'), 'dst ? 4 : 0', 'i32') }}};
{{{ makeSetValue('tmPtr', C_STRUCTS.tm.tm_zone, 'zonePtr', 'i32') }}};

return tmPtr;
Expand Down Expand Up @@ -2061,11 +2060,11 @@ LibraryManager.library = {
// TODO: Initialize these to defaults on startup from system settings.
// Note: glibc has one fewer underscore for all of these. Also used in other related functions (timegm)
#if USE_PTHREADS
tzname: '; if (ENVIRONMENT_IS_PTHREAD) _tzname = PthreadWorkerInit._tzname; else PthreadWorkerInit._tzname = _tzname = allocate({{{ 2*Runtime.QUANTUM_SIZE }}}, "i32*", ALLOC_STATIC)',
tzname: '; if (ENVIRONMENT_IS_PTHREAD) _tzname = PthreadWorkerInit._tzname; else PthreadWorkerInit._tzname = _tzname = allocate({{{ 8 }}}, "i32*", ALLOC_STATIC)',
daylight: '; if (ENVIRONMENT_IS_PTHREAD) _daylight = PthreadWorkerInit._daylight; else PthreadWorkerInit._daylight = _daylight = allocate(1, "i32*", ALLOC_STATIC)',
timezone: '; if (ENVIRONMENT_IS_PTHREAD) _timezone = PthreadWorkerInit._timezone; else PthreadWorkerInit._timezone = _timezone = allocate(1, "i32*", ALLOC_STATIC)',
#else
tzname: '{{{ makeStaticAlloc(2*Runtime.QUANTUM_SIZE) }}}',
tzname: '{{{ makeStaticAlloc(8) }}}',
daylight: '{{{ makeStaticAlloc(1) }}}',
timezone: '{{{ makeStaticAlloc(1) }}}',
#endif
Expand Down Expand Up @@ -2094,10 +2093,10 @@ LibraryManager.library = {
if (summer.getTimezoneOffset() < winter.getTimezoneOffset()) {
// Northern hemisphere
{{{ makeSetValue(makeGlobalUse('_tzname'), '0', 'winterNamePtr', 'i32') }}};
{{{ makeSetValue(makeGlobalUse('_tzname'), Runtime.QUANTUM_SIZE, 'summerNamePtr', 'i32') }}};
{{{ makeSetValue(makeGlobalUse('_tzname'), '4', 'summerNamePtr', 'i32') }}};
} else {
{{{ makeSetValue(makeGlobalUse('_tzname'), '0', 'summerNamePtr', 'i32') }}};
{{{ makeSetValue(makeGlobalUse('_tzname'), Runtime.QUANTUM_SIZE, 'winterNamePtr', 'i32') }}};
{{{ makeSetValue(makeGlobalUse('_tzname'), '4', 'winterNamePtr', 'i32') }}};
}
},

Expand Down
8 changes: 4 additions & 4 deletions src/library_browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,19 +659,19 @@ var LibraryBrowser = {
setFullscreenCanvasSize: function() {
// check if SDL is available
if (typeof SDL != "undefined") {
var flags = {{{ makeGetValue('SDL.screen+Runtime.QUANTUM_SIZE*0', '0', 'i32', 0, 1) }}};
var flags = {{{ makeGetValue('SDL.screen', '0', 'i32', 0, 1) }}};
flags = flags | 0x00800000; // set SDL_FULLSCREEN flag
{{{ makeSetValue('SDL.screen+Runtime.QUANTUM_SIZE*0', '0', 'flags', 'i32') }}}
{{{ makeSetValue('SDL.screen', '0', 'flags', 'i32') }}}
}
Browser.updateResizeListeners();
},

setWindowedCanvasSize: function() {
// check if SDL is available
if (typeof SDL != "undefined") {
var flags = {{{ makeGetValue('SDL.screen+Runtime.QUANTUM_SIZE*0', '0', 'i32', 0, 1) }}};
var flags = {{{ makeGetValue('SDL.screen', '0', 'i32', 0, 1) }}};
flags = flags & ~0x00800000; // clear SDL_FULLSCREEN flag
{{{ makeSetValue('SDL.screen+Runtime.QUANTUM_SIZE*0', '0', 'flags', 'i32') }}}
{{{ makeSetValue('SDL.screen', '0', 'flags', 'i32') }}}
}
Browser.updateResizeListeners();
},
Expand Down
18 changes: 9 additions & 9 deletions src/library_sdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1379,12 +1379,12 @@ var LibrarySDL = {
SDL_GetVideoInfo__sig: 'i',
SDL_GetVideoInfo: function() {
// %struct.SDL_VideoInfo = type { i32, i32, %struct.SDL_PixelFormat*, i32, i32 } - 5 fields of quantum size
var ret = _malloc(5*Runtime.QUANTUM_SIZE);
{{{ makeSetValue('ret+Runtime.QUANTUM_SIZE*0', '0', '0', 'i32') }}}; // TODO
{{{ makeSetValue('ret+Runtime.QUANTUM_SIZE*1', '0', '0', 'i32') }}}; // TODO
{{{ makeSetValue('ret+Runtime.QUANTUM_SIZE*2', '0', '0', 'void*') }}};
{{{ makeSetValue('ret+Runtime.QUANTUM_SIZE*3', '0', 'Module["canvas"].width', 'i32') }}};
{{{ makeSetValue('ret+Runtime.QUANTUM_SIZE*4', '0', 'Module["canvas"].height', 'i32') }}};
var ret = _malloc(20);
{{{ makeSetValue('ret', '0', '0', 'i32') }}}; // TODO
{{{ makeSetValue('ret+4', '0', '0', 'i32') }}}; // TODO
{{{ makeSetValue('ret+8', '0', '0', 'void*') }}};
{{{ makeSetValue('ret+12', '0', 'Module["canvas"].width', 'i32') }}};
{{{ makeSetValue('ret+16', '0', 'Module["canvas"].height', 'i32') }}};
return ret;
},

Expand Down Expand Up @@ -2225,9 +2225,9 @@ var LibrarySDL = {
}
}
var callStbImage = function(func, params) {
var x = Module['_malloc']({{{ QUANTUM_SIZE }}});
var y = Module['_malloc']({{{ QUANTUM_SIZE }}});
var comp = Module['_malloc']({{{ QUANTUM_SIZE }}});
var x = Module['_malloc'](4);
var y = Module['_malloc'](4);
var comp = Module['_malloc'](4);
addCleanup(function() {
Module['_free'](x);
Module['_free'](y);
Expand Down
2 changes: 1 addition & 1 deletion src/parseTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ function makePointer(slab, pos, allocator, type, ptr, finalMemoryInitialization)
if (!finalMemoryInitialization) {
// writing out into memory, without a normal allocation. We put all of these into a single big chunk.
assert(typeof slab == 'object');
assert(slab.length % QUANTUM_SIZE == 0, slab.length); // must be aligned already
assert(slab.length % 4 == 0, slab.length); // must be aligned already
if (SIDE_MODULE && typeof ptr == 'string') {
ptr = parseInt(ptr.substring(ptr.indexOf('+'), ptr.length-1)); // parse into (H_BASE+X)
}
Expand Down
2 changes: 1 addition & 1 deletion src/postamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ Module['callMain'] = Module.callMain = function callMain(args) {

var argc = args.length+1;
function pad() {
for (var i = 0; i < {{{ QUANTUM_SIZE }}}-1; i++) {
for (var i = 0; i < 3; i++) {
argv.push(0);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var RuntimeGenerator = {
},

forceAlign: function(target, quantum) {
quantum = quantum || {{{ QUANTUM_SIZE }}};
quantum = quantum || 4;
if (quantum == 1) return target;
if (isNumber(target) && isNumber(quantum)) {
return Math.ceil(target/quantum)*quantum;
Expand Down Expand Up @@ -156,7 +156,7 @@ var Runtime = {
case 'double': return 8;
default: {
if (type[type.length-1] === '*') {
return Runtime.QUANTUM_SIZE; // A pointer
return 4; // A pointer
} else if (type[0] === 'i') {
var bits = parseInt(type.substr(1));
assert(bits % 8 === 0);
Expand All @@ -172,7 +172,7 @@ var Runtime = {
//! for now).
//! @param type The type, by name.
getNativeFieldSize: function(type) {
return Math.max(Runtime.getNativeTypeSize(type), Runtime.QUANTUM_SIZE);
return Math.max(Runtime.getNativeTypeSize(type), 4);
},

STACK_ALIGN: {{{ STACK_ALIGN }}},
Expand All @@ -197,7 +197,7 @@ var Runtime = {
// we align i64s and doubles on 64-bit boundaries, unlike x86
if (!vararg && (type == 'i64' || type == 'double')) return 8;
if (!type) return Math.min(size, 8); // align structures internally to 64 bits
return Math.min(size || (type ? Runtime.getNativeFieldSize(type) : 0), Runtime.QUANTUM_SIZE);
return Math.min(size || (type ? Runtime.getNativeFieldSize(type) : 0), 4);
},

dynCall: function(sig, ptr, args) {
Expand Down
9 changes: 0 additions & 9 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@
//

// Tuning
var QUANTUM_SIZE = 4; // This is the size of an individual field in a structure. 1 would
// lead to e.g. doubles and chars both taking 1 memory address. This
// is a form of 'compressed' memory, with shrinking and stretching
// according to the type, when compared to C/C++. On the other hand
// the normal value of 4 means all fields take 4 memory addresses,
// as per the norm on a 32-bit machine.
//
// Changing this from the default of 4 is deprecated.

var ASSERTIONS = 1; // Whether we should add runtime assertions, for example to
// check that each allocation to the stack does not
// exceed its size, whether all allocations (stack and static) are
Expand Down
1 change: 0 additions & 1 deletion tests/core/emscripten_get_compiler_setting.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <emscripten.h>

int main() {
printf("QS: %d\n", emscripten_get_compiler_setting("QUANTUM_SIZE"));
assert((unsigned)emscripten_get_compiler_setting("OPT_LEVEL") <= 3);
assert((unsigned)emscripten_get_compiler_setting("DEBUG_LEVEL") <= 4);
printf("EV: %s\n", (char*)emscripten_get_compiler_setting("EMSCRIPTEN_VERSION"));
Expand Down
1 change: 0 additions & 1 deletion tests/core/emscripten_get_compiler_setting.out
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
QS: 4
EV: waka
5 changes: 2 additions & 3 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2138,8 +2138,7 @@ def test_statics(self):
def test_copyop(self):
# clang generated code is vulnerable to this, as it uses
# memcpy for assignments, with hardcoded numbers of bytes
# (llvm-gcc copies items one by one). See QUANTUM_SIZE in
# settings.js.
# (llvm-gcc copies items one by one).
test_path = path_from_root('tests', 'core', 'test_copyop')
src, output = (test_path + s for s in ('.c', '.out'))

Expand Down Expand Up @@ -7160,7 +7159,7 @@ def test_wrap_malloc(self):
self.do_run(open(path_from_root('tests', 'wrap_malloc.cpp')).read(), 'OK.')

# Generate tests for everything
def make_run(fullname, name=-1, compiler=-1, embetter=0, quantum_size=0,
def make_run(fullname, name=-1, compiler=-1, embetter=0,
typed_arrays=0, emcc_args=None, env=None):

if env is None: env = {}
Expand Down
2 changes: 1 addition & 1 deletion tools/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ def __init__(self):

@classmethod
def reset(self):
self.attrs = { 'QUANTUM_SIZE': 4 }
self.attrs = { }
self.load()

# Given some emcc-type args (-O3, -s X=Y, etc.), fill Settings with the right settings
Expand Down