nissy-core

The "engine" of nissy, including the H48 optimal solver.
git clone https://git.tronto.net/nissy-core
Download | Log | Files | Refs | README | LICENSE

commit b1770039f4d483cdab2d4d136cd7ffbf12f165b7
parent fcf5a819ef52ab3069f687e6943599fa3ccf96b3
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Wed, 28 May 2025 14:32:38 +0200

Enable WASM64

Diffstat:
Mbuild | 9++++++---
Mweb/callback.js | 9++++++++-
Mweb/http/index.html | 2+-
Mweb/http/nissyapp.mjs | 14--------------
Mweb/storage.cpp | 7+++++--
Mweb/worker.mjs | 7++-----
6 files changed, 22 insertions(+), 26 deletions(-)

diff --git a/build b/build @@ -127,9 +127,12 @@ MFLAGS="-DTHREADS=$THREADS -D$ARCH" CPPFLAGS="-std=c++20 -pthread" # Build flags for emscripten (WASM target) -WASMCFLAGS="-std=c11 -fPIC -D_POSIX_C_SOURCE=199309L -pthread" +WASMCFLAGS="-std=c11 -fPIC -D_POSIX_C_SOURCE=199309L -pthread \ + -sMEMORY64 -sMAXIMUM_MEMORY=10737418240 -sASSERTIONS" +WASMCPPFLAGS="-std=c++20 -pthread -sMEMORY64 -sMAXIMUM_MEMORY=10737418240 \ + -sASSERTIONS" WASMMFLAGS="-DTHREADS=$THREADS -DWASMSIMD" -WASMLINKFLAGS="--no-entry -sEXPORT_NAME='Nissy' -sMODULARIZE \ +WASMLINKFLAGS="--no-entry -sEXPORT_NAME='Nissy' -sMODULARIZE -sMEMORY64 \ -sALLOW_MEMORY_GROWTH -sSTACK_SIZE=5MB -sPTHREAD_POOL_SIZE=$THREADS \ -sFETCH -sASYNCIFY -sLINKABLE -sEXPORT_ALL" @@ -271,7 +274,7 @@ build_web() { run $EMCC $WASMCFLAGS $WFLAGS $WASMMFLAGS $(odflags) -c \ -o nissy.o src/nissy.c || exit 1 run $EMCC -lembind -lidbfs.js \ - $CPPFLAGS $(odflags) $WASMLINKFLAGS \ + $WASMCPPFLAGS $(odflags) $WASMLINKFLAGS \ --js-library web/callback.js -o web/"$obj".mjs \ cpp/nissy.cpp web/storage.cpp web/adapter.cpp nissy.o || exit 1 cp web/"$obj".mjs web/http/ diff --git a/web/callback.js b/web/callback.js @@ -31,8 +31,15 @@ addCallbackFunction: function(f) { callFunction__deps: [ 'cbfl', 'validateCallbackId' ], callFunction: function(id, arg) { + // This is a workaround related to usign WASM64 + // JavaScript's UTF8ToString expects a pointer argument, which for JS is + // of type "number", but WASM64 is passing a BigInt. See also: + // https://github.com/emscripten-core/emscripten/issues/21541 + // (but I could not make the suggested solution work in this case). + // TODO: check if there is a better workaround. + const non64_arg = Number(arg); if (_validateCallbackId(id)) - _cbfl[id](UTF8ToString(arg)); + _cbfl[id](UTF8ToString(non64_arg)); }, callFunctionInt__deps: [ 'cbfl', 'validateCallbackId' ], diff --git a/web/http/index.html b/web/http/index.html @@ -11,7 +11,7 @@ <select id="solverSelector"> <option value="h48h0k4">h48 h=0 k=4 (59Mb)</option> <option value="h48h3k2" selected="selected">h48 h=3 k=2 (283Mb)</option> - <!--option value="h48h7k2">h48 h=7 k=2 (3.6Gb)</option--> + <option value="h48h7k2">h48 h=7 k=2 (3.6Gb)</option> </select> <button id="solveButton">Solve</button> <div id="confirmDownload" style="display:none"> diff --git a/web/http/nissyapp.mjs b/web/http/nissyapp.mjs @@ -50,20 +50,6 @@ solveButton.addEventListener("click", () => { const solver = solverSelector.options[solverSelector.selectedIndex].value; const scramble = scrField.value; loadDataThenSolve(solver, scramble); - - const solveCallbackId = ++lastCallbackId; - callbacks.set(solveCallbackId, { - f: (callbackArg, loadResult) => { - if (loadResult.success) { - startSolve(callbackArg.solver, callbackArg.scramble); - } else { - updateResults("", "", true); - } - }, - arg: { solver: solver, scramble: scramble } - }); - - const downloadCallbackId = ++lastCallbackId; }); function loadDataThenSolve(solver, scramble) { diff --git a/web/storage.cpp b/web/storage.cpp @@ -43,8 +43,11 @@ EM_ASYNC_JS(int, download_and_store, (const char *key, const char *url), { self instanceof WorkerGlobalScope; console.assert(inBrowser || inWorker, "Non-browsers not supported"); - url = UTF8ToString(url); - key = UTF8ToString(key); + // See comment in callback.js about this workaround + const non64_url = Number(url); + const non64_key = Number(key); + url = UTF8ToString(non64_url); + key = UTF8ToString(non64_key); let response = await fetch(url); if (!response.ok) { console.log("Error downloading data for " + key); diff --git a/web/worker.mjs b/web/worker.mjs @@ -1,10 +1,7 @@ import Nissy from "./nissy_web_module.mjs" const nissy = await Nissy(); -function log(message) { - postMessage({ command: "log", id: -1, object: message }); - console.log(message); -} +const log = (msg) => postMessage({ command: "log", id: -1, object: msg }); nissy.setLogger(nissy._addCallbackFunction(log)); const commands = [ @@ -32,7 +29,7 @@ onmessage = (event) => { } } - log("[nissy worker] unknown command " + event.data.command); + console.log("[nissy worker] unknown command " + event.data.command); }; // Load solver data from storage.