Recent

Author Topic: Asm.js optimizations  (Read 2343 times)

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Asm.js optimizations
« on: April 13, 2019, 09:19:46 pm »
Asm.js
https://en.wikipedia.org/wiki/Asm.js

Is the pas2js output javascript code optimized like is described in that wiki article, for example:

Code: C  [Select][+][-]
  1. int f(int i) {
  2.   return i + 1;
  3. }

That in Pascal is something like:

Code: Pascal  [Select][+][-]
  1. function f(i: integer): integer;
  2. begin
  3.   Result := i + 1;
  4. end;

And translated to Asm.js

Code: Javascript  [Select][+][-]
  1. function f(i) {
  2.   i = i|0;
  3.   return (i + 1)|0;
  4. }

The extra "|0" converts the variables to int32 acording to the article, so it doesn't use floating point math.
« Last Edit: April 13, 2019, 09:24:29 pm by Lainz »

mattias

  • Administrator
  • Full Member
  • *
  • Posts: 184
    • http://www.lazarus.freepascal.org
Re: Asm.js optimizations
« Reply #1 on: April 13, 2019, 10:08:28 pm »
No, but it would be possible to add an option to do so.
I did not take a look what other conversions are needed, so I can't estimate how much work it is.

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: Asm.js optimizations
« Reply #2 on: April 13, 2019, 11:43:00 pm »
Hi thanks for the quick response.

Ok it will be great and another reason to choose pas2js instead of emscriptem.

 

TinyPortal © 2005-2018