Skip to content

Added atomic ops to binaryen.js as well#1280

Merged
kripken merged 1 commit intoWebAssembly:masterfrom
dcodeIO:js-atomic-ops
Nov 13, 2017
Merged

Added atomic ops to binaryen.js as well#1280
kripken merged 1 commit intoWebAssembly:masterfrom
dcodeIO:js-atomic-ops

Conversation

@dcodeIO
Copy link
Copy Markdown
Contributor

@dcodeIO dcodeIO commented Nov 10, 2017

As a follow-up to #1276 being merged, this PR adds the following methods to binaryen.js:

  • Module#i32/i64.atomic.rmw.add
  • Module#i32/i64.atomic.rmw8_u.add
  • Module#i32/i64.atomic.rmw16_u.add
  • Module#i64.atomic.rmw32_u.add
  • Module#i32/i64.atomic.rmw.sub
  • Module#i32/i64.atomic.rmw8_u.sub
  • Module#i32/i64.atomic.rmw16_u.sub
  • Module#i64.atomic.rmw32_u.sub
  • Module#i32/i64.atomic.rmw.and
  • Module#i32/i64.atomic.rmw8_u.and
  • Module#i32/i64.atomic.rmw16_u.and
  • Module#i64.atomic.rmw32_u.and
  • Module#i32/i64.atomic.rmw.or
  • Module#i32/i64.atomic.rmw8_u.or
  • Module#i32/i64.atomic.rmw16_u.or
  • Module#i64.atomic.rmw32_u.or
  • Module#i32/i64.atomic.rmw.xor
  • Module#i32/i64.atomic.rmw8_u.xor
  • Module#i32/i64.atomic.rmw16_u.xor
  • Module#i64.atomic.rmw32_u.xor
  • Module#i32/i64.atomic.rmw.cmpxchg
  • Module#i32/i64.atomic.rmw8_u.cmpxchg
  • Module#i32/i64.atomic.rmw16_u.cmpxchg
  • Module#i64.atomic.rmw32_u.cmpxchg
  • Module#i32/i64.wait
  • Module#wake

Each method is named after its text format representation (I used Print.cpp as a reference) and takes the same parameters as its respective C-API function, with module, op, bytes, type, expectedType (if applicable) substituted accordingly.

Copy link
Copy Markdown
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise this looks good, but please add a test.

Comment thread src/js/binaryen.js-post.js Outdated

function makeAtomicOps(ofType) {
return {
'rmw': {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could perhaps be more concise, since the return [..] line is almost identical on all these except one. So we could switch on just the add => Module['AtomicRMWAdd'] parts, what do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't sure if there might be additional atomic ops in the future, besides rmw. Other than that, we'd also have to repeat the { 'rmw': ... } four times below then - or did you mean to remove the rmw subsection entirely?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean by repeating that section, but maybe I wasn't clear before. This is what I meant, just to remove the duplication in those rmws by changing makeAtomicOps to this: https://gist.github.com/kripken/406fa34ab78a608a3442aaa8b0e77a40

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks. This could be done for other functions as well. Though, the updated commit now uses the usual format similar to the other functions. Suggesting to leave the refactoring for another PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

@binji
Copy link
Copy Markdown
Member

binji commented Nov 11, 2017

There are no f32/f64 atomic ops in wasm currently, so it's probably best not to add these to binaryen.

@dcodeIO
Copy link
Copy Markdown
Contributor Author

dcodeIO commented Nov 11, 2017

Sorry, had a bad start on this one. Should actually stick to the text format now and implement supported ops only.

@kripken kripken merged commit 29963c3 into WebAssembly:master Nov 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants