Skip to content

Update Binaryen to latest #571

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

Merged
merged 2 commits into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"@protobufjs/utf8": "^1.1.0",
"binaryen": "73.0.0-nightly.20190327",
"binaryen": "77.0.0-nightly.20190407",
"glob": "^7.1.3",
"long": "^4.0.0",
"opencollective-postinstall": "^2.0.0",
Expand Down
20 changes: 4 additions & 16 deletions src/builtins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,6 @@ export namespace BuiltinSymbols {
export const i64_atomic_rmw_cmpxchg = "~lib/builtins/i64.atomic.rmw.cmpxchg";
export const i32_wait = "~lib/builtins/i32.wait";
export const i64_wait = "~lib/builtins/i64.wait";
export const i32_notify = "~lib/builtins/i32.notify";
export const i64_notify = "~lib/builtins/i64.notify";

export const v128_splat = "~lib/builtins/v128.splat";
export const v128_extract_lane = "~lib/builtins/v128.extract_lane";
Expand Down Expand Up @@ -1944,21 +1942,13 @@ export function compileCall(
compiler.currentType = Type.i32;
return module.createAtomicWait(arg0, arg1, arg2, type.toNativeType());
}
case BuiltinSymbols.atomic_notify: { // notify<T!>(ptr: usize, count: i32): i32;
case BuiltinSymbols.atomic_notify: { // notify(ptr: usize, count: i32): i32;
if (!compiler.options.hasFeature(Feature.THREADS)) break;
compiler.currentType = Type.i32;
if (
checkTypeRequired(typeArguments, reportNode, compiler) |
checkTypeAbsent(typeArguments, reportNode, prototype) |
checkArgsRequired(operands, 2, reportNode, compiler)
) return module.createUnreachable();
let type = typeArguments![0];
if (!type.is(TypeFlags.INTEGER) || type.size < 32) {
compiler.error(
DiagnosticCode.Operation_not_supported,
reportNode.typeArgumentsRange
);
return module.createUnreachable();
}
let arg0 = compiler.compileExpression(
operands[0],
compiler.options.usizeType,
Expand All @@ -1967,12 +1957,12 @@ export function compileCall(
);
let arg1 = compiler.compileExpression(
operands[1],
type,
Type.i32,
ConversionKind.IMPLICIT,
WrapMode.NONE
);
compiler.currentType = Type.i32;
return module.createAtomicWake(arg0, arg1);
return module.createAtomicNotify(arg0, arg1);
}

// === Control flow ===========================================================================
Expand Down Expand Up @@ -3792,8 +3782,6 @@ function tryDeferASM(

case BuiltinSymbols.i32_wait: return deferASM(BuiltinSymbols.atomic_wait, compiler, Type.i32, operands, Type.i32, reportNode);
case BuiltinSymbols.i64_wait: return deferASM(BuiltinSymbols.atomic_wait, compiler, Type.i64, operands, Type.i32, reportNode);
case BuiltinSymbols.i32_notify: return deferASM(BuiltinSymbols.atomic_notify, compiler, Type.i32, operands, Type.i32, reportNode);
case BuiltinSymbols.i64_notify: return deferASM(BuiltinSymbols.atomic_notify, compiler, Type.i64, operands, Type.i32, reportNode);
}
}
if (compiler.options.hasFeature(Feature.SIMD)) {
Expand Down
2 changes: 1 addition & 1 deletion src/decompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ export class Decompiler {
case ExpressionId.AtomicCmpxchg:
case ExpressionId.AtomicRMW:
case ExpressionId.AtomicWait:
case ExpressionId.AtomicWake:
case ExpressionId.AtomicNotify:
}
throw new Error("not implemented");
}
Expand Down
10 changes: 5 additions & 5 deletions src/glue/binaryen.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ declare function _BinaryenUnreachableId(): BinaryenExpressionId;
declare function _BinaryenAtomicCmpxchgId(): BinaryenExpressionId;
declare function _BinaryenAtomicRMWId(): BinaryenExpressionId;
declare function _BinaryenAtomicWaitId(): BinaryenExpressionId;
declare function _BinaryenAtomicWakeId(): BinaryenExpressionId;
declare function _BinaryenAtomicNotifyId(): BinaryenExpressionId;
declare function _BinaryenSIMDExtractId(): BinaryenExpressionId;
declare function _BinaryenSIMDReplaceId(): BinaryenExpressionId;
declare function _BinaryenSIMDShuffleId(): BinaryenExpressionId;
Expand Down Expand Up @@ -392,7 +392,7 @@ declare function _BinaryenAtomicStore(module: BinaryenModuleRef, bytes: Binaryen
declare function _BinaryenAtomicRMW(module: BinaryenModuleRef, op: BinaryenAtomicRMWOp, bytes: i32, offset: i32, ptr: BinaryenExpressionRef, value: BinaryenExpressionRef, type: BinaryenType): BinaryenExpressionRef;
declare function _BinaryenAtomicCmpxchg(module: BinaryenModuleRef, bytes: i32, offset: i32, ptr: BinaryenExpressionRef, expected: BinaryenExpressionRef, replacement: BinaryenExpressionRef, type: BinaryenType): BinaryenExpressionRef;
declare function _BinaryenAtomicWait(module: BinaryenModuleRef, ptr: BinaryenExpressionRef, expected: BinaryenExpressionRef, timeout: BinaryenExpressionRef, expectedType: BinaryenType): BinaryenExpressionRef;
declare function _BinaryenAtomicWake(module: BinaryenModuleRef, ptr: BinaryenExpressionRef, wakeCount: BinaryenExpressionRef): BinaryenExpressionRef;
declare function _BinaryenAtomicNotify(module: BinaryenModuleRef, ptr: BinaryenExpressionRef, notifyCount: BinaryenExpressionRef): BinaryenExpressionRef;

declare function _BinaryenSIMDExtract(module: BinaryenModuleRef, op: BinaryenSIMDOp, vec: BinaryenExpressionRef, idx: u8): BinaryenExpressionRef;
declare function _BinaryenSIMDReplace(module: BinaryenModuleRef, op: BinaryenSIMDOp, vec: BinaryenExpressionRef, idx: u8, value: BinaryenExpressionRef): BinaryenExpressionRef;
Expand Down Expand Up @@ -506,8 +506,8 @@ declare function _BinaryenAtomicWaitGetExpected(expr: BinaryenExpressionRef): Bi
declare function _BinaryenAtomicWaitGetTimeout(expr: BinaryenExpressionRef): BinaryenExpressionRef;
declare function _BinaryenAtomicWaitGetExpectedType(expr: BinaryenExpressionRef): BinaryenType;

declare function _BinaryenAtomicWakeGetPtr(expr: BinaryenExpressionRef): BinaryenExpressionRef;
declare function _BinaryenAtomicWakeGetWakeCount(expr: BinaryenExpressionRef): BinaryenExpressionRef;
declare function _BinaryenAtomicNotifyGetPtr(expr: BinaryenExpressionRef): BinaryenExpressionRef;
declare function _BinaryenAtomicNotifyGetNotifyCount(expr: BinaryenExpressionRef): BinaryenExpressionRef;

declare function _BinaryenSIMDExtractGetOp(expr: BinaryenExpressionRef): BinaryenSIMDOp;
declare function _BinaryenSIMDExtractGetVec(expr: BinaryenExpressionRef): BinaryenExpressionRef;
Expand Down Expand Up @@ -596,7 +596,7 @@ declare function _BinaryenRemoveGlobal(module: BinaryenModuleRef, name: usize):

declare function _BinaryenSetFunctionTable(module: BinaryenModuleRef, initial: BinaryenIndex, maximum: BinaryenIndex, funcs: usize, numFuncs: BinaryenIndex): void;

declare function _BinaryenSetMemory(module: BinaryenModuleRef, initial: BinaryenIndex, maximum: BinaryenIndex, exportName: usize, segments: usize, segmentOffsets: usize, segmentSizes: usize, numSegments: BinaryenIndex, shared: bool): void;
declare function _BinaryenSetMemory(module: BinaryenModuleRef, initial: BinaryenIndex, maximum: BinaryenIndex, exportName: usize, segments: usize, segmentPassive: usize, segmentOffsets: usize, segmentSizes: usize, numSegments: BinaryenIndex, shared: bool): void;

declare function _BinaryenSetStart(module: BinaryenModuleRef, start: BinaryenFunctionRef): void;

Expand Down
18 changes: 11 additions & 7 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export enum ExpressionId {
AtomicCmpxchg = _BinaryenAtomicCmpxchgId(),
AtomicRMW = _BinaryenAtomicRMWId(),
AtomicWait = _BinaryenAtomicWaitId(),
AtomicWake = _BinaryenAtomicWakeId(),
AtomicNotify = _BinaryenAtomicNotifyId(),
SIMDExtract = _BinaryenSIMDExtractId(),
SIMDReplace = _BinaryenSIMDReplaceId(),
SIMDShuffle = _BinaryenSIMDShuffleId(),
Expand Down Expand Up @@ -608,11 +608,11 @@ export class Module {
return _BinaryenAtomicWait(this.ref, ptr, expected, timeout, expectedType);
}

createAtomicWake(
createAtomicNotify(
ptr: ExpressionRef,
wakeCount: ExpressionRef
notifyCount: ExpressionRef
): ExpressionRef {
return _BinaryenAtomicWake(this.ref, ptr, wakeCount);
return _BinaryenAtomicNotify(this.ref, ptr, notifyCount);
}

// statements
Expand Down Expand Up @@ -976,23 +976,27 @@ export class Module {
var cStr = this.allocStringCached(exportName);
var k = segments.length;
var segs = new Array<usize>(k);
var psvs = new Array<i8>(k);
var offs = new Array<ExpressionRef>(k);
var sizs = new Array<Index>(k);
for (let i = 0; i < k; ++i) {
let buffer = segments[i].buffer;
let offset = segments[i].offset;
segs[i] = allocU8Array(buffer);
psvs[i] = 0; // no passive segments currently
offs[i] = target == Target.WASM64
? this.createI64(i64_low(offset), i64_high(offset))
: this.createI32(i64_low(offset));
sizs[i] = buffer.length;
}
var cArr1 = allocI32Array(segs);
var cArr2 = allocI32Array(offs);
var cArr3 = allocI32Array(sizs);
var cArr2 = allocU8Array(psvs);
var cArr3 = allocI32Array(offs);
var cArr4 = allocI32Array(sizs);
try {
_BinaryenSetMemory(this.ref, initial, maximum, cStr, cArr1, cArr2, cArr3, k, shared);
_BinaryenSetMemory(this.ref, initial, maximum, cStr, cArr1, cArr2, cArr3, cArr4, k, shared);
} finally {
memory.free(cArr4);
memory.free(cArr3);
memory.free(cArr2);
memory.free(cArr1);
Expand Down
4 changes: 1 addition & 3 deletions std/assembly/builtins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export namespace atomic {
@builtin export declare function xchg<T>(ptr: usize, value: T, immOffset?: usize): T;
@builtin export declare function cmpxchg<T>(ptr: usize, expected: T, replacement: T, immOffset?: usize): T;
@builtin export declare function wait<T>(ptr: usize, expected: T, timeout: i64): AtomicWaitResult;
@builtin export declare function notify<T>(ptr: usize, count: i32): i32;
@builtin export declare function notify(ptr: usize, count: i32): i32;
}

@lazy export const enum AtomicWaitResult {
Expand Down Expand Up @@ -105,7 +105,6 @@ export namespace i32 {
@builtin export declare function store16(offset: usize, value: i32, immOffset?: usize): void;
@builtin export declare function store(offset: usize, value: i32, immOffset?: usize): void;
@builtin export declare function wait(ptr: usize, expected: i32, timeout: i64): AtomicWaitResult;
@builtin export declare function notify(ptr: usize, count: i32): i32;

export namespace rmw8 {
@builtin export declare function add_u(offset: usize, value: i32, immOffset?: usize): i32;
Expand Down Expand Up @@ -169,7 +168,6 @@ export namespace i64 {
@builtin export declare function store32(offset: usize, value: i64, immOffset?: usize): void;
@builtin export declare function store(offset: usize, value: i64, immOffset?: usize): void;
@builtin export declare function wait(ptr: usize, expected: i64, timeout: i64): AtomicWaitResult;
@builtin export declare function notify(ptr: usize, count: i32): i32;

export namespace rmw8 {
@builtin export declare function add_u(offset: usize, value: i64, immOffset?: usize): i64;
Expand Down
10 changes: 3 additions & 7 deletions std/assembly/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ declare namespace atomic {
export function xchg<T>(ptr: usize, value: T, immOffset?: usize): T;
/** Atomically compares and exchanges an integer value in memory if the condition is met. */
export function cmpxchg<T>(ptr: usize, expected: T, replacement: T, immOffset?: usize): T;
/** Performs a wait operation on an integer value in memory suspending this agent if the condition is met. */
/** Performs a wait operation on an address in memory suspending this agent if the integer condition is met. */
export function wait<T>(ptr: usize, expected: T, timeout: i64): AtomicWaitResult;
/** Performs a notify operation on an integer value in memory waking up suspended agents. */
export function notify<T>(ptr: usize, count: i32): i32;
/** Performs a notify operation on an address in memory waking up suspended agents. */
export function notify(ptr: usize, count: i32): i32;
}

/** Describes the result of an atomic wait operation. */
Expand Down Expand Up @@ -254,8 +254,6 @@ declare namespace i32 {
export function store(offset: usize, value: i32, immOffset?: usize): void;
/** Performs a wait operation on a 32-bit integer value in memory suspending this agent if the condition is met. */
export function wait(ptr: usize, expected: i32, timeout: i64): AtomicWaitResult;
/** Performs a notify operation on a 32-bit integer value in memory waking up suspended agents. */
export function notify(ptr: usize, count: i32): i32;
/** Atomic 32-bit integer read-modify-write operations on 8-bit values. */
export namespace rmw8 {
/** Atomically adds an 8-bit unsigned integer value in memory. */
Expand Down Expand Up @@ -358,8 +356,6 @@ declare namespace i64 {
export function store(offset: usize, value: i64, immOffset?: usize): void;
/** Performs a wait operation on a 64-bit integer value in memory suspending this agent if the condition is met. */
export function wait(ptr: usize, expected: i64, timeout: i64): AtomicWaitResult;
/** Performs a notify operation on a 64-bit integer value in memory waking up suspended agents. */
export function notify(ptr: usize, count: i32): i32;
/** Atomic 64-bit integer read-modify-write operations on 8-bit values. */
export namespace rmw8 {
/** Atomically adds an 8-bit unsigned integer value in memory. */
Expand Down