Search code examples
javascriptasm.js

Inserting ASM.JS code into vanilla javascript


Just a simple question, can I include a section of asm.js code in a set of normal javascript, as a function or otherwise, similar to how I can put ASM code into a C program for areas that need special optimization?


Solution

  • Yes. Use the

    "use asm";
    

    prologue directive on top of the function block (i.e. function or file) that is asm. Full example:

    function MyAsmModule() {
        "use asm";
        // module body
    }
    

    See http://asmjs.org/spec/latest/#introduction for more information