You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 15, 2025. It is now read-only.
Repository navigation
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
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
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.
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.
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.
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.
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:
Allow the limits of a tabletype to specify an i64 index type
Extend text format parsing of tables to allow specifying index type
Extend JS-API table constructors to take index type
Extend JS-API get/set methods to take i64 values? (might be superseded by an implementation limit)
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.
Yes, that sounds correct to me.
FWIW, the way C function pointers are currently compiled to WASM does not
do any of the bounds checking. This is not "unsafe" because bounds are
still being checked after the 64->32 bit truncation has occurred. However,
this is less than ideal because an out-of-bounds 64-bit function pointer
could become valid during the truncation, so we currently lose some
fidelity in error checking there.
Thanks for considering this!
Matthias
On Wed, Feb 21, 2024 at 2:33 PM Ryan Hunt ***@***.***> wrote:
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.
—
Reply to this email directly, view it on GitHub
<#46 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB56SSVVHQSAG22IUGBUMADYUZKYZAVCNFSM6AAAAABDLDR52KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJXHA3DAMZYGM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
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).
Reacted by Valerio De Benedetto and Andreas Rossberg
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!
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.
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.
@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)
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.
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.
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.
Activity
[-]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[/+]sbc100 commentedon Feb 15, 2024
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)
sunfishcode commentedon Feb 16, 2024
I don't see a strong motivation for this. Looking at #43 and #10, the concrete motivations seem to be:
call_indirectinstructions in typical compiled C code, which is theorized to be a code-size win, however the theoretical impact has not been calculated.eqrion commentedon Feb 16, 2024
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.
rossberg commentedon Feb 16, 2024
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.
backes commentedon Feb 19, 2024
Implementing explicit bounds checking of
i64values 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.
eqrion commentedon Feb 21, 2024
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:
- 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.
matthias-blume commentedon Feb 21, 2024
sbc100 commentedon Mar 25, 2024
I've put some time on tomorrow's CG meeting agenda to discuss this issue.
sbc100 commentedon Mar 26, 2024
As per today's CG discussion lets have an informal poll here by voting thumbs up or thumbs down on OP of this issue.
sbc100 commentedon Apr 13, 2024
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).
conrad-watt commentedon Apr 13, 2024
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!
rossberg commentedon Apr 13, 2024
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.
conrad-watt commentedon Apr 13, 2024
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.
conrad-watt commentedon Apr 22, 2024
@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)
schedule table64 poll
schedule table64 poll (#1544)
sbc100 commentedon Apr 23, 2024
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.
sbc100 commentedon Apr 23, 2024
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
.setand.getmethods 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
.getand.setmethods for 64-bit tables could either either Number or BigInt as arguments.conrad-watt commentedon Apr 23, 2024
What is currently done for 64 bit memories in the JS API? I vaguely remember we previously discussed a
2^53JS 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.sbc100 commentedon Apr 23, 2024
Memory access is done via JavaScript typed arrays which can be indexed by both Number and BigInt. By analogy I suppose that
.getand.setshould also accept both.sbc100 commentedon Apr 24, 2024
Closing this issue for now. Implementation will be tracked in #51.
Merge pull request #46 from yamt/memory_copy1