引擎应该如何评估这段 ASM.js 代码?

How this piece of ASM.js code should be evaluated by the engine?

根据规范,ASM.js 中的类型“int”没有符号。

The int type is the type of 32-bit integers where the signedness is not known. In asm.js, the type of a variable never has a known signedness. This allows them to be compiled as 32-bit integer registers and memory words. However, this representation creates an overlap between signed and unsigned numbers that causes an ambiguity in determining which JavaScript number they represent. For example, the bit pattern 0xffffffff could represent 4294967295 or -1, depending on the signedness. For this reason, values of the int type are disallowed from escaping into external (non-asm.js) JavaScript code.

那么引擎如何评估下面的一段ASM.js代码呢?因为如果参数 x 和 y 具有不同的符号,结果可能会不同。我们如何为它生成 AOT 代码?

function foo(start, end) {
  start = start|0;  // start is int.
  end = end|0;  // start is int.

  return +((end - start)|0);
}

|0 转换为有符号整数。所以该函数中的所有值和操作都是有符号的。

(但是,对于减法,符号无论如何都无关紧要 - 它是一条用于有符号或无符号的 CPU 指令,请参阅