Skip to content

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

Closed

Description

@jilinxiaohuo

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;

Activity

  1. atgreen commented on Apr 3, 2023

    @atgreen
    Member

    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).

  2. jilinxiaohuo commented on Apr 4, 2023

    @jilinxiaohuo
    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.

  3. atgreen commented on Apr 5, 2023

    @atgreen
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions