Closed Bug 924268 Opened 13 years ago Closed 12 years ago

inconsistent return type of Math.abs in asm.js

Categories

(Core :: JavaScript Engine: JIT, defect)

defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: sunfish, Unassigned)

Details

In section 9 "Standard Library" of the asm.js spec (http://asmjs.org/spec/latest/), Math.abs with a signed argument is defined to return unsigned. This is inconsistent with what's actually implemented in OdinMonkey. CheckMathAbs does this: if (argType.isSigned()) { if (retType != RetType::Signed) This testcase: (function(glob) { "use asm"; var abs=glob.Math.abs; function f() { return abs(0)>>>0; } return f; })(this)(0); gets this type error: abs.js:6:11 warning: asm.js type error: non-expression-statement call must be coerced Changing the >>> to | results in no errors.
Component: JavaScript Engine → JavaScript Engine: JIT
Luke, setting needinfo in case you didn't see this.
Flags: needinfo?(luke)
'unsigned' as a return type for 'abs' makes sense, but unfortunately, this is a bug in the spec: at the moment all calls (whether to builtins, ffis, or other asm.js functions) must be explicitly coerced to indicate their return type with one of + or |0 (just like arguments and return statements) or used as an expression-statement (or non-last comma-expresion operand) to indicate a 'void' return. Since this does not include >>>0, 'abs' can only return signed. Thus, I think the spec should say 'signed'. To allow 'abs' to be 'unsigned', we could relax the rules to allow making builtin calls w/o the explicit return-type coercion (which makes sense, since we don't need to infer the return type, we know it from the name). Right now Odin and the spec benefit from the unified call syntax so we haven't been motivated to add this special-case thus far, but it could save space and improve parse times. Feel free to file a bug on the asm.js github repo. I'm tentatively closing this invalid, but feel free to reopen if I've missed something. I'll see about getting 'abs' fixed in the spec.
Status: NEW → RESOLVED
Closed: 12 years ago
Flags: needinfo?(luke)
Resolution: --- → INVALID
The spec is now fixed. The return type of Math.abs is now signed. https://github.com/dherman/asm.js/commit/d16ceee6e962d6f922d19e1047a9399c5cd2ca27
You need to log in before you can comment on or make changes to this bug.