Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Adding support for 64-bit call_indirect or full table64 support #46

Closed

Description

@sbc100

When targeting wasm64 today llvm currently truncates the i64 pointer operand to call_indirect since call_indirect currently requires a i32.

Should we add support for an i64 operand to call_indirect as part of this proposal?

If so, should we do this by adding the concept of 64-bit-indexed table?

There have been some discussion of this already in both #43 and in #10 since I thought it worth creating a separate issue.

Activity

  1. changed the title [-]Should we include support for 64-bit call_indirect or full table64 support in this proposal[/-] [+]Adding support for 64-bit call_indirect or full table64 support[/+] on Feb 15, 2024
  2. sbc100 commented on Feb 15, 2024

    @sbc100
    MemberAuthor

    My understanding is that this would not but much work from the implementation side. @backes and @eqrion perhaps you could confirm?

    (To be clear this would not involve implementations having to increase the size of the tables they support)

  3. sunfishcode commented on Feb 16, 2024

    @sunfishcode
    Member

    I don't see a strong motivation for this. Looking at #43 and #10, the concrete motivations seem to be:

    • Avoiding conversion instructions before call_indirect instructions in typical compiled C code, which is theorized to be a code-size win, however the theoretical impact has not been calculated.
    • A compiler that deliberately violates the Wasm spec and omits sandboxing would be helped, however this is not a priority for Wasm.
  4. eqrion commented on Feb 16, 2024

    @eqrion
    Contributor

    My understanding is that this would not but much work from the implementation side. @backes and @eqrion perhaps you could confirm?

    (To be clear this would not involve implementations having to increase the size of the tables they support)

    It would be a 'fair' amount of work. We'd have to update our codegen for call_indirect bounds checking to perform the truncation/overflow check, including on 32-bit systems where the 64-bit pointer is two registers. Nothing we've not done before, but also not just a couple days of work.

  5. rossberg commented on Feb 16, 2024

    @rossberg
    Member

    IIRC, the problem (reported by @matthias-blume at the time) was that implementing the right behaviour for invalid function pointers when "safely" compiling something like C required manual bounds checks in user code, since simply truncating from 64 to 32 bit before call_indirect might accidentally result in a successful call through an invalid pointer.

    There also is the question of coherence of Wasm itself. We generally tried to keep memories and tables as similar as possible, especially after tables were repurposed to a general storage for references with the GC proposal, tables now being to reference types what memory is to numeric types.

  6. backes commented on Feb 19, 2024

    @backes
    Member

    My understanding is that this would not but much work from the implementation side. @backes and @eqrion perhaps you could confirm?

    (To be clear this would not involve implementations having to increase the size of the tables they support)

    Implementing explicit bounds checking of i64 values against 32-bit values (e.g. for memory accesses on 32-bit platforms) didn't turn out to be particularly hard in V8. I guess we could reuse most of that for 64-bit table indexing.
    I think "a few days of work" is the right bucket for this.

  7. eqrion commented on Feb 21, 2024

    @eqrion
    Contributor

    So just to make sure I understand what's being proposed, this would be a general '(table i64)' feature even if we maintain a <2^32 implementation limit on their size?

    So we'd need to:

    1. Allow the limits of a tabletype to specify an i64 index type
    2. Extend text format parsing of tables to allow specifying index type
    3. Extend JS-API table constructors to take index type
    4. Extend JS-API get/set methods to take i64 values? (might be superseded by an implementation limit)
    5. Update the following instructions to take i32 or i64, depending on the type:
      - table.get/set/size
      - table.grow?
      - call_indirect

    I think this could be a reasonable feature, and the example of correct compilation that Rossberg mentions seems compelling.

  8. matthias-blume commented on Feb 21, 2024

    @matthias-blume
  9. sbc100 commented on Mar 25, 2024

    @sbc100
    MemberAuthor

    I've put some time on tomorrow's CG meeting agenda to discuss this issue.

  10. sbc100 commented on Mar 26, 2024

    @sbc100
    MemberAuthor

    As per today's CG discussion lets have an informal poll here by voting thumbs up or thumbs down on OP of this issue.

  11. sbc100 commented on Apr 13, 2024

    @sbc100
    MemberAuthor

    Looks like we have 8 to 1 for adding this to memory64 proposal. @conrad-watt do you think we need to take this back to the CG or can we simply move ahead with this? I'm hoping we can simply start work on it immediately (perhaps we can do both.. i.e. start work and have a vote ASAP).

  12. conrad-watt commented on Apr 13, 2024

    @conrad-watt
    Contributor

    Given the late stage of the proposal, this change should be confirmed with a pre-announced vote in the CG.

    Given the straw poll here, I think it's ok for work to be started in anticipation of the vote result, but just be aware that if the vote goes a surprising way there may be the potential for wasted work!

  13. rossberg commented on Apr 13, 2024

    @rossberg
    Member

    Given the late stage of the proposal, this change should be confirmed with a pre-announced vote in the CG.

    Just want to note that this isn't a change, merely an addition, so champion's discretion could suffice? Technically, the only required votes are the stage votes.

  14. conrad-watt commented on Apr 13, 2024

    @conrad-watt
    Contributor

    Technically, the only required votes are the stage votes.

    There's no hard and fast rule on how much a proposal can be changed at phase 3, but assuming we're going with full table64 support we're essentially skipping a (small) feature-sized group of instructions past the regular phase process to phase 3. We should take extra care to make sure consensus on this decision is well-recorded, especially since the proposal has otherwise stayed unchanged for quite a while and there's no associated subgroup where regular discussions are happening.

    It's not world-ending either way, but IMO it's better to take the extra meeting slot to be very deliberate about this and minimize surprise for the ecosystem.

  15. conrad-watt commented on Apr 22, 2024

    @conrad-watt
    Contributor

    @sbc100 would you be ok with us slotting a brief confirmatory vote into tomorrow's meeting, or do you want this to settle for a little longer? (edit: see PR)

  16. added a commit that references this issue on Apr 22, 2024
  17. added a commit that references this issue on Apr 22, 2024
  18. sbc100 commented on Apr 23, 2024

    @sbc100
    MemberAuthor

    The poll on today's CG meeting was positive (all votes we in favor or neutral) so it looks like we will be going ahead with this.

  19. sbc100 commented on Apr 23, 2024

    @sbc100
    MemberAuthor
    • Extend JS-API get/set methods to take i64 values? (might be superseded by an implementation limit)

    This issue likely requires come consideration. In JavaScript i64 pointers tend to be represented as BigInt values and by extension it would make sense to allow these pointers to be used as arguments to the JavaScript .set and .get methods on tables.

    However, in emscripten today it actually convert pointers to JavaScript Numbers (i.e. 53bit numbers) so for the emscripten POV it would be great if the .get and .set methods for 64-bit tables could either either Number or BigInt as arguments.

  20. conrad-watt commented on Apr 23, 2024

    @conrad-watt
    Contributor

    What is currently done for 64 bit memories in the JS API? I vaguely remember we previously discussed a 2^53 JS implementation limit on memory size, to ensure that regular JS numbers could continue to be used as indices. If we followed through on this idea for memories, we could do the same for tables.

  21. sbc100 commented on Apr 23, 2024

    @sbc100
    MemberAuthor

    What is currently done for 64 bit memories in the JS API? I vaguely remember we previously discussed a 2^53 JS implementation limit on memory size, to ensure that regular JS numbers could continue to be used as indices. If we followed through on this idea for memories, we could do the same for tables.

    Memory access is done via JavaScript typed arrays which can be indexed by both Number and BigInt. By analogy I suppose that .get and .set should also accept both.

  22. sbc100 commented on Apr 24, 2024

    @sbc100
    MemberAuthor

    Closing this issue for now. Implementation will be tracked in #51.

  23. added a commit that references this issue on Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions