[acqrel] Added atomic acquire load and release store instructions [v8/v8 : main]

2 views
Skip to first unread message

Rezvan Mahdavi Hezaveh (Gerrit)

unread,
Jan 7, 2026, 7:25:19 PM (5 days ago) Jan 7
to Deepti Gandluri, Jakob Kummerow, Steven Fontanella, AyeAye, v8-risc...@chromium.org, v8-ppc...@googlegroups.com, v8-mip...@googlegroups.com, dmercadi...@chromium.org, v8-re...@googlegroups.com, was...@google.com
Attention needed from Deepti Gandluri and Jakob Kummerow

Rezvan Mahdavi Hezaveh added 11 comments

Patchset-level comments
File-level comment, Patchset 15 (Latest):
Rezvan Mahdavi Hezaveh . resolved

Jakob and Deepti, thanks for your first round of comments! I would appreciate another round of early feedback. The architecture related `inl.h` files may need more work. You can ignore them for now or take them with a grain of salt.

File src/wasm/baseline/liftoff-compiler.cc
Line 5979, Patchset 8: __ AtomicStoreRelease(addr, index, offset, value, type, nullptr,
Jakob Kummerow . resolved
This is the only difference from the existing `AtomicStoreMem`, right? That's not worth duplicating the whole function for. So I'd suggest to:
- drop `AtomicStoreReleaseMem`
- add the `order` parameter to `AtomicStoreMem`
- replace line 5940 with:
```
if (order == …::kAcqRel) {
__ AtomicStoreRelease(…);
} else {
__ AtomicStore(…);
}
```
Rezvan Mahdavi Hezaveh

Yeah that makes sense, done.

Line 6023, Patchset 8: // I'll keep this one for now but we may remove it altogether
Jakob Kummerow . resolved

+1, similar to Store above.

Rezvan Mahdavi Hezaveh

Done

Line 6323, Patchset 8:#define ATOMIC_STORE_RELEASE_LIST(V) \
Jakob Kummerow . resolved

If you do the method merging I suggested above, then you can just add the new instructions to the old macro here (`ATOMIC_STORE_LIST`).

Rezvan Mahdavi Hezaveh

I removed the new instructions.

File src/wasm/baseline/x64/liftoff-assembler-x64-inl.h
Line 758, Patchset 8: // x86 stores have release semantics. A simple mov is atomic for aligned
// accesses.
Jakob Kummerow . resolved

We don't have any alignment guarantees here though. (There's an "alignment hint" in the `MemoryAccessImmediate`, but it's just that: a hint, not a guarantee, so entirely useless for codegen purposes.)

Rezvan Mahdavi Hezaveh

Ah, I see. That is a very good point. I think the alignment is checked in the caller of this function inside `liftoff-compiler.cc`. I removed the comment for more clarity.

File src/wasm/function-body-decoder-impl.h
Line 7068, Patchset 8: if (this->enabled_.has_acquire_release()) { \
MemoryOrderImmediate memory_order(this, this->pc_ + opcode_length, \
Jakob Kummerow . resolved

This isn't going to work: it adds a new immediate to the existing instructions when the V8 feature flag is enabled.

Instead, have a look at `MemoryAccessImmediate::ConstructSlow`, and add a new `if (alignment & 0x20)` block to it, similar to the existing handling of `alignment & 0x40`.

We'll then still want a feature check: if that `0x20` bit is set but the feature flag is off, fail validation.

Rezvan Mahdavi Hezaveh

Got it, thanks for the hint. Done.

Line 7062, Patchset 8: AtomicMemoryOrder::kSeqCst; // set to the default value
Jakob Kummerow . resolved

nit: All comments should be proper sentences, with capitalization at the beginning and punctuation at the end. See https://google.github.io/styleguide/cppguide.html#Comments.

Rezvan Mahdavi Hezaveh

Done

Line 8, Patchset 8:#include "src/flags/flags.h"
Jakob Kummerow . resolved

This should be alphabetically sorted with the other includes, i.e. between lines 24/25. (Or just drop it and rely on transitive includes... that's arguably not super clean but it's the status quo.)

Pro tip: add `-header-insertion=never` to your clangd arguments and deal with headers manually, to avoid such misplaced auto insertions. See https://v8.dev/docs/ide-setup.

Rezvan Mahdavi Hezaveh

Great tip, thanks!

File src/wasm/wasm-opcodes.h
Line 735, Patchset 8: V(I32AtomicLoadAcquire, 0xfe50, i_i, "i32.atomic.load_acq", i_l) \
V(I64AtomicLoadAcquire, 0xfe51, l_i, "i64.atomic.load_acq", l_l) \
V(I32AtomicStoreRelease, 0xfe52, v_ii, "i32.atomic.store_rel", v_li) \
V(I64AtomicStoreRelease, 0xfe53, v_il, "i64.atomic.store_rel", v_ll)
Jakob Kummerow . resolved

This would technically work (at least for a prototype), but it's not what https://github.com/WebAssembly/shared-everything-threads/blob/main/proposals/shared-everything-threads/Overview.md#memory-orderings specifies. We should probably implement the proposal, unless there's a reason not to?

Rezvan Mahdavi Hezaveh

When I start the implementation, I added new instructions to make sure I am not breaking the existing ones while prototyping and understanding the code. My plan was to remove them and modify the code later on. Now that I spent more time on the code, I think it's easier if I go with the proposal approach instead of having new opcodes. Removed them.

File test/mjsunit/wasm/shared-everything/test-acq-rel-instructions.js
Line 15, Patchset 8: kExprLocalGet,
0,
Jakob Kummerow . resolved

This looks auto-formatted, which is technically acceptable, but for (slightly) increased readability, it makes more sense to keep each instruction on one line, e.g.:

```
kExprLocalGet, 0,
kAtomicPrefix, kExprI32AtomicLoad, 0x22, kAtomicAcqRel, 0,
```

(Feel free to define a named constant or helper function for `0x22`; or perhaps we even want a builder for memory accesses that takes an options bag such as `MemoryAccess({alignment: ..., offset: ..., memIndex: ..., atomicOrder: ...})`, or perhaps any of these ideas should be a separate CL.)

Rezvan Mahdavi Hezaveh

Yes, is file is auto-formatted. I can see why this format decrease the readability, I fixed the format.

About the second part of your comment, let's do it in a separate CL.

Line 30, Patchset 8: var builder = new WasmModuleBuilder();
Jakob Kummerow . resolved

To improve efficiency of the test, don't create new module builders unless necessary: one Wasm function per atomic instruction is fine, but they can all be added to the same module.

Usually, the one case where we do need multiple module builders is when we want to test validation failures: while a module can of course contain many invalid things, usually all tests will first run into the same problem, and report that as the failure reason.

(I can see that some of the existing tests use one module builder per tested instruction as well, so you've probably copied this pattern from there. Cleaning up the precedent would be nice but is optional.)

Rezvan Mahdavi Hezaveh

Got it. Yeah, there are some other tests with similar structure. I updated this test to have just one module.

Open in Gerrit

Related details

Attention is currently required from:
  • Deepti Gandluri
  • Jakob Kummerow
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: v8/v8
Gerrit-Branch: main
Gerrit-Change-Id: Ibe5b293ec5dfe64f1fab7ceec745f84c7765dad9
Gerrit-Change-Number: 7164383
Gerrit-PatchSet: 15
Gerrit-Owner: Rezvan Mahdavi Hezaveh <rez...@chromium.org>
Gerrit-Reviewer: Deepti Gandluri <gde...@chromium.org>
Gerrit-Reviewer: Jakob Kummerow <jkum...@chromium.org>
Gerrit-CC: Steven Fontanella <steve...@chromium.org>
Gerrit-Attention: Jakob Kummerow <jkum...@chromium.org>
Gerrit-Attention: Deepti Gandluri <gde...@chromium.org>
Gerrit-Comment-Date: Thu, 08 Jan 2026 00:25:16 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Jakob Kummerow <jkum...@chromium.org>
unsatisfied_requirement
open
diffy

Jakob Kummerow (Gerrit)

unread,
Jan 8, 2026, 6:50:39 AM (5 days ago) Jan 8
to Rezvan Mahdavi Hezaveh, Deepti Gandluri, Jakob Kummerow, Steven Fontanella, AyeAye, v8-risc...@chromium.org, v8-ppc...@googlegroups.com, v8-mip...@googlegroups.com, dmercadi...@chromium.org, v8-re...@googlegroups.com, was...@google.com
Attention needed from Deepti Gandluri and Rezvan Mahdavi Hezaveh

Jakob Kummerow added 8 comments

Patchset-level comments
Jakob Kummerow . resolved

Looking good, some minor comments. Didn't look at the `-inl.h` files.

File src/wasm/function-body-decoder-impl.h
Line 2402, Patchset 15 (Latest): bool kAcquireReleaseAtomicEnables = decoder->enabled_.has_acquire_release();
Jakob Kummerow . unresolved

In this function, we don't actually care about validation, see e.g. `WasmEnabledFeatures::All()` in line 2416. So this can be:
```
constexpr bool kAcqRelEnabled = true;
```
(Or consider following the `WasmEnabledFeatures::All()` precedent instead of passing that bool.)

Line 2229, Patchset 15 (Latest): "--experimental--acquire-release flag");
Jakob Kummerow . unresolved

`-wasm-`

Line 2225, Patchset 15 (Latest): if (!VALIDATE(this->enabled_.has_acquire_release() ||
imm.memory_order != AtomicMemoryOrder::kAcqRel)) {
Jakob Kummerow . unresolved

This can't ever happen, right? The condition on line 1123 makes it impossible.

I think the block starting in line 1091 provides all required validation. If you want, you can improve the error message there, something like:

```
if (alignment & 0x20) {
DecodeError("acqrel requires --experimental-wasm-acquire-release");
} else {
// existing DecodeError
}
```

Spec question: what should happen when a non-atomic load or store instruction's alignment immediate has the acqrel bit set?

File test/mjsunit/wasm/shared-everything/test-acq-rel-instructions.js
Line 1, Patchset 15 (Latest):// Copyright 2025 the V8 project authors. All rights reserved.
Jakob Kummerow . unresolved

nit: 2026 now 😊

Line 9, Patchset 15 (Latest):(function TestAllInOneModule() {
print(arguments.callee.name);
Jakob Kummerow . unresolved

nit: just drop this (and the corresponding `}` at the end).

Line 20, Patchset 15 (Latest): .exportAs('i32_atomic_load_acquire');
Jakob Kummerow . unresolved

nit: use `exportFunc()`, then you don't need to repeat the function name (and then you can save lines by putting it at the end of the `.addFunction(...)` line, before `.addBody(...)`).

Line 137, Patchset 15 (Latest): assertEquals(0, exports.i32_atomic_load_acquire(0));
Jakob Kummerow . unresolved

If you did one `exports.i64_atomic_store_release(0, 0x1234567890abcdefn)` before, you'd have more interesting expectation values for the loads.

(Tests should, within reason, rule out as many bugs as they can: suppose some platform's assembler implementation accidentally read from the wrong address, or always returned zero; as currently written this test would still pass.)

Open in Gerrit

Related details

Attention is currently required from:
  • Deepti Gandluri
  • Rezvan Mahdavi Hezaveh
Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: v8/v8
    Gerrit-Branch: main
    Gerrit-Change-Id: Ibe5b293ec5dfe64f1fab7ceec745f84c7765dad9
    Gerrit-Change-Number: 7164383
    Gerrit-PatchSet: 15
    Gerrit-Owner: Rezvan Mahdavi Hezaveh <rez...@chromium.org>
    Gerrit-Reviewer: Deepti Gandluri <gde...@chromium.org>
    Gerrit-Reviewer: Jakob Kummerow <jkum...@chromium.org>
    Gerrit-CC: Steven Fontanella <steve...@chromium.org>
    Gerrit-Attention: Rezvan Mahdavi Hezaveh <rez...@chromium.org>
    Gerrit-Attention: Deepti Gandluri <gde...@chromium.org>
    Gerrit-Comment-Date: Thu, 08 Jan 2026 11:50:34 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Rezvan Mahdavi Hezaveh (Gerrit)

    unread,
    7:26 PM (3 hours ago) 7:26 PM
    to Deepti Gandluri, Jakob Kummerow, Steven Fontanella, AyeAye, v8-risc...@chromium.org, v8-ppc...@googlegroups.com, v8-mip...@googlegroups.com, dmercadi...@chromium.org, v8-re...@googlegroups.com, was...@google.com
    Attention needed from Deepti Gandluri, Jakob Kummerow and Rezvan Mahdavi Hezaveh

    Message from Rezvan Mahdavi Hezaveh

    Set Ready For Review

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Deepti Gandluri
    • Jakob Kummerow
    • Rezvan Mahdavi Hezaveh
    Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: v8/v8
    Gerrit-Branch: main
    Gerrit-Change-Id: Ibe5b293ec5dfe64f1fab7ceec745f84c7765dad9
    Gerrit-Change-Number: 7164383
    Gerrit-PatchSet: 17
    Gerrit-Owner: Rezvan Mahdavi Hezaveh <rez...@chromium.org>
    Gerrit-Reviewer: Deepti Gandluri <gde...@chromium.org>
    Gerrit-Reviewer: Jakob Kummerow <jkum...@chromium.org>
    Gerrit-CC: Steven Fontanella <steve...@chromium.org>
    Gerrit-Attention: Rezvan Mahdavi Hezaveh <rez...@chromium.org>
    Gerrit-Attention: Deepti Gandluri <gde...@chromium.org>
    Gerrit-Attention: Jakob Kummerow <jkum...@chromium.org>
    Gerrit-Comment-Date: Tue, 13 Jan 2026 00:26:40 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Rezvan Mahdavi Hezaveh (Gerrit)

    unread,
    7:27 PM (3 hours ago) 7:27 PM
    to Deepti Gandluri, Jakob Kummerow, Steven Fontanella, AyeAye, v8-risc...@chromium.org, v8-ppc...@googlegroups.com, v8-mip...@googlegroups.com, dmercadi...@chromium.org, v8-re...@googlegroups.com, was...@google.com
    Attention needed from Deepti Gandluri and Jakob Kummerow

    Rezvan Mahdavi Hezaveh added 9 comments

    Rezvan Mahdavi Hezaveh . resolved

    This CL is ready for review. Thanks!

    File src/wasm/baseline/x64/liftoff-assembler-x64-inl.h
    Line 758, Patchset 8: // x86 stores have release semantics. A simple mov is atomic for aligned
    // accesses.
    Jakob Kummerow . unresolved

    We don't have any alignment guarantees here though. (There's an "alignment hint" in the `MemoryAccessImmediate`, but it's just that: a hint, not a guarantee, so entirely useless for codegen purposes.)

    Rezvan Mahdavi Hezaveh

    Ah, I see. That is a very good point. I think the alignment is checked in the caller of this function inside `liftoff-compiler.cc`. I removed the comment for more clarity.

    Rezvan Mahdavi Hezaveh

    It meant to be a question here: I think the alignment is checked in the caller of this function inside liftoff-compiler.cc. Right?

    File src/wasm/function-body-decoder-impl.h
    Line 2402, Patchset 15: bool kAcquireReleaseAtomicEnables = decoder->enabled_.has_acquire_release();
    Jakob Kummerow . resolved

    In this function, we don't actually care about validation, see e.g. `WasmEnabledFeatures::All()` in line 2416. So this can be:
    ```
    constexpr bool kAcqRelEnabled = true;
    ```
    (Or consider following the `WasmEnabledFeatures::All()` precedent instead of passing that bool.)

    Rezvan Mahdavi Hezaveh

    Got it. I decided to go with the `true` value.

    Line 2229, Patchset 15: "--experimental--acquire-release flag");
    Jakob Kummerow . resolved

    `-wasm-`

    Rezvan Mahdavi Hezaveh

    Done

    Line 2225, Patchset 15: if (!VALIDATE(this->enabled_.has_acquire_release() ||
    imm.memory_order != AtomicMemoryOrder::kAcqRel)) {
    Jakob Kummerow . resolved

    This can't ever happen, right? The condition on line 1123 makes it impossible.

    I think the block starting in line 1091 provides all required validation. If you want, you can improve the error message there, something like:

    ```
    if (alignment & 0x20) {
    DecodeError("acqrel requires --experimental-wasm-acquire-release");
    } else {
    // existing DecodeError
    }
    ```

    Spec question: what should happen when a non-atomic load or store instruction's alignment immediate has the acqrel bit set?

    Rezvan Mahdavi Hezaveh

    Done.

    About your question: My answer is that it should be a validation error. I added the check to the code and opened a PR to add this to the spec overview (https://github.com/WebAssembly/shared-everything-threads/pull/107). Thanks for the great question!

    File test/mjsunit/wasm/shared-everything/test-acq-rel-instructions.js
    Line 1, Patchset 15:// Copyright 2025 the V8 project authors. All rights reserved.
    Jakob Kummerow . resolved

    nit: 2026 now 😊

    Rezvan Mahdavi Hezaveh

    Oh yeah 😊

    Line 9, Patchset 15:(function TestAllInOneModule() {
    print(arguments.callee.name);
    Jakob Kummerow . unresolved

    nit: just drop this (and the corresponding `}` at the end).

    Rezvan Mahdavi Hezaveh

    mmm I am not sure if I understand this comment. I can't see extra/unnecessary `(` or `{`.

    Line 20, Patchset 15: .exportAs('i32_atomic_load_acquire');
    Jakob Kummerow . resolved

    nit: use `exportFunc()`, then you don't need to repeat the function name (and then you can save lines by putting it at the end of the `.addFunction(...)` line, before `.addBody(...)`).

    Rezvan Mahdavi Hezaveh

    Done

    Line 137, Patchset 15: assertEquals(0, exports.i32_atomic_load_acquire(0));
    Jakob Kummerow . unresolved

    If you did one `exports.i64_atomic_store_release(0, 0x1234567890abcdefn)` before, you'd have more interesting expectation values for the loads.

    (Tests should, within reason, rule out as many bugs as they can: suppose some platform's assembler implementation accidentally read from the wrong address, or always returned zero; as currently written this test would still pass.)

    Rezvan Mahdavi Hezaveh

    That's a good point, sure!
    I think we need some tests with shared memory as well to see of the instructions actually works and acquire and release semantics are correct. Can you provide some pointers for that? I know that one example is `test/mjsunit/wasm/shared-everything/atomic-instructions.js` but I still appreciate some pointers/hints. I may add these correctness tests in follow-up CLs.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Deepti Gandluri
    • Jakob Kummerow
    Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: v8/v8
    Gerrit-Branch: main
    Gerrit-Change-Id: Ibe5b293ec5dfe64f1fab7ceec745f84c7765dad9
    Gerrit-Change-Number: 7164383
    Gerrit-PatchSet: 17
    Gerrit-Owner: Rezvan Mahdavi Hezaveh <rez...@chromium.org>
    Gerrit-Reviewer: Deepti Gandluri <gde...@chromium.org>
    Gerrit-Reviewer: Jakob Kummerow <jkum...@chromium.org>
    Gerrit-CC: Steven Fontanella <steve...@chromium.org>
    Gerrit-Attention: Deepti Gandluri <gde...@chromium.org>
    Gerrit-Attention: Jakob Kummerow <jkum...@chromium.org>
    Gerrit-Comment-Date: Tue, 13 Jan 2026 00:27:04 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Rezvan Mahdavi Hezaveh <rez...@chromium.org>
    Comment-In-Reply-To: Jakob Kummerow <jkum...@chromium.org>
    unsatisfied_requirement
    open
    diffy

    Rezvan Mahdavi Hezaveh (Gerrit)

    unread,
    7:50 PM (2 hours ago) 7:50 PM
    to V8 LUCI CQ, Deepti Gandluri, Jakob Kummerow, Steven Fontanella, AyeAye, v8-risc...@chromium.org, v8-ppc...@googlegroups.com, v8-mip...@googlegroups.com, dmercadi...@chromium.org, v8-re...@googlegroups.com, was...@google.com
    Attention needed from Deepti Gandluri and Jakob Kummerow

    Rezvan Mahdavi Hezaveh added 1 comment

    Rezvan Mahdavi Hezaveh . resolved

    Oh wait. I got some compile errors on some architectures. Let me fix them and send the correct CL for review. Sorry for the previous ping.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Deepti Gandluri
    • Jakob Kummerow
    Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: v8/v8
    Gerrit-Branch: main
    Gerrit-Change-Id: Ibe5b293ec5dfe64f1fab7ceec745f84c7765dad9
    Gerrit-Change-Number: 7164383
    Gerrit-PatchSet: 18
    Gerrit-Owner: Rezvan Mahdavi Hezaveh <rez...@chromium.org>
    Gerrit-Reviewer: Deepti Gandluri <gde...@chromium.org>
    Gerrit-Reviewer: Jakob Kummerow <jkum...@chromium.org>
    Gerrit-Reviewer: Rezvan Mahdavi Hezaveh <rez...@chromium.org>
    Gerrit-CC: Steven Fontanella <steve...@chromium.org>
    Gerrit-Attention: Deepti Gandluri <gde...@chromium.org>
    Gerrit-Attention: Jakob Kummerow <jkum...@chromium.org>
    Gerrit-Comment-Date: Tue, 13 Jan 2026 00:50:00 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy
    Reply all
    Reply to author
    Forward
    0 new messages