fix: handle arm64 float arrays in HFA detection
- commit
- 5e114e1bf8ccae01abd55a03b1e1737f1fe68223
- author
- brice · · 2026-04-13 10:13 UTC
- parent
- b883928
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +22 -1
M struct_arm64.go +15 -1
| @@ -230,7 +230,7 @@ func placeStack(v reflect.Value, keepAlive []any, addInt func(uintptr)) []any { | |||
| 230 | 230 | // [Arm64 Calling Convention]: https://github.com/ARM-software/abi-aa/blob/main/sysvabi64/sysvabi64.rst | |
| 231 | 231 | func isHFA(t reflect.Type) bool { | |
| 232 | 232 | structSize := roundUpTo8(t.Size()) | |
| 233 | - | if structSize == 0 || t.NumField() > 4 { | |
| 233 | + | if structSize == 0 { | |
| 234 | 234 | return false | |
| 235 | 235 | } | |
| 236 | 236 | var kind reflect.Kind | |
| @@ -254,6 +254,20 @@ func isHFA(t reflect.Type) bool { | |||
| 254 | 254 | if !walk(ft) { | |
| 255 | 255 | return false | |
| 256 | 256 | } | |
| 257 | + | case reflect.Array: | |
| 258 | + | elemKind := ft.Elem().Kind() | |
| 259 | + | if elemKind != reflect.Float32 && elemKind != reflect.Float64 { | |
| 260 | + | return false | |
| 261 | + | } | |
| 262 | + | if kind == 0 { | |
| 263 | + | kind = elemKind | |
| 264 | + | } else if elemKind != kind { | |
| 265 | + | return false | |
| 266 | + | } | |
| 267 | + | members += ft.Len() | |
| 268 | + | if members > 4 { | |
| 269 | + | return false | |
| 270 | + | } | |
| 257 | 271 | default: | |
| 258 | 272 | return false | |
| 259 | 273 | } | |
| @@ -230,7 +230,7 @@ func placeStack(v reflect.Value, keepAlive []any, addInt func(uintptr)) []any { | |||||
| 230 | // [Arm64 Calling Convention]: https://github.com/ARM-software/abi-aa/blob/main/sysvabi64/sysvabi64.rst | 230 | // [Arm64 Calling Convention]: https://github.com/ARM-software/abi-aa/blob/main/sysvabi64/sysvabi64.rst | ||
| 231 | func isHFA(t reflect.Type) bool { | 231 | func isHFA(t reflect.Type) bool { | ||
| 232 | structSize := roundUpTo8(t.Size()) | 232 | structSize := roundUpTo8(t.Size()) | ||
| 233 | - | if structSize == 0 || t.NumField() > 4 { | 233 | + | if structSize == 0 { |
| 234 | return false | 234 | return false | ||
| 235 | } | 235 | } | ||
| 236 | var kind reflect.Kind | 236 | var kind reflect.Kind | ||
| @@ -254,6 +254,20 @@ func isHFA(t reflect.Type) bool { | |||||
| 254 | if !walk(ft) { | 254 | if !walk(ft) { | ||
| 255 | return false | 255 | return false | ||
| 256 | } | 256 | } | ||
| 257 | + | case reflect.Array: | |||
| 258 | + | elemKind := ft.Elem().Kind() | |||
| 259 | + | if elemKind != reflect.Float32 && elemKind != reflect.Float64 { | |||
| 260 | + | return false | |||
| 261 | + | } | |||
| 262 | + | if kind == 0 { | |||
| 263 | + | kind = elemKind | |||
| 264 | + | } else if elemKind != kind { | |||
| 265 | + | return false | |||
| 266 | + | } | |||
| 267 | + | members += ft.Len() | |||
| 268 | + | if members > 4 { | |||
| 269 | + | return false | |||
| 270 | + | } | |||
| 257 | default: | 271 | default: | ||
| 258 | return false | 272 | return false | ||
| 259 | } | 273 | } | ||
M struct_arm64_regression_test.go +7 -0
| @@ -28,3 +28,10 @@ func TestIsHFAAcceptsNestedFloatStructs(t *testing.T) { | |||
| 28 | 28 | t.Fatal("expected nested float-only struct to be HFA") | |
| 29 | 29 | } | |
| 30 | 30 | } | |
| 31 | + | ||
| 32 | + | func TestIsHFAAcceptsFloatArrayStruct(t *testing.T) { | |
| 33 | + | type arrayed struct{ A [2]float64 } | |
| 34 | + | if !isHFA(reflect.TypeOf(arrayed{})) { | |
| 35 | + | t.Fatal("expected float array struct to be HFA") | |
| 36 | + | } | |
| 37 | + | } | |
| @@ -28,3 +28,10 @@ func TestIsHFAAcceptsNestedFloatStructs(t *testing.T) { | |||||
| 28 | t.Fatal("expected nested float-only struct to be HFA") | 28 | t.Fatal("expected nested float-only struct to be HFA") | ||
| 29 | } | 29 | } | ||
| 30 | } | 30 | } | ||
| 31 | + | ||||
| 32 | + | func TestIsHFAAcceptsFloatArrayStruct(t *testing.T) { | |||
| 33 | + | type arrayed struct{ A [2]float64 } | |||
| 34 | + | if !isHFA(reflect.TypeOf(arrayed{})) { | |||
| 35 | + | t.Fatal("expected float array struct to be HFA") | |||
| 36 | + | } | |||
| 37 | + | } | |||