Skip to content

Commit

Permalink
Rename atomic.notify and *.atomic.wait
Browse files Browse the repository at this point in the history
- atomic.notify -> memory.atomic.notify
- i32.atomic.wait -> memory.atomic.wait32
- i64.atomic.wait -> memory.atomic.wait64

See WebAssembly/threads#149.

This renames instruction name printing but not the internal data
structure names, such as `AtomicNotify`, which are not always the same
as printed instruction names anyway. This also does not modify C API.
But this fixes interface functions in binaryen.js because it seems
binaryen.js's interface functions all follow the corresponding
instruction names.
  • Loading branch information
aheejin committed Nov 13, 2020
1 parent 262bd62 commit ef103b8
Show file tree
Hide file tree
Showing 33 changed files with 153 additions and 144 deletions.
6 changes: 3 additions & 3 deletions scripts/gen-s-parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@
("i64.extend16_s", "makeUnary(s, UnaryOp::ExtendS16Int64)"),
("i64.extend32_s", "makeUnary(s, UnaryOp::ExtendS32Int64)"),
# atomic instructions
("atomic.notify", "makeAtomicNotify(s)"),
("i32.atomic.wait", "makeAtomicWait(s, Type::i32)"),
("i64.atomic.wait", "makeAtomicWait(s, Type::i64)"),
("memory.atomic.notify", "makeAtomicNotify(s)"),
("memory.atomic.wait32", "makeAtomicWait(s, Type::i32)"),
("memory.atomic.wait64", "makeAtomicWait(s, Type::i64)"),
("atomic.fence", "makeAtomicFence(s)"),
("i32.atomic.load8_u", "makeLoad(s, Type::i32, /*isAtomic=*/true)"),
("i32.atomic.load16_u", "makeLoad(s, Type::i32, /*isAtomic=*/true)"),
Expand Down
28 changes: 14 additions & 14 deletions src/binaryen-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -1404,47 +1404,47 @@ BinaryenAtomicCmpxchgSetReplacement(BinaryenExpressionRef expr,

// AtomicWait

// Gets the pointer expression of an `atomic.wait` expression.
// Gets the pointer expression of an `memory.atomic.wait` expression.
BINARYEN_API BinaryenExpressionRef
BinaryenAtomicWaitGetPtr(BinaryenExpressionRef expr);
// Sets the pointer expression of an `atomic.wait` expression.
// Sets the pointer expression of an `memory.atomic.wait` expression.
BINARYEN_API void BinaryenAtomicWaitSetPtr(BinaryenExpressionRef expr,
BinaryenExpressionRef ptrExpr);
// Gets the expression representing the expected value of an `atomic.wait`
// expression.
// Gets the expression representing the expected value of an
// `memory.atomic.wait` expression.
BINARYEN_API BinaryenExpressionRef
BinaryenAtomicWaitGetExpected(BinaryenExpressionRef expr);
// Sets the expression representing the expected value of an `atomic.wait`
// expression.
// Sets the expression representing the expected value of an
// `memory.atomic.wait` expression.
BINARYEN_API void
BinaryenAtomicWaitSetExpected(BinaryenExpressionRef expr,
BinaryenExpressionRef expectedExpr);
// Gets the timeout expression of an `atomic.wait` expression.
// Gets the timeout expression of an `memory.atomic.wait` expression.
BINARYEN_API BinaryenExpressionRef
BinaryenAtomicWaitGetTimeout(BinaryenExpressionRef expr);
// Sets the timeout expression of an `atomic.wait` expression.
// Sets the timeout expression of an `memory.atomic.wait` expression.
BINARYEN_API void
BinaryenAtomicWaitSetTimeout(BinaryenExpressionRef expr,
BinaryenExpressionRef timeoutExpr);
// Gets the expected type of an `atomic.wait` expression.
// Gets the expected type of an `memory.atomic.wait` expression.
BINARYEN_API BinaryenType
BinaryenAtomicWaitGetExpectedType(BinaryenExpressionRef expr);
// Sets the expected type of an `atomic.wait` expression.
// Sets the expected type of an `memory.atomic.wait` expression.
BINARYEN_API void BinaryenAtomicWaitSetExpectedType(BinaryenExpressionRef expr,
BinaryenType expectedType);

// AtomicNotify

// Gets the pointer expression of an `atomic.notify` expression.
// Gets the pointer expression of an `memory.atomic.notify` expression.
BINARYEN_API BinaryenExpressionRef
BinaryenAtomicNotifyGetPtr(BinaryenExpressionRef expr);
// Sets the pointer expression of an `atomic.notify` expression.
// Sets the pointer expression of an `memory.atomic.notify` expression.
BINARYEN_API void BinaryenAtomicNotifySetPtr(BinaryenExpressionRef expr,
BinaryenExpressionRef ptrExpr);
// Gets the notify count expression of an `atomic.notify` expression.
// Gets the notify count expression of an `memory.atomic.notify` expression.
BINARYEN_API BinaryenExpressionRef
BinaryenAtomicNotifyGetNotifyCount(BinaryenExpressionRef expr);
// Sets the notify count expression of an `atomic.notify` expression.
// Sets the notify count expression of an `memory.atomic.notify` expression.
BINARYEN_API void
BinaryenAtomicNotifySetNotifyCount(BinaryenExpressionRef expr,
BinaryenExpressionRef notifyCountExpr);
Expand Down
39 changes: 22 additions & 17 deletions src/gen-s-parser.inc
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,9 @@ switch (op[0]) {
default: goto parse_error;
}
}
case 't': {
switch (op[7]) {
case 'f':
if (strcmp(op, "atomic.fence") == 0) { return makeAtomicFence(s); }
goto parse_error;
case 'n':
if (strcmp(op, "atomic.notify") == 0) { return makeAtomicNotify(s); }
goto parse_error;
default: goto parse_error;
}
}
case 't':
if (strcmp(op, "atomic.fence") == 0) { return makeAtomicFence(s); }
goto parse_error;
default: goto parse_error;
}
}
Expand Down Expand Up @@ -1224,9 +1216,6 @@ switch (op[0]) {
default: goto parse_error;
}
}
case 'w':
if (strcmp(op, "i32.atomic.wait") == 0) { return makeAtomicWait(s, Type::i32); }
goto parse_error;
default: goto parse_error;
}
}
Expand Down Expand Up @@ -1976,9 +1965,6 @@ switch (op[0]) {
default: goto parse_error;
}
}
case 'w':
if (strcmp(op, "i64.atomic.wait") == 0) { return makeAtomicWait(s, Type::i64); }
goto parse_error;
default: goto parse_error;
}
}
Expand Down Expand Up @@ -2676,6 +2662,25 @@ switch (op[0]) {
}
case 'm': {
switch (op[7]) {
case 'a': {
switch (op[14]) {
case 'n':
if (strcmp(op, "memory.atomic.notify") == 0) { return makeAtomicNotify(s); }
goto parse_error;
case 'w': {
switch (op[18]) {
case '3':
if (strcmp(op, "memory.atomic.wait32") == 0) { return makeAtomicWait(s, Type::i32); }
goto parse_error;
case '6':
if (strcmp(op, "memory.atomic.wait64") == 0) { return makeAtomicWait(s, Type::i64); }
goto parse_error;
default: goto parse_error;
}
}
default: goto parse_error;
}
}
case 'c':
if (strcmp(op, "memory.copy") == 0) { return makeMemoryCopy(s); }
goto parse_error;
Expand Down
26 changes: 13 additions & 13 deletions src/js/binaryen.js-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,17 @@ function wrapModule(module, self = {}) {
},
'fill'(dest, value, size) {
return Module['_BinaryenMemoryFill'](module, dest, value, size);
},
'atomic': {
'notify'(ptr, notifyCount) {
return Module['_BinaryenAtomicNotify'](module, ptr, notifyCount);
},
'wait32'(ptr, expected, timeout) {
return Module['_BinaryenAtomicWait'](module, ptr, expected, timeout, Module['i32']);
},
'wait64'(ptr, expected, timeout) {
return Module['_BinaryenAtomicWait'](module, ptr, expected, timeout, Module['i64']);
}
}
}

Expand Down Expand Up @@ -889,9 +900,6 @@ function wrapModule(module, self = {}) {
return Module['_BinaryenAtomicCmpxchg'](module, 2, offset, ptr, expected, replacement, Module['i32'])
},
},
'wait'(ptr, expected, timeout) {
return Module['_BinaryenAtomicWait'](module, ptr, expected, timeout, Module['i32']);
}
},
'pop'() {
return Module['_BinaryenPop'](module, Module['i32']);
Expand Down Expand Up @@ -1193,9 +1201,6 @@ function wrapModule(module, self = {}) {
return Module['_BinaryenAtomicCmpxchg'](module, 4, offset, ptr, expected, replacement, Module['i64'])
},
},
'wait'(ptr, expected, timeout) {
return Module['_BinaryenAtomicWait'](module, ptr, expected, timeout, Module['i64']);
}
},
'pop'() {
return Module['_BinaryenPop'](module, Module['i64']);
Expand Down Expand Up @@ -2131,13 +2136,8 @@ function wrapModule(module, self = {}) {
return Module['_BinaryenUnreachable'](module);
};

self['atomic'] = {
'notify'(ptr, notifyCount) {
return Module['_BinaryenAtomicNotify'](module, ptr, notifyCount);
},
'fence'() {
return Module['_BinaryenAtomicFence'](module);
}
self['atomic.fence'] = function() {
return Module['_BinaryenAtomicFence'](module);
};

self['try'] = function(body, catchBody) {
Expand Down
6 changes: 4 additions & 2 deletions src/passes/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,15 @@ struct PrintExpressionContents
}
void visitAtomicWait(AtomicWait* curr) {
prepareColor(o);
o << forceConcrete(curr->expectedType) << ".atomic.wait";
Type type = forceConcrete(curr->expectedType);
assert(type == Type::i32 || type == Type::i64);
o << "memory.atomic.wait" << (type == Type::i32 ? "32" : "64");
if (curr->offset) {
o << " offset=" << curr->offset;
}
}
void visitAtomicNotify(AtomicNotify* curr) {
printMedium(o, "atomic.notify");
printMedium(o, "memory.atomic.notify");
if (curr->offset) {
o << " offset=" << curr->offset;
}
Expand Down
8 changes: 5 additions & 3 deletions src/wasm/wasm-s-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1463,11 +1463,12 @@ Expression* SExpressionWasmBuilder::makeAtomicWait(Element& s, Type type) {
} else if (type == Type::i64) {
expectedAlign = 8;
} else {
WASM_UNREACHABLE("Invalid prefix for atomic.wait");
WASM_UNREACHABLE("Invalid prefix for memory.atomic.wait");
}
size_t i = parseMemAttributes(s, ret->offset, align, expectedAlign);
if (align != expectedAlign) {
throw ParseException("Align of atomic.wait must match size", s.line, s.col);
throw ParseException(
"Align of memory.atomic.wait must match size", s.line, s.col);
}
ret->ptr = parseExpression(s[i]);
ret->expected = parseExpression(s[i + 1]);
Expand All @@ -1482,7 +1483,8 @@ Expression* SExpressionWasmBuilder::makeAtomicNotify(Element& s) {
Address align;
size_t i = parseMemAttributes(s, ret->offset, align, 4);
if (align != 4) {
throw ParseException("Align of atomic.notify must be 4", s.line, s.col);
throw ParseException(
"Align of memory.atomic.notify must be 4", s.line, s.col);
}
ret->ptr = parseExpression(s[i]);
ret->notifyCount = parseExpression(s[i + 1]);
Expand Down
12 changes: 6 additions & 6 deletions test/atomics.wast
Original file line number Diff line number Diff line change
Expand Up @@ -138,40 +138,40 @@
(local $0 i32)
(local $1 i64)
(drop
(i32.atomic.wait
(memory.atomic.wait32
(local.get $0)
(local.get $0)
(local.get $1)
)
)
(drop
(i32.atomic.wait offset=4 align=4
(memory.atomic.wait32 offset=4 align=4
(local.get $0)
(local.get $0)
(local.get $1)
)
)
(drop
(atomic.notify
(memory.atomic.notify
(local.get $0)
(local.get $0)
)
)
(drop
(atomic.notify offset=24 align=4
(memory.atomic.notify offset=24 align=4
(local.get $0)
(local.get $0)
)
)
(drop
(i64.atomic.wait
(memory.atomic.wait64
(local.get $0)
(local.get $1)
(local.get $1)
)
)
(drop
(i64.atomic.wait align=8 offset=16
(memory.atomic.wait64 align=8 offset=16
(local.get $0)
(local.get $1)
(local.get $1)
Expand Down
12 changes: 6 additions & 6 deletions test/atomics.wast.from-wast
Original file line number Diff line number Diff line change
Expand Up @@ -138,40 +138,40 @@
(local $0 i32)
(local $1 i64)
(drop
(i32.atomic.wait
(memory.atomic.wait32
(local.get $0)
(local.get $0)
(local.get $1)
)
)
(drop
(i32.atomic.wait offset=4
(memory.atomic.wait32 offset=4
(local.get $0)
(local.get $0)
(local.get $1)
)
)
(drop
(atomic.notify
(memory.atomic.notify
(local.get $0)
(local.get $0)
)
)
(drop
(atomic.notify offset=24
(memory.atomic.notify offset=24
(local.get $0)
(local.get $0)
)
)
(drop
(i64.atomic.wait
(memory.atomic.wait64
(local.get $0)
(local.get $1)
(local.get $1)
)
)
(drop
(i64.atomic.wait offset=16
(memory.atomic.wait64 offset=16
(local.get $0)
(local.get $1)
(local.get $1)
Expand Down
12 changes: 6 additions & 6 deletions test/atomics.wast.fromBinary
Original file line number Diff line number Diff line change
Expand Up @@ -138,40 +138,40 @@
(local $0 i32)
(local $1 i64)
(drop
(i32.atomic.wait
(memory.atomic.wait32
(local.get $0)
(local.get $0)
(local.get $1)
)
)
(drop
(i32.atomic.wait offset=4
(memory.atomic.wait32 offset=4
(local.get $0)
(local.get $0)
(local.get $1)
)
)
(drop
(atomic.notify
(memory.atomic.notify
(local.get $0)
(local.get $0)
)
)
(drop
(atomic.notify offset=24
(memory.atomic.notify offset=24
(local.get $0)
(local.get $0)
)
)
(drop
(i64.atomic.wait
(memory.atomic.wait64
(local.get $0)
(local.get $1)
(local.get $1)
)
)
(drop
(i64.atomic.wait offset=16
(memory.atomic.wait64 offset=16
(local.get $0)
(local.get $1)
(local.get $1)
Expand Down
Loading

0 comments on commit ef103b8

Please sign in to comment.