Skip to content

Instantly share code, notes, and snippets.

Alon Zakai kripken

Block or report user

Report or block kripken

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kripken
kripken / fac.byn.wat
Last active Jun 13, 2019
Factorial function in wasm instrumented as coroutine, printed 3 ways
View fac.byn.wat
;; printed in binaryen, to .wat s-expressions
(func $factorial-recursive (; 10 ;) (type $4) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
(if
(i32.eq
(global.get $global$1)
(i32.const 2)
)
View benchmark.cpp
#include <iostream>
#include <string>
#include <emscripten.h>
int main() {
size_t total = 0;
for (int i = 0; i < 1000000; i++) {
for (std::string str : { "hello", "world", "!", "test", "ing", "strings", "many", "of", "them" }) {
total += EM_ASM_INT({
return AsciiToString($0).length;
@kripken
kripken / README.markdown
Last active Mar 25, 2019
WebAssembly pthreads + memory growth + JS
View README.markdown

WebAssembly pthreads + memory growth + JS

Background

JavaScript can access a wasm memory, using

var buffer = wasmMemory.buffer;
View test.py
@needs_dlfcn
def test_dylink_global_ctor_and_stack(self):
# a global ctor in the main module must not call a side module before the side module is
# all set up - otherwise, the stack may be in the wrong place.
self.emcc_args += ['-g']
with env_modify({'EMCC_FORCE_STDLIBS': 'libc++'}):
self.dylink_test(header=r'''
#include<string>
const int gStudent = 10;
View trivial.txt
; start LHS (in $2)
%0:i32 = var
%1 = shl %0, 3:i32
%2 = add %1, 461288:i32
%3 = add %2, 8:i32
infer %3
View watfail.wat
(module
(func $0
(drop
(block $label$1 (result i32)
(loop $label$2
(unreachable)
)
)
)
(unreachable)
View aom-inspect
; function: $_od_ec_decode_cdf_q15
; start LHS (in $_od_ec_decode_cdf_q15)
%0:i32 = var
%1 = add %0, -1:i32
infer %1
; start LHS (in $_od_ec_decode_cdf_q15)
View bad.asm.js
Module["asm"] = (/** @suppress {uselessCode} */ function(global, env, buffer) {
'use asm';
var HEAP8 = new global.Int8Array(buffer);
var HEAP16 = new global.Int16Array(buffer);
var HEAP32 = new global.Int32Array(buffer);
var HEAPU8 = new global.Uint8Array(buffer);
var HEAPU16 = new global.Uint16Array(buffer);
var HEAPU32 = new global.Uint32Array(buffer);
View em_asm.cpp
#include <emscripten.h>
int main() {
EM_ASM({
console.log("hello, world!");
});
}
View emscripten_log.cpp
#include <emscripten.h>
int main() {
emscripten_log(EM_LOG_CONSOLE, "hello, world!");
}
You can’t perform that action at this time.