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

On Android platform aarch64 ABI does not return vec4 correctly #773

Open
jilinxiaohuo opened this issue Mar 14, 2023 · 3 comments
Open

On Android platform aarch64 ABI does not return vec4 correctly #773

jilinxiaohuo opened this issue Mar 14, 2023 · 3 comments

Comments

@jilinxiaohuo
Copy link

jilinxiaohuo commented Mar 14, 2023

System Details

platform: x86_64-pc-mingw64
toolchain: aarch64-unknown-linux-android
compiler: clang version 12.0.5

Problems Description

When calling the C++ member function glm::vec4 imageview::get_background_color() through ffi, the returnvalue parameter of the ffi_call can only get the first member (x) of vec4, and through debug, it is found that the st4 { v0.s, v1.s, v2.s, v3.s }[0], [x3] instructions used in sysV.S copy the return value. I debugged in lldb and found that the four members of vec4 are placed in the v0 register, not v0, v1, v2, v3 each stored in a float, changed to stp x0, x1, [x3] instructions can correctly get the return value. I also tried to return to vec3, and found that the three members of vec3 have stored v0, v1, v2 registers respectively, which can work correctly. Is there a way to get st4 to work correctly?

PS: the type of returnvalue passed to the ffi_call is:
type = new ffi_type;
memset(type, 0, sizeof(ffi_type));
type->type = FFI_TYPE_STRUCT;
type->elements = new ffi_type * [5];
type->elements[0] = &ffi_type_float;
type->elements[1] = &ffi_type_float;
type->elements[2] = &ffi_type_float;
type->elements[3] = &ffi_type_float;
type->elements[4] = nullptr;

@atgreen
Copy link
Member

atgreen commented Apr 3, 2023

I added two tests: 2d63cee

Can you please validate that I wrote them correctly for this problem?
They are passing on aarch64 Linux, so this must be an ABI difference on Android (or the tests are wrong).

@jilinxiaohuo
Copy link
Author

They are passing on my Android aarch64 platform.
There are some differences between your tests and my case.
The underlying type of glm::vec4 is float32x4_t( float32_t attribute((ext_vector_type(4))) ), which is defined in arm_neon.h.
I don't know how to describe float32x4_t with ffi_type_xxx.

@atgreen
Copy link
Member

atgreen commented Apr 5, 2023

Ok, got it. There was work in progress for this feature. It stalled, but you might want to look to see how close it is: #414

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

2 participants