Posts

Showing posts with the label asmjs

WebAssembly: a binary format for the web

Image
Updates: [2015-07-02] New material in these sections: How do I create WebAssembly code? First experiences in practice Further reading [2015-06-24] I added an FAQ with three new questions: Does the web finally have a universal bytecode? Isn’t WebAssembly like Flash? Will WebAssembly make JavaScript faster? WebAssembly (short: wasm ) is a new binary format for the web, created by Google, Microsoft, Mozilla and others. It will be used for performance critical code and to compile languages other than JavaScript (especially C/C++) to the web platform. It can be seen as a next step for asm.js [3] . asm.js Most JavaScript engines have the following compilation pipeline: JavaScript source → bytecode → machine code The idea of asm.js is to code JavaScript in such a way that engines produce machine code that is as efficient as possible. That is, you kind of try to bypass the first compilation step. The results are impressive: if one compiles C++ to asm.js one can reach 70% of native speed in we...

JavaScript gains support for SIMD

Recently , a new JavaScript feature has landed for the next Firefox Nightly: an API for SIMD (Single Instruction, Multiple Data). This blog post explains how the API works and how it fits into the JavaScript landscape. What is SIMD? SIMD is the ability of a CPU to apply an operand to vectors of values, instead of single values. For example, a CPU may be able to add two vectors v and w by adding their components, hence applying the single instruction addition to multiple data: v + w = 〈v 1 , …, v n 〉+ 〈w 1 , …, w n 〉 = 〈v 1 +w 1 , …, v n +w n 〉 SIMD brings speed-ups to many kinds of number crunching (3D computations, image processing, singal processing, etc.). John McCutchan (Google) and Peter Jensen (Intel) have proposed a JavaScript API for SIMD. That API initially grew out of the SIMD support in Dart, because Dart SIMD code needed to be compiled to JavaScript. At the moment, the API provides two data types: float32x4 (C type: __m128): four 32 bit floating point n...

Running code fast in web browsers: PNaCl versus asm.js

The main point of the blog post “ Thoughts on asm.js vs PNaCl ” (by Gregg Tavares) is: It just seems like asm.js and PNaCl are closer than people are admitting. Some of the other points he is making are more controversial, so be sure to read the comments to get the complete picture. Comparing the two solutions PNaCl [1] and asm.js [2] are Google’s and Mozilla’s solutions for running code with (near-)native speed in web browsers. asm.js is a minimal solution. It being based on JavaScript give it three advantages: asm.js code already runs in all current JavaScript engines, albeit much slower than in an asm.js-optimized engine. Easy to standardize: asm.js semantics is derived from JavaScript and thus very easy to define, because it can be based on the ECMAScript specification. Easy to port: an asm.js implementation is based on a JavaScript engine, meaning comparatively little work is required to create one. As an aside, standardization is a requirement for portab...