gpt4 book ai didi

javascript - 无法解决 Firefox 的 AMS.js 链接限制

转载 作者:行者123 更新时间:2023-11-28 01:35:56 25 4
gpt4 key购买 nike

我收到错误:

asm.js link error: As a temporary limitation, modules cannot be linked more than once.
This limitation should be removed in a future release. To work around this, compile a second module (e.g., using the Function constructor).

我尚未找到有关此解决方法的任何文档。有人有一个可行的例子吗?

不是我的代码,但这遇到了同样的问题:http://jsperf.com/simplex-noise-comparison-asm使用 FireFox 在控制台中查看问题。

最佳答案

我自己解决了这个问题。这是一个 JSFiddle 链接,供遇到相同问题的人使用: http://jsfiddle.net/QLtMB/

// Store template as actual function, do not use real pragma to avoid compile
var asmTemplate = function MyAsmModule( stdlib, foreign, heap ) {
"asm template";

var HEAP = new stdlib.Uint8Array(heap);
var _sqrt = stdlib.Math.sqrt;
var _sin = stdlib.Math.sin;
var _cos = stdlib.Math.cos;


function fastSqr( x ) {
x = +x;
return +(x*x);
}

function fastSqrt( x ) {
x = +x;
return +_sqrt( x );
}

function fastSin( x ) {
x = +x;
return +_sin( x );
}

function fastCos( x ) {
x = +x;
return +_cos( x );
}

function fastTest( x ) {
x = +x;
return +fastSqr( 2.17 * (+fastSqrt( 0.75 * +fastSin( x ) + 0.25 * +fastCos( x ) )) );
}

return { sqrt: fastSqrt, sin: fastSin, cos: fastCos, test: fastTest };
}

// Generate source string once, replace with real pragma.
asmTemplate = asmTemplate.toString().replace('asm template', 'use asm');

function createASM(buffer) {
window.asmBufferExport = buffer;
return Function(asmTemplate + "\nreturn MyAsmModule( Function( 'return this;' )(), null, asmBufferExport.buffer );")();
}

var Asm = createASM(new Uint8Array(4 * 1024));
var Asm2 = createASM(new Uint8Array(4 * 1024));

作为奖励,这会将您的堆大小四舍五入到 asm.js 标准:

    var size = <actual size>;
// Round up to multiple of 4096
var remainder = size % 4096;
size = remainder ? size + 4096 - remainder : size;
// Round up to the nearest power of 2
size--;
size |= size >> 1; // handle 2 bit numbers
size |= size >> 2; // handle 4 bit numbers
size |= size >> 4; // handle 8 bit numbers
size |= size >> 8; // handle 16 bit numbers
size |= size >> 16; // handle 32 bit numbers
size++;

资源:

关于javascript - 无法解决 Firefox 的 AMS.js 链接限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21541705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com