Lazarus

Programming => Networking and Web Programming => Pas2JS => Topic started by: lainz on April 13, 2019, 09:19:46 pm

Title: Asm.js optimizations
Post by: lainz 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.
Title: Re: Asm.js optimizations
Post by: mattias 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.
Title: Re: Asm.js optimizations
Post by: lainz 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