Adding new WebAssembly opcode?

57 views
Skip to first unread message

Keith Teo

unread,
Jan 13, 2025, 3:02:18 PMJan 13
to v8-dev
Hi all,

I am trying to add a new WASM release atomic store opcode (instead of the default seqcst atomic store). I aim to compile it on x64 to MOV, while the current i32.atomic.store compiles to (LOCK) XCHG. I've made a number of changes, largely at the functions/macros where WASM opcodes are lowered to native x64 code, by creating a new instruction similar to i32.atomic.store but emitting MOV instead. I've got it to accept my new opcode, and it runs without error in d8, but checking the output of compiling with the standard i32.atomic.store and the new opcode there's no difference. And looking deeper into the code, there's a lot of higher level functions that deals more abstractly with atomicity, memory ordering and such which is beyond me to understand right now.

Could anyone point me in the right direction of what I would need to add and in which files?

Some details:

1) I am targeting the Liftoff compiler
2) The new opcode is named i32.atomic.store.release, with opcode fe04 (original i32.atomic.store has opcode fe17)

You can see the changes I made here
https://github.com/KayTeo/v8/commits/main/

Thanks,
Keith

Clemens Backes

unread,
Jan 14, 2025, 4:50:29 AMJan 14
to v8-...@googlegroups.com
Hi Keith,

You added the opcode to the `ATOMIC_STORE_LIST` in this CL and used the same `StoreType` as the existing store. This makes your new instruction identical to the existing "i32.atomic.store" instruction.
Since you want to pass additional information about the memory ordering down to code generation, I would propose introducing a new enum for this, like `enum MemoryOrdering { kSeqCst, kRelease}`, and passing that to the existing `AtomicStoreMem` helper. You could then just handle your new opcode explicitly in the existing switch in `AtomicOp`: `case kExprI32AtomicStoreRelease: AtomicStoreMem(decoder, StoreType::kI32Store, imm, MemoryOrdering::kRelease); break;`.
The `LiftoffCompiler::AtomicStore` method would then pass the `MemoryOrdering` down to `LiftoffAssembler::AtomicStore`, where you would emit a `movl` instead of `xchgl` if the new parameter is `MemoryOrdering::kRelease`.

Hope that helps,
Clemens



--
--
v8-dev mailing list
v8-...@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/v8-dev/1df186f5-e26f-489c-82cc-f2ae9a74a454n%40googlegroups.com.


--

Clemens Backes

Software Engineer

clem...@google.com

Google Germany GmbH

Erika-Mann-Straße 33

80636 München


Geschäftsführer: Paul Manicle, Liana Sebastian   

Registergericht und -nummer: Hamburg, HRB 86891

Sitz der Gesellschaft: Hamburg


Diese E-Mail ist vertraulich. Falls sie diese fälschlicherweise erhalten haben sollten, leiten Sie diese bitte nicht an jemand anderes weiter, löschen Sie alle Kopien und Anhänge davon und lassen Sie mich bitte wissen, dass die E-Mail an die falsche Person gesendet wurde.


This e-mail is confidential. If you received this communication by mistake, please don't forward it to anyone else, please erase all copies and attachments, and please let me know that it has gone to the wrong person.


Reply all
Reply to author
Forward
0 new messages