Skip to content

[WIP] lib/threading #392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 54 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
c48a230
Merge pull request #1 from AssemblyScript/master
nidin Aug 9, 2018
3b4f4fb
Merge pull request #2 from AssemblyScript/master
nidin Nov 12, 2018
0d983b5
Path tracer and shared memory support added
nidin Jul 16, 2018
68adaeb
path tracer bucket indicator added
nidin Jul 16, 2018
0bd5fdc
Working on atomic load store
nidin Sep 10, 2018
ae41a85
Atomic operations added.
nidin Sep 21, 2018
8c0e6fa
If sharedMemory is greater than 0.
nidin Sep 21, 2018
5099533
smallpt CPP codes removed
nidin Sep 21, 2018
e6b1594
Removed tmp examples.
nidin Sep 21, 2018
931e221
CLI updated with shared memory options.
nidin Sep 22, 2018
179a2b2
Atomic operation tests added
nidin Sep 23, 2018
892949d
Atomic operations updated
nidin Sep 23, 2018
a09e397
Shared memory examples updated
nidin Sep 23, 2018
0ce39e4
Sign off
nidin Nov 12, 2018
9d7a8c9
Shared memory tests fixed.
nidin Nov 12, 2018
ea23fe0
Shared memory tests alignment issues fixed
nidin Nov 12, 2018
2deef79
Wait wake feature added
nidin Nov 17, 2018
ff102b5
Atomic wait wake example updated
nidin Nov 29, 2018
ba56ef1
Wait wake example clean up
nidin Nov 29, 2018
cbaa786
Wait wake example html updated
nidin Nov 29, 2018
e9cf712
Merge pull request #3 from 01alchemist/feature/worker-based-threads-w…
nidin Nov 29, 2018
8b98771
Rename atomic.wake -> atomic.notify to align with WebAssembbly Spec.
nidin Dec 11, 2018
41fa72b
Handle the case where an inlined body is empty
dcodeIO Nov 12, 2018
feebe09
Fix parsing of properties and field names using semi-reserved keywords
dcodeIO Nov 13, 2018
c0706e3
Add ArrayBuffer/DataView/Symbol#toString and improve Errors (#332)
MaxGraey Nov 18, 2018
c496345
Add Math.signbit (#333)
MaxGraey Nov 18, 2018
877c1d1
Fix unsafeCompare (#336)
MaxGraey Nov 19, 2018
fec60b3
Update dist files
dcodeIO Nov 19, 2018
8bf5fb9
Update Binaryen to latest
dcodeIO Nov 22, 2018
5897dbf
Cast to bool by comparing to zero (#343)
dcodeIO Nov 23, 2018
2846e81
Shortcut f32/f64/i64 conversions to bool
dcodeIO Nov 23, 2018
7a002d2
Fix unsupported element access on 'this', see #349
dcodeIO Nov 29, 2018
0c40d2f
Add 'instantiate<T>' builtin (like 'new' but from a type), see #349
dcodeIO Nov 29, 2018
1c969f1
Fix implementation of Array#splice (#347)
MaxGraey Nov 29, 2018
b7f9ba1
Document the use of two type parameters in loadUnsafe, TypedArray etc…
dcodeIO Nov 30, 2018
ee2a4e4
Add a test suite option to also generate binaries
dcodeIO Nov 30, 2018
99faca2
Fix an issue with 'super' not being present when inlining
dcodeIO Nov 30, 2018
40434bc
Update Binaryen to latest
dcodeIO Dec 1, 2018
846215e
Add a way to ensure that lazy globals are resolved, fixes #355
dcodeIO Dec 1, 2018
4db1ea0
Fix partial function prototypes not sharing their instances
dcodeIO Dec 1, 2018
1d625b8
Add missing definitions for Uint8ClampedArray
dcodeIO Dec 1, 2018
bc95999
Allow asynchronous file read/writes for cli.
willemneal Dec 5, 2018
c9cb854
Trying to use wake/wait on single thread.
willemneal Dec 5, 2018
f49d793
Adding threading library.
willemneal Dec 22, 2018
8adbd7c
Cleaning up print statements.
willemneal Dec 22, 2018
aaaf0c7
Added notes to README
willemneal Dec 22, 2018
907e812
Update README.md
willemneal Dec 22, 2018
170a8c1
Moved back to using a mailbox.
willemneal Dec 22, 2018
97f5a5f
Update README.md
willemneal Dec 22, 2018
3eadf63
Isolating bug. Uncomment log_str in Lock.aquire and it causes the va…
willemneal Dec 24, 2018
25b8d1d
Moved to typescript. Todo: make test with node that uses webworker.
willemneal Dec 25, 2018
629e03b
Remove reference to wasm file
Dec 27, 2018
afd7bb4
oops
Jan 29, 2019
9a925e2
small edits
Jan 29, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ docs/
node_modules/
out/
raw/
.history
.vscode
.idea
Empty file modified bin/asinit
100644 → 100755
Empty file.
2 changes: 2 additions & 0 deletions cli/asc.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,9 @@ exports.main = function main(argv, options, callback) {
assemblyscript.setNoTreeShaking(compilerOptions, args.noTreeShaking);
assemblyscript.setNoAssert(compilerOptions, args.noAssert);
assemblyscript.setImportMemory(compilerOptions, args.importMemory);
assemblyscript.setSharedMemory(compilerOptions, args.sharedMemory);
assemblyscript.setImportTable(compilerOptions, args.importTable);
assemblyscript.ignoreDataSegments(compilerOptions, args.ignoreDataSegments);
assemblyscript.setMemoryBase(compilerOptions, args.memoryBase >>> 0);
assemblyscript.setSourceMap(compilerOptions, args.sourceMap != null);
assemblyscript.setOptimizeLevelHints(compilerOptions, optimizeLevel, shrinkLevel);
Expand Down
10 changes: 10 additions & 0 deletions cli/asc.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@
"type": "b",
"default": false
},
"sharedMemory": {
"description": "Declare memory as shared.",
"type": "i",
"default": 0
},
"ignoreDataSegments": {
"description": "Ingore data segments to binary. Default false.",
"type": "b",
"default": false
},
"memoryBase": {
"description": "Sets the start offset of compiler-generated static memory.",
"type": "i",
Expand Down
2 changes: 1 addition & 1 deletion dist/asc.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/asc.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/assemblyscript.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/assemblyscript.js.map

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions examples/atomic-shared-memory/assembly/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const fs = require("fs");
const path = require("path");

const compiled = new WebAssembly.Module(
fs.readFileSync(path.resolve(__dirname, "..", "build", "atomic.builtins.wasm"))
);
const memory = new WebAssembly.Memory({
initial: 256,
maximum: 256,
shared: true
})
const imports = {
env: {
memory,
abort: (filename, line, column) => {
throw Error("abort called at " + line + ":" + colum);
}
}
};

Object.defineProperty(module, "exports", {
get: () => new WebAssembly.Instance(compiled, imports).exports
});
105 changes: 105 additions & 0 deletions examples/atomic-shared-memory/assembly/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
declare function log(v: i32): void;

export function test(): void {
var i: i32 = 0;
var u: u32 = 0;
var I: i64 = 0;
var U: u64 = 0;

// Atomic store
Atomic.store<i8>(120, <i32>8);
Atomic.store<i16>(121, <i32>16);
Atomic.store<i32>(123, <i32>32);

Atomic.store<i8>(120, <i64>8);
Atomic.store<i16>(121, <i64>16);
Atomic.store<i32>(123, <i64>32);
Atomic.store<i64>(127, <i64>64);

// Atomic load
i = Atomic.load<i8>(120);
i = Atomic.load<i16>(121);
i = Atomic.load<i32>(123);
u = Atomic.load<i8>(120);
u = Atomic.load<i16>(121);
u = Atomic.load<i32>(123);

I = Atomic.load<i8>(120);
I = Atomic.load<i16>(121);
I = Atomic.load<i32>(123);
I = Atomic.load<i64>(127);
U = Atomic.load<i8>(120);
U = Atomic.load<i16>(121);
U = Atomic.load<i32>(123);
U = Atomic.load<i64>(127);

// Atomic add
i = Atomic.add<i8>(120, 1);
i = Atomic.add<i16>(121, 1);
i = Atomic.add<i32>(123, 1);

I = Atomic.add<i8>(120, <i64>1);
I = Atomic.add<i16>(121, <i64>1);
I = Atomic.add<i32>(123, <i64>1);
I = Atomic.add<i64>(127, <i64>1);

// Atomic subtract
Atomic.sub<i8>(120, 1);
Atomic.sub<i16>(121, 1);
Atomic.sub<i32>(123, 1);

I = Atomic.sub<i8>(120, <i64>1);
I = Atomic.sub<i16>(121, <i64>1);
I = Atomic.sub<i32>(123, <i64>1);
I = Atomic.sub<i64>(127, <i64>1);

// Atomic AND
Atomic.and<i8>(120, 1);
Atomic.and<i16>(121, 1);
Atomic.and<i32>(123, 1);

I = Atomic.and<i8>(120, <i64>1);
I = Atomic.and<i16>(121, <i64>1);
I = Atomic.and<i32>(123, <i64>1);
I = Atomic.and<i64>(127, <i64>1);

// Atomic OR
Atomic.or<i8>(120, 1);
Atomic.or<i16>(121, 1);
Atomic.or<i32>(123, 1);

I = Atomic.or<i8>(120, <i64>1);
I = Atomic.or<i16>(121, <i64>1);
I = Atomic.or<i32>(123, <i64>1);
I = Atomic.or<i64>(127, <i64>1);

// Atomic XOR
Atomic.xor<i8>(120, 1);
Atomic.xor<i16>(121, 1);
Atomic.xor<i32>(123, 1);

I = Atomic.xor<i8>(120, <i64>1);
I = Atomic.xor<i16>(121, <i64>1);
I = Atomic.xor<i32>(123, <i64>1);
I = Atomic.xor<i64>(127, <i64>1);

// Atomic xchg
Atomic.xchg<i8>(120, 1);
Atomic.xchg<i16>(121, 1);
Atomic.xchg<i32>(123, 1);

I = Atomic.xchg<i8>(120, <i64>1);
I = Atomic.xchg<i16>(121, <i64>1);
I = Atomic.xchg<i32>(123, <i64>1);
I = Atomic.xchg<i64>(127, <i64>1);

// Atomic cmpxchg
Atomic.cmpxchg<i8>(120, 1, 2);
Atomic.cmpxchg<i16>(121, 1, 2);
Atomic.cmpxchg<i32>(123, 1, 2);

I = Atomic.cmpxchg<i8>(120, <i64>1, <i64>2);
I = Atomic.cmpxchg<i16>(121, <i64>1, <i64>2);
I = Atomic.cmpxchg<i32>(123, <i64>1, <i64>2);
I = Atomic.cmpxchg<i64>(127, <i64>1, <i64>2);
}
6 changes: 6 additions & 0 deletions examples/atomic-shared-memory/assembly/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../../std/assembly.json",
"include": [
"./**/*.ts"
]
}
77 changes: 77 additions & 0 deletions examples/atomic-shared-memory/build/index.asm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
function asmFunc(global, env, buffer) {
"almost 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);
var HEAPF32 = new global.Float32Array(buffer);
var HEAPF64 = new global.Float64Array(buffer);
var Math_imul = global.Math.imul;
var Math_fround = global.Math.fround;
var Math_abs = global.Math.abs;
var Math_clz32 = global.Math.clz32;
var Math_min = global.Math.min;
var Math_max = global.Math.max;
var Math_floor = global.Math.floor;
var Math_ceil = global.Math.ceil;
var Math_sqrt = global.Math.sqrt;
var abort = env.abort;
var nan = global.NaN;
var infinity = global.Infinity;
var $0 = env.memory;
var $lib_allocator_arena_startOffset = 0;
var $lib_allocator_arena_offset = 0;
var assembly_index_str = 8;
var HEAP_BASE = 16;
var i64toi32_i32$HIGH_BITS = 0;
function assembly_index_read() {
return assembly_index_str | 0;
}

function start() {
$lib_allocator_arena_startOffset = (HEAP_BASE + 7 | 0) & 4294967288 | 0;
$lib_allocator_arena_offset = $lib_allocator_arena_startOffset;
}

function __wasm_grow_memory(pagesToAdd) {
pagesToAdd = pagesToAdd | 0;
var oldPages = __wasm_current_memory() | 0;
var newPages = oldPages + pagesToAdd | 0;
if ((oldPages < newPages) && (newPages < 65535)) {
var newBuffer = new ArrayBuffer(Math_imul(newPages, 65536));
var newHEAP8 = new global.Int8Array(newBuffer);
newHEAP8.set(HEAP8);
HEAP8 = newHEAP8;
HEAP16 = new global.Int16Array(newBuffer);
HEAP32 = new global.Int32Array(newBuffer);
HEAPU8 = new global.Uint8Array(newBuffer);
HEAPU16 = new global.Uint16Array(newBuffer);
HEAPU32 = new global.Uint32Array(newBuffer);
HEAPF32 = new global.Float32Array(newBuffer);
HEAPF64 = new global.Float64Array(newBuffer);
buffer = newBuffer;
}
return oldPages;
}

function __wasm_current_memory() {
return buffer.byteLength / 65536 | 0;
}

return {
read: assembly_index_read,
memory: Object.create(Object.prototype, {
grow: {
value: __wasm_grow_memory
},
buffer: {
get: function () {
return buffer;
}

}
})
};
}
8 changes: 8 additions & 0 deletions examples/atomic-shared-memory/build/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("allocator/arena");
let str = "A";
function read() {
return str;
}
exports.read = read;
Loading