Live data from Hacker News

Compiling LLJS to asm.js

jlongster.com

21–30 of 35 posts

Re: Compiling LLJS to asm.js

#22

I am sure there is some reason this can't be done, but can we compile JavaScript to asm.js? If this can be done with C, it can be done with JS?

Sure, but it's different because you need to compile a whole VM to asm.js and run javascript inside of it. You can't compile a dynamic language like javascript to low-level code because you need too much information at runtime.

See this project, which compiles SpiderMonkey to javascript via emscripten, which supports asm.js: https://github.com/jterrace/js.js/

Re: Compiling LLJS to asm.js

#23

Yesterday I rewrote a tiny Javascript demo in asm.js and also saw an order-of-magnitude speedup. (I thought at first it didn't help at all, apparently because the framerate was limited by setInterval().) Code at http://wry.me/hacking/canvas_asm.html

Cool. I recently wrote a low-level sha1 implementation in pure javascript, trying to leverage asm.js (http://github.com/srijs/rusha).

Can you tell me, how did you confirm you wrote valid asm.js and there was no fallback-mechanism kicking in?

I benchmarked my implementation, of course, and noticed a 2x speedup. However, this seems quite less for the this type of low-level algorithm...

Re: Compiling LLJS to asm.js

#24
post #23

Yesterday I rewrote a tiny Javascript demo in asm.js and also saw an order-of-magnitude speedup. (I thought at first it didn't help at all, apparently because the framerate was limited by setInterval().) Code at http://wry.me/hacking/canvas_asm.html

Cool. I recently wrote a low-level sha1 implementation in pure javascript, trying to leverage asm.js ( http://github.com/srijs/rusha ). Can you tell me, how did you confirm you wrote valid asm.js and there was no fallback-mechanism kicking in? I benchmarked my implementation, of course, and noticed a 2x speedup. However, this seems quite less for the this type of low-level algorithm...

Open the error console (via the Web Developer menu item) and you'll see messages there. Success shows up as "Error: successfully compiled asm.js code." :-)

P.S. Looking at your code, I can tell it's not asm.js conformant yet, though it should just be a bunch of small tweaks (e.g. an expression like (a+b) will need to be (a+b)|0, etc.).

Re: Compiling LLJS to asm.js

#25

I am sure there is some reason this can't be done, but can we compile JavaScript to asm.js? If this can be done with C, it can be done with JS?

Sure, but it's different because you need to compile a whole VM to asm.js and run javascript inside of it. You can't compile a dynamic language like javascript to low-level code because you need too much information at runtime. See this project, which compiles SpiderMonkey to javascript via emscripten, which supports asm.js: https://github.com/jterrace/js.js/

qt-emscripten does something similar, it builds the JSC interpreter together with Qt.

Re: Compiling LLJS to asm.js

#26

Yesterday I rewrote a tiny Javascript demo in asm.js and also saw an order-of-magnitude speedup. (I thought at first it didn't help at all, apparently because the framerate was limited by setInterval().) Code at http://wry.me/hacking/canvas_asm.html

That is the most exciting news I've heard in quite a while.

Re: Compiling LLJS to asm.js

#27
post #23

Earlier quoted context omitted.

Cool. I recently wrote a low-level sha1 implementation in pure javascript, trying to leverage asm.js ( http://github.com/srijs/rusha ). Can you tell me, how did you confirm you wrote valid asm.js and there was no fallback-mechanism kicking in? I benchmarked my implementation, of course, and noticed a 2x speedup. However, this seems quite less for the this type of low-level algorithm...

Open the error console (via the Web Developer menu item) and you'll see messages there. Success shows up as "Error: successfully compiled asm.js code." :-) P.S. Looking at your code, I can tell it's not asm.js conformant yet, though it should just be a bunch of small tweaks (e.g. an expression like (a+b) will need to be (a+b)|0, etc.).

Thank you. I just updated my code and it's really within half of native speed now... (benchmarks in the README, if any of you are interested)

asm.js is very exciting technology!

Re: Compiling LLJS to asm.js

#28
post #27

Earlier quoted context omitted.

Open the error console (via the Web Developer menu item) and you'll see messages there. Success shows up as "Error: successfully compiled asm.js code." :-) P.S. Looking at your code, I can tell it's not asm.js conformant yet, though it should just be a bunch of small tweaks (e.g. an expression like (a+b) will need to be (a+b)|0, etc.).

Thank you. I just updated my code and it's really within half of native speed now... (benchmarks in the README, if any of you are interested) asm.js is very exciting technology!

You're welcome!

Re: Compiling LLJS to asm.js

#29
How far are we from being able to do meaningful text processing with typed arrays and (therefore, presumably) asm.js? Last I checked, there was work being done on a string encoding/decoding standard but it wasn't implemented in browsers yet. Can anyone say more about this?

Re: Compiling LLJS to asm.js

#30
post #15

LLJS, asm.js, & Emscripten are really moving Javascript forward at incredible speed. I wonder if these projects will affect the future of the JS spec (ECMAScript Harmony + above). It's an exciting time to be a web programmer.

These projects are already affecting the spec. Here's a very small example: https://mail.mozilla.org/pipermail/es-discuss/2012-November/... which is used in asm.js and already implemented in Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=808148
Post reply on HN