Skip to content

Commit

Permalink
use if instead of switch
Browse files Browse the repository at this point in the history
  • Loading branch information
TotallyGamerJet committed Feb 25, 2024
1 parent 2751470 commit 5103bb8
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions struct_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import (

func getStruct(outType reflect.Type, syscall syscall15Args) (v reflect.Value) {
outSize := outType.Size()
switch {
case outSize == 0:
if outSize == 0 {
return reflect.New(outType).Elem()
case outSize <= 8:
} else if outSize <= 8 {
if isAllSameFloat(outType) {
if outType.NumField() == 2 {
return reflect.NewAt(outType, unsafe.Pointer(&struct{ a uintptr }{syscall.f2<<32 | syscall.f1})).Elem()
Expand All @@ -24,7 +23,7 @@ func getStruct(outType reflect.Type, syscall syscall15Args) (v reflect.Value) {
} else {
return reflect.NewAt(outType, unsafe.Pointer(&struct{ a uintptr }{syscall.a1})).Elem()
}
case outSize <= 16:
} else if outSize <= 16 {
r1, r2 := syscall.a1, syscall.a2
if isAllSameFloat(outType) {
switch outType.NumField() {
Expand All @@ -42,7 +41,7 @@ func getStruct(outType reflect.Type, syscall syscall15Args) (v reflect.Value) {
}
}
return reflect.NewAt(outType, unsafe.Pointer(&struct{ a, b uintptr }{r1, r2})).Elem()
default:
} else {
if isAllSameFloat(outType) && outType.NumField() <= 4 {
switch outType.NumField() {
case 4:
Expand All @@ -58,7 +57,6 @@ func getStruct(outType reflect.Type, syscall syscall15Args) (v reflect.Value) {
return reflect.NewAt(outType, *(*unsafe.Pointer)(unsafe.Pointer(&syscall.arm64_r8))).Elem()
}
}
return v
}

// https://github.com/ARM-software/abi-aa/blob/main/sysvabi64/sysvabi64.rst
Expand Down

0 comments on commit 5103bb8

Please sign in to comment.