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

performance issue for std::span on wasm C calling convention #217

Open
trcrsired opened this issue Oct 3, 2023 · 5 comments
Open

performance issue for std::span on wasm C calling convention #217

trcrsired opened this issue Oct 3, 2023 · 5 comments

Comments

@trcrsired
Copy link

trcrsired commented Oct 3, 2023

#include<span>
#include<cstddef>

void baz(::std::size_t *ptr,::std::size_t n) noexcept;

void foo(::std::span<::std::size_t> sp) noexcept
{
	baz(sp.data(),sp.size());
}

void bar(::std::size_t *ptr,::std::size_t n) noexcept
{
	baz(ptr,n);
}
_Z3fooNSt3__14spanImLm4294967295EEE:    # @_Z3fooNSt3__14spanImLm4294967295EEE
	.functype	_Z3fooNSt3__14spanImLm4294967295EEE (i32) -> ()
# %bb.0:
	local.get	0
	i32.load	0
	local.get	0
	i32.load	4
	call	_Z3bazPmm
                                        # fallthrough-return
	end_function
                                        # -- End function
	.section	.text._Z3barPmm,"",@
	.hidden	_Z3barPmm                       # -- Begin function _Z3barPmm
	.globl	_Z3barPmm
	.type	_Z3barPmm,@function
_Z3barPmm:                              # @_Z3barPmm
	.functype	_Z3barPmm (i32, i32) -> ()
# %bb.0:
	local.get	0
	local.get	1
	call	_Z3bazPmm
                                        # fallthrough-return
	end_function

std::span is passed by memory, not by registers on wasm. which is extremely slow.

This is going to encourage people to overuse pointers. Please change the calling convention here. Also, the return value has the same issue.

@dschuff
Copy link
Member

dschuff commented Oct 3, 2023

What happens if you enable -mmulti-value? IIRC we use a different calling convention there, which passes structures in registers.

@trcrsired
Copy link
Author

What happens if you enable -mmulti-value? IIRC we use a different calling convention there, which passes structures in registers.

Nothing changes. It is an ABI issue.

@tlively
Copy link
Member

tlively commented Oct 27, 2023

The full set of magic flags @dschuff is thinking of is -mmultivalue -Xclang -target-abi -Xclang experimental-mv.

@dschuff
Copy link
Member

dschuff commented Oct 27, 2023

Ah thanks for that, I had forgotten that the feature enabler and the ABI were separate flags.

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

No branches or pull requests

3 participants