Skip to content

fix(arm64): a homogeneous float aggregate takes one SIMD register per element - #627

Merged
SamboyCoding merged 1 commit into
SamboyCoding:developmentfrom
XHuoHuaX:pr/arm64-hfa
Nov 28, 2026
Merged

SamboyCoding merged 1 commit into
SamboyCoding:developmentfrom
XHuoHuaX:pr/arm64-hfa

Conversation

@XHuoHuaX

@XHuoHuaX XHuoHuaX commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

What this fixes

AAPCS64 passes a homogeneous floating-point aggregate — a struct whose instance fields are all float, or all double, one to four of them — in consecutive SIMD registers. IL2CPP follows the platform ABI for managed methods, so a Vector3 argument occupies V0..V2, the float argument after it goes in V3, and the null MethodInfo slot sits in X0.

The ARM64 resolver counted every parameter as exactly one register slot, so an HFA took the struct's integer register. Every argument after such a struct was then read from the wrong register — typically X0, the nil MethodInfo — which is where literal 0s in call arguments come from, and why the decompiled output reports int -> Vector3 conversion errors (CS0030).

Evidence

Assembly-CSharp::AutoRotation::Update, whose native body passes rot in V0..V2 and deltaTime in V3:

before: Call Vector3.op_Multiply, dest, 0, this.rot
after : Call Vector3.op_Multiply, dest, this.rot, v68 @ V0_v1 (Single)

Measured effect

Over a 46,727-method IL2CPP game (ARM64, metadata 24.5), compiling the decompiled output assembly by assembly:

before after
total C# compile errors 9,395 7,965
CS0030 ("cannot convert") 3,229 1,913

7 assemblies improved, none regressed.

How it is scoped

  • HomogeneousFloatAggregate.Count flattens nested aggregates, bounds the element count (4) and the nesting depth, refuses mixed float/double, and returns 0 when the layout is unknown so such a parameter keeps the previous behaviour rather than guessing.
  • AddParameterSlots expands such a parameter into one slot per element while still contributing exactly one call operand, so the operand↔parameter mapping stays 1:1 and nothing downstream has to change.
  • Purely ABI-shaped: no game- or type-specific constants. The rule describes "a struct of 1–4 identical floating-point fields", which is the ABI's own definition.

Notes for review

  • The base-class hook is a protected virtual AddParameterSlots with the previous one-slot behaviour as its default, so other architectures are untouched.
  • I could not add a unit test: this needs a real ARM64 IL2CPP binary to exercise, and the repo's test files do not include one. Happy to add a test if you can point me at a suitable fixture, or to restructure this as you prefer.

…er element

AAPCS64 passes a struct whose instance fields are all float (or all double), one to four of
them, in consecutive SIMD registers. IL2CPP follows the platform ABI for managed methods:
Vector3 occupies V0..V2, so the float argument after it goes in V3, and the null MethodInfo
slot sits in X0.

The resolver counted every parameter as one slot, taking the struct's integer register. Every
argument after such a struct was then read from the wrong register - typically X0, the nil
MethodInfo - which is why call arguments showed up as a literal 0 and C# reported
int -> Vector3 conversion errors.

Adds HomogeneousFloatAggregate.Count, which flattens nested aggregates, bounds both the element
count (4) and the nesting depth, refuses mixed float/double, and returns 0 when the layout is
unknown so such a parameter keeps the previous behaviour. AddParameterSlots expands such a
parameter into one slot per element while still contributing exactly one call operand, so the
operand-to-parameter mapping stays 1:1.

Verified on Assembly-CSharp::AutoRotation::Update, whose native body passes rot in V0..V2 and
deltaTime in V3:
  before: Call Vector3.op_Multiply, dest, 0, this.rot
  after : Call Vector3.op_Multiply, dest, this.rot, v68 @ V0_v1 (Single)

Measured over a 46,727-method IL2CPP game (ARM64, metadata 24.5) by compiling the decompiled
output assembly by assembly: total C# compile errors 9,395 -> 7,965, of which "cannot convert"
(CS0030) 3,229 -> 1,913. 7 assemblies improved, none regressed.
@SamboyCoding
SamboyCoding merged commit eeaf6b5 into SamboyCoding:development Nov 28, 2026
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

Successfully merging this pull request may close these issues.

2 participants