If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

Odinmonkey: extend annotations to included bitwise subsets of the signed type.




JavaScript Engine
4 years ago
3 years ago


(Reporter: dougc, Unassigned)


Firefox Tracking Flags

(Not tracked)




4 years ago
The asm.js spec. currently supports a few function parameter and
return type annotations including '|0' for the 'signed' type.

For optimization of heap access using index masking it would be
common to apply a bitwise-and operation to the parameters passed
and received by functions, and to results returned by and received
from functions.

If the annotations were extended to support '&n', where 'n' is a
literal constant mask, then it might be possible to eliminate
one side of the masking or the other by enforcing the matching
of the types.


  function intPointerPlus (p1, p2) {
      p1 = p1 & 0xfffc;           // Word aligned pointer argument
      p2 = p2 & 0xfffc;
      return (p1 + p2) & 0xfffc;

  // If the matching of argument and result types were enforced then
  // it would be possible to optimize away the bitwise-and operations in
  // the following while still being able to depend on the callee masking
  // the arguments and depend on the result being a word aligned number
  // in the range 0 to 0xfffc which could help optimize heap access.
  ... intPointerPlus(pa & 0xfffc, pb & 0xfffc) & 0xfffc

Being able to declare results type in this manner could also be
expected to help other compiler optimizations by improving type
information in range analysis.

There might also be a similar issue with variables.  For example
a global variable holding a stack pointer, might be declared to be
a word aligned signed within the range of the heap, and then it
might only be necessary to mask stores rather than also loads while
still being able to depend on a loaded stack pointer being masked
when optimizing heap access.

Rather then enforcing just equality of masks, it would be possible
to accept an input with a more restrictive mask than that declared.

There might also be a gain in the code density if '(... |0)&n'
patterns could be replaced by just '&n'.

Comment 1

4 years ago
I guess I see 2 separate goals: decreasing code size and adding a new type to asm.js that exposed a new optimization.

For the former, it'd be interesting to measure, but I wouldn't expect a huge difference (esp. after gzip).

The latter is pretty intriguing; I'd be curious to see the proposed addition to the type system.


3 years ago
Assignee: general → nobody
You need to log in before you can comment on or make changes to this bug.