Preventing Liftoff from compiling WASM atomic add with LOCK on x86_64?

141 views
Skip to first unread message

Keith Teo

unread,
Sep 25, 2024, 2:02:22 PM9/25/24
to v8-dev
Hi all,

I am trying to investigate the performance of WASM atomics with lower atomic guarantees. Specifically I am targeting the x86_64 architecture. i32.atomic.rmw.add currently compiles to LOCK XADDL, I want it to compile only to XADDL. I am changing "void LiftoffAssembler::AtomicAdd" in "src/wasm/baseline/x64/liftoff-assembler-x64-inl.h" by commenting out the lock() function on line 713. However, this does not seem to work. Neither does commenting out "emit(0xF0)" in "void Assembler:lock()" in assembler-x64.cc. I am running d8 with the -print-wasm-code, --liftoff and --no-wasm-tier-up flags. 

Could someone point me in the right direction on how I would do this? 


Clemens Backes

unread,
Sep 25, 2024, 2:46:03 PM9/25/24
to v8-...@googlegroups.com
Hi Keith,

you seem to be exactly on the right track. When I try it locally, it works as expected.

I use this test file:
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");

let builder = new WasmModuleBuilder();
builder.addImportedMemory('m', 'imported_mem', 0, 1);
builder.addFunction('atomic_add', kSig_i_ii)
    .addBody([
      kExprLocalGet, 0, kExprLocalGet, 1, kAtomicPrefix, kExprI32AtomicAdd, 2, 0
    ])
    .exportFunc();
builder.toModule();

And then I run it via:
out/x64.optdebug/d8 test.js --print-wasm-code --code-comments --liftoff-only --no-wasm-lazy-compilation --no-debug-code

Originally I find this in the output:
                  atomic binop
                  [ load memory start
0x227693bb48cb    4b  488b5e17             REX.W movq rbx,[rsi+0x17]
                  ]
0x227693bb48cf    4f  488bca               REX.W movq rcx,rdx
0x227693bb48d2    52  f00fc10c03           lock xaddl [rbx+rax*1],rcx

After commenting out the lock() in LiftoffAssembler::AtomicAdd, I see this disassembly:
                  atomic binop
                  [ load memory start
0x1ece0cd448cb    4b  488b5e17             REX.W movq rbx,[rsi+0x17]
                  ]
0x1ece0cd448cf    4f  488bca               REX.W movq rcx,rdx
0x1ece0cd448d2    52  0fc10c03             xaddl [rbx+rax*1],rcx

I don't know what went wrong on your side.

-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 on the web visit https://groups.google.com/d/msgid/v8-dev/838d2d34-3a8c-46da-8cf8-524e32f1a57cn%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