Skip to content

Commit 75e6120

Browse files
authored
Rename atomic.notify and *.atomic.wait (#3353)
- 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.
1 parent cc2b3e4 commit 75e6120

34 files changed

+155
-140
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ full changeset diff at the end of each section.
1515
Current Trunk
1616
-------------
1717

18+
- JS API functions for atomic notify/wait instructions are renamed.
19+
- `module.atomic.notify` -> `module.memory.atomic.notify`
20+
- `module.i32.atomic.wait` -> `module.memory.atomic.wait32`
21+
- `module.i64.atomic.wait` -> `module.memory.atomic.wait64`
1822
- Remove old/broken SpollPointers pass. This pass: Spills values that might be
1923
pointers to the C stack. This allows Boehm-style GC to see them properly.
2024
This can be revived if needed from git history (#3261).

scripts/gen-s-parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@
201201
("i64.extend16_s", "makeUnary(s, UnaryOp::ExtendS16Int64)"),
202202
("i64.extend32_s", "makeUnary(s, UnaryOp::ExtendS32Int64)"),
203203
# atomic instructions
204-
("atomic.notify", "makeAtomicNotify(s)"),
205-
("i32.atomic.wait", "makeAtomicWait(s, Type::i32)"),
206-
("i64.atomic.wait", "makeAtomicWait(s, Type::i64)"),
204+
("memory.atomic.notify", "makeAtomicNotify(s)"),
205+
("memory.atomic.wait32", "makeAtomicWait(s, Type::i32)"),
206+
("memory.atomic.wait64", "makeAtomicWait(s, Type::i64)"),
207207
("atomic.fence", "makeAtomicFence(s)"),
208208
("i32.atomic.load8_u", "makeLoad(s, Type::i32, /*isAtomic=*/true)"),
209209
("i32.atomic.load16_u", "makeLoad(s, Type::i32, /*isAtomic=*/true)"),

src/binaryen-c.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,47 +1404,47 @@ BinaryenAtomicCmpxchgSetReplacement(BinaryenExpressionRef expr,
14041404

14051405
// AtomicWait
14061406

1407-
// Gets the pointer expression of an `atomic.wait` expression.
1407+
// Gets the pointer expression of an `memory.atomic.wait` expression.
14081408
BINARYEN_API BinaryenExpressionRef
14091409
BinaryenAtomicWaitGetPtr(BinaryenExpressionRef expr);
1410-
// Sets the pointer expression of an `atomic.wait` expression.
1410+
// Sets the pointer expression of an `memory.atomic.wait` expression.
14111411
BINARYEN_API void BinaryenAtomicWaitSetPtr(BinaryenExpressionRef expr,
14121412
BinaryenExpressionRef ptrExpr);
1413-
// Gets the expression representing the expected value of an `atomic.wait`
1414-
// expression.
1413+
// Gets the expression representing the expected value of an
1414+
// `memory.atomic.wait` expression.
14151415
BINARYEN_API BinaryenExpressionRef
14161416
BinaryenAtomicWaitGetExpected(BinaryenExpressionRef expr);
1417-
// Sets the expression representing the expected value of an `atomic.wait`
1418-
// expression.
1417+
// Sets the expression representing the expected value of an
1418+
// `memory.atomic.wait` expression.
14191419
BINARYEN_API void
14201420
BinaryenAtomicWaitSetExpected(BinaryenExpressionRef expr,
14211421
BinaryenExpressionRef expectedExpr);
1422-
// Gets the timeout expression of an `atomic.wait` expression.
1422+
// Gets the timeout expression of an `memory.atomic.wait` expression.
14231423
BINARYEN_API BinaryenExpressionRef
14241424
BinaryenAtomicWaitGetTimeout(BinaryenExpressionRef expr);
1425-
// Sets the timeout expression of an `atomic.wait` expression.
1425+
// Sets the timeout expression of an `memory.atomic.wait` expression.
14261426
BINARYEN_API void
14271427
BinaryenAtomicWaitSetTimeout(BinaryenExpressionRef expr,
14281428
BinaryenExpressionRef timeoutExpr);
1429-
// Gets the expected type of an `atomic.wait` expression.
1429+
// Gets the expected type of an `memory.atomic.wait` expression.
14301430
BINARYEN_API BinaryenType
14311431
BinaryenAtomicWaitGetExpectedType(BinaryenExpressionRef expr);
1432-
// Sets the expected type of an `atomic.wait` expression.
1432+
// Sets the expected type of an `memory.atomic.wait` expression.
14331433
BINARYEN_API void BinaryenAtomicWaitSetExpectedType(BinaryenExpressionRef expr,
14341434
BinaryenType expectedType);
14351435

14361436
// AtomicNotify
14371437

1438-
// Gets the pointer expression of an `atomic.notify` expression.
1438+
// Gets the pointer expression of an `memory.atomic.notify` expression.
14391439
BINARYEN_API BinaryenExpressionRef
14401440
BinaryenAtomicNotifyGetPtr(BinaryenExpressionRef expr);
1441-
// Sets the pointer expression of an `atomic.notify` expression.
1441+
// Sets the pointer expression of an `memory.atomic.notify` expression.
14421442
BINARYEN_API void BinaryenAtomicNotifySetPtr(BinaryenExpressionRef expr,
14431443
BinaryenExpressionRef ptrExpr);
1444-
// Gets the notify count expression of an `atomic.notify` expression.
1444+
// Gets the notify count expression of an `memory.atomic.notify` expression.
14451445
BINARYEN_API BinaryenExpressionRef
14461446
BinaryenAtomicNotifyGetNotifyCount(BinaryenExpressionRef expr);
1447-
// Sets the notify count expression of an `atomic.notify` expression.
1447+
// Sets the notify count expression of an `memory.atomic.notify` expression.
14481448
BINARYEN_API void
14491449
BinaryenAtomicNotifySetNotifyCount(BinaryenExpressionRef expr,
14501450
BinaryenExpressionRef notifyCountExpr);

src/gen-s-parser.inc

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,9 @@ switch (op[0]) {
5050
default: goto parse_error;
5151
}
5252
}
53-
case 't': {
54-
switch (op[7]) {
55-
case 'f':
56-
if (strcmp(op, "atomic.fence") == 0) { return makeAtomicFence(s); }
57-
goto parse_error;
58-
case 'n':
59-
if (strcmp(op, "atomic.notify") == 0) { return makeAtomicNotify(s); }
60-
goto parse_error;
61-
default: goto parse_error;
62-
}
63-
}
53+
case 't':
54+
if (strcmp(op, "atomic.fence") == 0) { return makeAtomicFence(s); }
55+
goto parse_error;
6456
default: goto parse_error;
6557
}
6658
}
@@ -1224,9 +1216,6 @@ switch (op[0]) {
12241216
default: goto parse_error;
12251217
}
12261218
}
1227-
case 'w':
1228-
if (strcmp(op, "i32.atomic.wait") == 0) { return makeAtomicWait(s, Type::i32); }
1229-
goto parse_error;
12301219
default: goto parse_error;
12311220
}
12321221
}
@@ -1976,9 +1965,6 @@ switch (op[0]) {
19761965
default: goto parse_error;
19771966
}
19781967
}
1979-
case 'w':
1980-
if (strcmp(op, "i64.atomic.wait") == 0) { return makeAtomicWait(s, Type::i64); }
1981-
goto parse_error;
19821968
default: goto parse_error;
19831969
}
19841970
}
@@ -2676,6 +2662,25 @@ switch (op[0]) {
26762662
}
26772663
case 'm': {
26782664
switch (op[7]) {
2665+
case 'a': {
2666+
switch (op[14]) {
2667+
case 'n':
2668+
if (strcmp(op, "memory.atomic.notify") == 0) { return makeAtomicNotify(s); }
2669+
goto parse_error;
2670+
case 'w': {
2671+
switch (op[18]) {
2672+
case '3':
2673+
if (strcmp(op, "memory.atomic.wait32") == 0) { return makeAtomicWait(s, Type::i32); }
2674+
goto parse_error;
2675+
case '6':
2676+
if (strcmp(op, "memory.atomic.wait64") == 0) { return makeAtomicWait(s, Type::i64); }
2677+
goto parse_error;
2678+
default: goto parse_error;
2679+
}
2680+
}
2681+
default: goto parse_error;
2682+
}
2683+
}
26792684
case 'c':
26802685
if (strcmp(op, "memory.copy") == 0) { return makeMemoryCopy(s); }
26812686
goto parse_error;

src/js/binaryen.js-post.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,17 @@ function wrapModule(module, self = {}) {
629629
},
630630
'fill'(dest, value, size) {
631631
return Module['_BinaryenMemoryFill'](module, dest, value, size);
632+
},
633+
'atomic': {
634+
'notify'(ptr, notifyCount) {
635+
return Module['_BinaryenAtomicNotify'](module, ptr, notifyCount);
636+
},
637+
'wait32'(ptr, expected, timeout) {
638+
return Module['_BinaryenAtomicWait'](module, ptr, expected, timeout, Module['i32']);
639+
},
640+
'wait64'(ptr, expected, timeout) {
641+
return Module['_BinaryenAtomicWait'](module, ptr, expected, timeout, Module['i64']);
642+
}
632643
}
633644
}
634645

@@ -889,9 +900,6 @@ function wrapModule(module, self = {}) {
889900
return Module['_BinaryenAtomicCmpxchg'](module, 2, offset, ptr, expected, replacement, Module['i32'])
890901
},
891902
},
892-
'wait'(ptr, expected, timeout) {
893-
return Module['_BinaryenAtomicWait'](module, ptr, expected, timeout, Module['i32']);
894-
}
895903
},
896904
'pop'() {
897905
return Module['_BinaryenPop'](module, Module['i32']);
@@ -1193,9 +1201,6 @@ function wrapModule(module, self = {}) {
11931201
return Module['_BinaryenAtomicCmpxchg'](module, 4, offset, ptr, expected, replacement, Module['i64'])
11941202
},
11951203
},
1196-
'wait'(ptr, expected, timeout) {
1197-
return Module['_BinaryenAtomicWait'](module, ptr, expected, timeout, Module['i64']);
1198-
}
11991204
},
12001205
'pop'() {
12011206
return Module['_BinaryenPop'](module, Module['i64']);
@@ -2132,9 +2137,6 @@ function wrapModule(module, self = {}) {
21322137
};
21332138

21342139
self['atomic'] = {
2135-
'notify'(ptr, notifyCount) {
2136-
return Module['_BinaryenAtomicNotify'](module, ptr, notifyCount);
2137-
},
21382140
'fence'() {
21392141
return Module['_BinaryenAtomicFence'](module);
21402142
}

src/passes/Print.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,15 @@ struct PrintExpressionContents
317317
}
318318
void visitAtomicWait(AtomicWait* curr) {
319319
prepareColor(o);
320-
o << forceConcrete(curr->expectedType) << ".atomic.wait";
320+
Type type = forceConcrete(curr->expectedType);
321+
assert(type == Type::i32 || type == Type::i64);
322+
o << "memory.atomic.wait" << (type == Type::i32 ? "32" : "64");
321323
if (curr->offset) {
322324
o << " offset=" << curr->offset;
323325
}
324326
}
325327
void visitAtomicNotify(AtomicNotify* curr) {
326-
printMedium(o, "atomic.notify");
328+
printMedium(o, "memory.atomic.notify");
327329
if (curr->offset) {
328330
o << " offset=" << curr->offset;
329331
}

src/wasm/wasm-s-parser.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,11 +1463,12 @@ Expression* SExpressionWasmBuilder::makeAtomicWait(Element& s, Type type) {
14631463
} else if (type == Type::i64) {
14641464
expectedAlign = 8;
14651465
} else {
1466-
WASM_UNREACHABLE("Invalid prefix for atomic.wait");
1466+
WASM_UNREACHABLE("Invalid prefix for memory.atomic.wait");
14671467
}
14681468
size_t i = parseMemAttributes(s, ret->offset, align, expectedAlign);
14691469
if (align != expectedAlign) {
1470-
throw ParseException("Align of atomic.wait must match size", s.line, s.col);
1470+
throw ParseException(
1471+
"Align of memory.atomic.wait must match size", s.line, s.col);
14711472
}
14721473
ret->ptr = parseExpression(s[i]);
14731474
ret->expected = parseExpression(s[i + 1]);
@@ -1482,7 +1483,8 @@ Expression* SExpressionWasmBuilder::makeAtomicNotify(Element& s) {
14821483
Address align;
14831484
size_t i = parseMemAttributes(s, ret->offset, align, 4);
14841485
if (align != 4) {
1485-
throw ParseException("Align of atomic.notify must be 4", s.line, s.col);
1486+
throw ParseException(
1487+
"Align of memory.atomic.notify must be 4", s.line, s.col);
14861488
}
14871489
ret->ptr = parseExpression(s[i]);
14881490
ret->notifyCount = parseExpression(s[i + 1]);

test/atomics.wast

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,40 +138,40 @@
138138
(local $0 i32)
139139
(local $1 i64)
140140
(drop
141-
(i32.atomic.wait
141+
(memory.atomic.wait32
142142
(local.get $0)
143143
(local.get $0)
144144
(local.get $1)
145145
)
146146
)
147147
(drop
148-
(i32.atomic.wait offset=4 align=4
148+
(memory.atomic.wait32 offset=4 align=4
149149
(local.get $0)
150150
(local.get $0)
151151
(local.get $1)
152152
)
153153
)
154154
(drop
155-
(atomic.notify
155+
(memory.atomic.notify
156156
(local.get $0)
157157
(local.get $0)
158158
)
159159
)
160160
(drop
161-
(atomic.notify offset=24 align=4
161+
(memory.atomic.notify offset=24 align=4
162162
(local.get $0)
163163
(local.get $0)
164164
)
165165
)
166166
(drop
167-
(i64.atomic.wait
167+
(memory.atomic.wait64
168168
(local.get $0)
169169
(local.get $1)
170170
(local.get $1)
171171
)
172172
)
173173
(drop
174-
(i64.atomic.wait align=8 offset=16
174+
(memory.atomic.wait64 align=8 offset=16
175175
(local.get $0)
176176
(local.get $1)
177177
(local.get $1)

test/atomics.wast.from-wast

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,40 +138,40 @@
138138
(local $0 i32)
139139
(local $1 i64)
140140
(drop
141-
(i32.atomic.wait
141+
(memory.atomic.wait32
142142
(local.get $0)
143143
(local.get $0)
144144
(local.get $1)
145145
)
146146
)
147147
(drop
148-
(i32.atomic.wait offset=4
148+
(memory.atomic.wait32 offset=4
149149
(local.get $0)
150150
(local.get $0)
151151
(local.get $1)
152152
)
153153
)
154154
(drop
155-
(atomic.notify
155+
(memory.atomic.notify
156156
(local.get $0)
157157
(local.get $0)
158158
)
159159
)
160160
(drop
161-
(atomic.notify offset=24
161+
(memory.atomic.notify offset=24
162162
(local.get $0)
163163
(local.get $0)
164164
)
165165
)
166166
(drop
167-
(i64.atomic.wait
167+
(memory.atomic.wait64
168168
(local.get $0)
169169
(local.get $1)
170170
(local.get $1)
171171
)
172172
)
173173
(drop
174-
(i64.atomic.wait offset=16
174+
(memory.atomic.wait64 offset=16
175175
(local.get $0)
176176
(local.get $1)
177177
(local.get $1)

test/atomics.wast.fromBinary

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,40 +138,40 @@
138138
(local $0 i32)
139139
(local $1 i64)
140140
(drop
141-
(i32.atomic.wait
141+
(memory.atomic.wait32
142142
(local.get $0)
143143
(local.get $0)
144144
(local.get $1)
145145
)
146146
)
147147
(drop
148-
(i32.atomic.wait offset=4
148+
(memory.atomic.wait32 offset=4
149149
(local.get $0)
150150
(local.get $0)
151151
(local.get $1)
152152
)
153153
)
154154
(drop
155-
(atomic.notify
155+
(memory.atomic.notify
156156
(local.get $0)
157157
(local.get $0)
158158
)
159159
)
160160
(drop
161-
(atomic.notify offset=24
161+
(memory.atomic.notify offset=24
162162
(local.get $0)
163163
(local.get $0)
164164
)
165165
)
166166
(drop
167-
(i64.atomic.wait
167+
(memory.atomic.wait64
168168
(local.get $0)
169169
(local.get $1)
170170
(local.get $1)
171171
)
172172
)
173173
(drop
174-
(i64.atomic.wait offset=16
174+
(memory.atomic.wait64 offset=16
175175
(local.get $0)
176176
(local.get $1)
177177
(local.get $1)

0 commit comments

Comments
 (0)