add webassembly support for ceval

pull/2753/head
Niklas Fiekas 2017-03-03 23:44:20 +01:00
parent 9e0695ff1d
commit b3f6192f2b
5 changed files with 9 additions and 5 deletions

@ -1 +1 @@
Subproject commit 63e11e4a01c2c9c9574a177c069df9f1221dc827
Subproject commit e7e57b95d48d6cac0ebc7f0b422123111b1b51cb

View File

@ -490,7 +490,7 @@ module.exports = function(opts) {
var env = this.ceval.env();
var desc = [
'ceval crash',
env.pnacl ? 'native' : 'asmjs',
env.pnacl ? 'pnacl' : (env.wasm ? 'wasm' : 'asmjs'),
'multiPv:' + env.multiPv,
'threads:' + env.threads,
'hashSize:' + env.hashSize,

View File

@ -12,6 +12,7 @@ module.exports = function(opts) {
};
var pnaclSupported = !opts.failsafe && navigator.mimeTypes['application/x-pnacl'];
var wasmSupported = !opts.failsafe && typeof WebAssembly === 'object' && WebAssembly.validate(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
var minDepth = 6;
var maxDepth = storedProp(storageKey('ceval.max-depth'), 18);
var multiPv = storedProp(storageKey('ceval.multipv'), opts.multiPvDefault || 1);
@ -28,8 +29,9 @@ module.exports = function(opts) {
var isDeeper = m.prop(false);
var pool = makePool(stockfishProtocol, {
asmjs: '/assets/vendor/stockfish.js/stockfish.js?v=16',
asmjs: '/assets/vendor/stockfish.js/stockfish.js?v=17',
pnacl: pnaclSupported && '/assets/vendor/stockfish.pexe/nacl/stockfish.nmf?v=16',
wasm: wasmSupported && '/assets/vendor/stockfish.js/stockfish.wasm.js?v=17',
onCrash: opts.onCrash
}, {
minDepth: minDepth,
@ -152,6 +154,7 @@ module.exports = function(opts) {
return {
pnaclSupported: pnaclSupported,
wasmSupported: wasmSupported,
start: start,
stop: stop,
allowed: allowed,
@ -193,6 +196,7 @@ module.exports = function(opts) {
env: function() {
return {
pnacl: !!pnaclSupported,
wasm: !!wasmSupported,
multiPv: multiPv(),
threads: threads(),
hashSize: hashSize(),

View File

@ -43,7 +43,7 @@ function makeHelper(makeWorker, terminateWorker, poolOpts, makeProtocol, protoco
function makeWebWorker(makeProtocol, poolOpts, protocolOpts) {
return makeHelper(function() {
return new Worker(poolOpts.asmjs);
return new Worker(poolOpts.wasm || poolOpts.asmjs);
}, function(worker) {
worker.terminate();
}, poolOpts, makeProtocol, protocolOpts);

View File

@ -70,7 +70,7 @@ function threatButton(ctrl) {
function engineName(ctrl) {
return [
lichess.engineName,
ctrl.pnaclSupported ? m('span.native', 'native') : m('span.asmjs', 'asmjs')
ctrl.pnaclSupported ? m('span.native', 'pnacl') : (ctrl.wasmSupported ? m('span.native', 'wasm') : m('span.asmjs', 'asmjs'))
];
}