Skip to content

wasm-opt missing support for table.fill #5939

Closed

Description

@kg

While wasm-opt appears to support table.grow correctly, any compiled module containing a table.fill instruction will fail to parse. This is true even if you pass the appropriate --enable-reference-types flag.

Sample code:

void
mono_jiterp_grow_function_table (int count, int fill_value) {
	__asm(
		// table.grow expects stack layout [fill_ref] [count]
		// start by loading fill_value, then fetching that reference from the indirect fn table
		"local.get 1;"
		"table.get __indirect_function_table;"
		// now fill_ref is on the stack, load count and perform the actual table grow
		"local.get 0;"
		"table.grow __indirect_function_table;"
		// table.grow returns either the new size or an error code. i'm too lazy to deal with it
		"drop;"
	);
}

#if 0
void
mono_jiterp_fill_function_table (int offset, int count, int fill_value) {
	__asm(
		// table.fill expects stack layout [offset] [fill_ref] [count]
		// load offset
		"local.get 0;"
		// load fill_value, then fetch that reference from the indirect fn table
		"local.get 2;"
		"table.get __indirect_function_table;"
		// now fill_ref is on the stack, load count and perform the actual table grow
		"local.get 1;"
		"table.fill __indirect_function_table;"
	);
}
#endif

change the #if 0 to #if 1 and the resulting built module will cause wasm-opt to fail with something like:

[parse exception: invalid code after misc prefix: 17 (at 0:266808)]
  Fatal: error parsing wasm (try --debug for more info)
emcc : error : '/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/wasm-opt --strip-dwarf --post-emscripten -O2 --low-memory-unused --zero-filled-memory --pass-arg=directize-initial-contents-immutable --strip-debug --strip-producers dotnet.native.wasm -o dotnet.native.wasm -g --mvp-features --enable-mutable-globals --enable-reference-types --enable-sign-ext --enable-simd' failed (returned 1) [/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/wasm.proj]

From checking the spec, 17 is table.fill. Looking through the repo it seems like support for table.init and table.copy might be missing too, but I'm not planning to use them...

Activity

  1. tlively commented on Sep 14, 2023

    @tlively
    Member

    You're the first person to ever ask for table.fill support! I can add it today.

  2. added a commit that references this issue on Sep 16, 2023
    5fd0930
  3. added a commit that references this issue on Sep 18, 2023
    003a6ff
  4. csjh commented on May 20, 2024

    @csjh

    Any chance table.init is being worked on? Seems like it's the lonely last table instruction left

  5. tlively commented on May 20, 2024

    @tlively
    Member

    There's no active work at the moment, but we might implement table.init soon as part of #6612.

  6. added a commit that references this issue on Jul 12, 2024
    038076c
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