This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Support for atomic.wait / atomic.wake builtins
ClosedPublic

Authored by aheejin on Jul 16 2018, 12:18 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

aheejin created this revision.Jul 16 2018, 12:18 PM
aheejin updated this revision to Diff 155738.Jul 16 2018, 12:19 PM
  • test fix
aheejin edited the summary of this revision. (Show Details)Jul 16 2018, 12:20 PM
aheejin edited the summary of this revision. (Show Details)
aheejin updated this revision to Diff 155958.Jul 17 2018, 1:32 PM
  • Type fix
aheejin updated this revision to Diff 158017.Jul 30 2018, 11:13 AM
  • Changed the first argument of wake from i8* to i32*
dschuff added inline comments.Jul 31 2018, 4:35 PM
include/clang/Basic/BuiltinsWebAssembly.def
38 ↗(On Diff #158017)

So this means that the signature is basically unsigned int __builtin_wasm_atomic_wait_i32(int *, int, long long)? We should maybe make it int __builtin_wasm_atomic_wait_i32(const unsigned char *, int, unsigned long long). Returning int so that you could define a C enum with the possible return values and compare without type coercion; unsigned char * so that it aliases with everything (i.e. a byte ptr), and unsigned long long since a negative relative timeout isn't meaningful(?). Not sure whether we should use int or unsigned int as the expected value, can't think of any particular reason right now to use one or the other.

Likewise with the other signatures.

aheejin updated this revision to Diff 158434.Jul 31 2018, 6:05 PM
aheejin marked an inline comment as done.
  • Changed types
include/clang/Basic/BuiltinsWebAssembly.def
38 ↗(On Diff #158017)

Returning int so that you could define a C enum with the possible return values and compare without type coercion;

Done.

unsigned char * so that it aliases with everything (i.e. a byte ptr),

From this pointer a value will be loaded and compared with the expected value, which is an int. Shouldn't this be an int pointer then? Not sure why it should alias with a byte ptr.

and unsigned long long since a negative relative timeout isn't meaningful(?).

Timeouts can be negative, in which case it never expires. The wake count of atomics.wake builtin can be negative too, in which case it waits for all waiters.

Not sure whether we should use int or unsigned int as the expected value, can't think of any particular reason right now to use one or the other.

We didn't impose any restrictions other than it is an int in the spec, so I think it should be a (signed) int?

aheejin updated this revision to Diff 158555.Aug 1 2018, 9:40 AM
  • wake -> notify
dschuff accepted this revision.Aug 1 2018, 4:52 PM
dschuff added inline comments.
include/clang/Basic/BuiltinsWebAssembly.def
38 ↗(On Diff #158017)

Oh you're right, I misread the spec. So int * and signed timeout is fine. For the expected value (and the pointer type) it could still be either signed or unsigned because at the wasm level there's no distinction. but signed int seems fine as it is.

This revision is now accepted and ready to land.Aug 1 2018, 4:52 PM
This revision was automatically updated to reflect the committed changes.