Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine alignment #31

Merged
merged 5 commits into from
Aug 28, 2015
Merged

Refine alignment #31

merged 5 commits into from
Aug 28, 2015

Conversation

lukewagner
Copy link
Member

Extending #30, this patch moves the alignment aspect of linear memory ops to what's in the design repo as follows:

  • remove Memory.alignment from Memory since alignment makes no semantic difference
  • add Ast.alignment, since load/store AST nodes do have an alignment field
  • switches alignment from a binary Aligned|Unaligned to an int which is validated to be {1,2,4,8} and smaller than the element size

@@ -241,6 +239,13 @@ and check_arm c t ts arm =
check_literal c [t] l;
check_expr c (if fallthru then [] else ts) e

and check_memop memop at =
require (memop.align = 1 || memop.align = 2 ||
memop.align = 4 || memop.align = 8)
Copy link
Member

Choose a reason for hiding this comment

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

Since we're checking that the alignment is at most the access size below, would it make sense to just check that the alignment is a power of 2 here, instead of having an explicit list? That way it'll automatically generalize to SIMD types.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed.

Extra advantage: subsequent indexed memory accesses can also key off the first access' alignment (base has an alignment, other indices don't because the alignment is implied).

Copy link
Member Author

Choose a reason for hiding this comment

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

Righto

@rossberg
Copy link
Member

Lgtm, other than README ;)

@lukewagner
Copy link
Member Author

Gosh, the README, it is my blind spot. lmk if Lib.is_power_of_two is the right place to put this.

@@ -26,6 +27,17 @@
(module (memory 100 1000 (segment 0 "a") (segment 2 "b") (segment 1 "c")))
"data segment not disjoint and ordered")

;; Test alignment annotation rules
(assertinvalid (module (func (loadu.2.i8 (const.i32 0)))) "alignment too big")
Copy link
Member

Choose a reason for hiding this comment

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

Too big alignment is part of the design so this test isn't correct.

Copy link
Member Author

Choose a reason for hiding this comment

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

The design document isn't expected to be a complete enumeration of all invalid conditions, that's what spec is for and so this test is correct, wrt the spec as updated by this PR. If you would like to disagree and argue that we should allow too-big alignment in the spec, that's another matter entirely, we shouldn't expect the high-level design repo to have to reiterate every single minute detail; that's not its purpose.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed that the design doc isn't expected to be complete, but this specific case was discussed when creating the design, and we agreed that alignment just had to be a positive power of 2, no limits. This spec PR contradicts the design and what we agreed on, so the design is now wrong.

In cases like this the discussion should occur in the design repo: it revisits a decision that was made in the design repo. What the point of agreeing on anything in the design repo otherwise? I'm not saying that the design is golden and shouldn't change (witness the issues I've filed recently), I'm saying that we want to avoid diverging slightly in every place we implement wasm.

It's great the the spec repo finds unforeseen problems with the design, but this one wasn't unforeseen!

Copy link
Member Author

Choose a reason for hiding this comment

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

I was not aware that anyone had discussed this issue; could you provide a link? This seems like the sort of decision that should be explicitly documented since it's nonobvious whether "power of 2" is just waving its hands at the boundary conditions (as we often do) or really means "no, seriously, every power of 2!" (up to what limit?). I'm happy to remove this check here for now since ultimately it's a minor detail and people have actually discussed it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Anyhow, now it's explicit in code and a test; the process is working!

lukewagner added a commit that referenced this pull request Aug 28, 2015
@lukewagner lukewagner merged commit 47fb41a into master Aug 28, 2015
@lukewagner lukewagner deleted the refine-alignment branch August 28, 2015 00:47
@lukewagner
Copy link
Member Author

Merging based on lgtm above and no outstanding concerns.

littledan pushed a commit to littledan/spec that referenced this pull request Mar 4, 2018
* Add clearer examples to Globals.md for rationale

* Fix destructuring

* Add comment about using globals for other TLS values

* Add example using WebAssembly.Global
eqrion pushed a commit to eqrion/wasm-spec that referenced this pull request Jul 18, 2019
…mory.init`, `memory.drop`, `table.init`, and `table.drop` identify passive segments; only that they index a valid segment. (WebAssembly#31)
alexcrichton pushed a commit to alexcrichton/spec that referenced this pull request Nov 19, 2019
…statement

Fix reference to `bind` statement
ErikMcClure pushed a commit to innative-sdk/spec that referenced this pull request Jun 15, 2020
dhil pushed a commit to dhil/webassembly-spec that referenced this pull request Apr 13, 2023
* Add a simple and more involved generator example

* More examples
dhil added a commit to dhil/webassembly-spec that referenced this pull request Apr 29, 2024
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.

4 participants