Skip to content

Instantly share code, notes, and snippets.

(module
(type $0 (func (result i32)))
(type $1 (func (result i64)))
(memory $0 0)
(export "f32.informally_known_as_plain_snan" (func $4))
(export "f32.all_ones_nan" (func $5))
(export "f32.nan" (func $0))
(export "f32.positive_nan" (func $1))
(export "f32.plain_nan" (func $3))
(export "f32.negative_nan" (func $2))
(module
(type $0 (func (result i32)))
(type $1 (func (result i64)))
(memory $0 0)
(export "f32.nan" (func $0))
(export "f32.positive_nan" (func $1))
(export "f32.negative_nan" (func $2))
(export "f32.plain_nan" (func $3))
(export "f32.informally_known_as_plain_snan" (func $4))
(export "f32.all_ones_nan" (func $5))
function truncate(x) {
  x = i64(x); // declare param as i64
  return i64_trunc(x) | 0; // truncate to low 32 bits
}
@kripken
kripken / hello_world.c
Last active March 19, 2025 06:14
Standalone WebAssembly Example
int doubler(int x) {
return 2 * x;
}

Box2D Code Size Measurements

step gzipped size (K)
asm.js 55.3
+ asm2wasm 50.0
+ wasm opts 45.2
- js opts 44.1
wasm-only 43.1

Corrections64 Speed Measurements

step time (seconds)
asm.js 28.46
+ asm2wasm 13.21
+ wasm opts 12.99
- js opts 12.88
wasm-only 6.88

Box2D Speed Measurements

step time (seconds)
asm.js 5.97
+ asm2wasm 5.66
+ wasm opts 5.28
- js opts 5.24
wasm-only 5.24
In file included from /usr/include/c++/5/bits/char_traits.h:39:0,
from /usr/include/c++/5/ios:40,
from /usr/include/c++/5/istream:38,
from /home/alon/Dev/binaryen/src/wasm-binary.h:25,
from /home/alon/Dev/binaryen/src/wasm/wasm-binary.cpp:17:
/usr/include/c++/5/bits/stl_algobase.h: In instantiation of ‘_BI2 std::__copy_move_backward_a(_BI1, _BI1, _BI2) [with bool _IsMove = false; _BI1 = wasm::Expression**; _BI2 = ArenaVector<wasm::Expression*>::Iterator]’:
/usr/include/c++/5/bits/stl_algobase.h:614:5: required from ‘_BI2 std::__copy_move_backward_a2(_BI1, _BI1, _BI2) [with bool _IsMove = false; _BI1 = __gnu_cxx::__normal_iterator<wasm::Expression**, std::vector<wasm::Expression*> >; _BI2 = ArenaVector<wasm::Expression*>::Iterator]’
/usr/include/c++/5/bits/stl_algobase.h:649:8: required from ‘_BI2 std::copy_backward(_BI1, _BI1, _BI2) [with _BI1 = __gnu_cxx::__normal_iterator<wasm::Expression**, std::vector<wasm::Expression*> >; _BI2 = Aren
#include <stdlib.h>
template <typename SubType>
struct ArenaVectorBase {
size_t allocatedElements = 0;
void allocate(size_t size) {
abort(); // must be implemented in children
}
};
function _arrayToHeap(typedArray){
var numBytes = typedArray.length * typedArray.BYTES_PER_ELEMENT;
var ptr = Module._malloc(numBytes);
var heapBytes = Module.HEAPU8.subarray(ptr, ptr + numBytes);
heapBytes.set(typedArray);
return heapBytes;
}