purego: refactor struct_amd64.go (#212)
- commit
- 07899564f3c44b9b4f56b58d3a40e9711963e2b4
- author
- Hajime Hoshi · · 2024-02-20 13:46 UTC
- committer
- GitHub · · 2024-02-20 13:46 UTC
- parent
- 29473c6
- signature
- GPG Unverified
B5690EEEBB952194The key is unknown - refs
- tag: v0.7.0-alpha.1
1 file · +6 -5
M struct_amd64.go +6 -5
| @@ -76,7 +76,10 @@ func tryPlaceRegister(v reflect.Value, addFloat func(uintptr), addInt func(uintp | |||
| 76 | 76 | var shift byte // # of bits to shift | |
| 77 | 77 | var flushed bool | |
| 78 | 78 | class := _NO_CLASS | |
| 79 | - | flush := func() { | |
| 79 | + | flushIfNeeded := func() { | |
| 80 | + | if flushed { | |
| 81 | + | return | |
| 82 | + | } | |
| 80 | 83 | flushed = true | |
| 81 | 84 | if class == _SSE { | |
| 82 | 85 | addFloat(uintptr(val)) | |
| @@ -167,7 +170,7 @@ func tryPlaceRegister(v reflect.Value, addFloat func(uintptr), addInt func(uintp | |||
| 167 | 170 | } | |
| 168 | 171 | ||
| 169 | 172 | if shift == 64 { | |
| 170 | - | flush() | |
| 173 | + | flushIfNeeded() | |
| 171 | 174 | } else if shift > 64 { | |
| 172 | 175 | // Should never happen, but may if we forget to reset shift after flush (or forget to flush), | |
| 173 | 176 | // better fall apart here, than corrupt arguments. | |
| @@ -177,9 +180,7 @@ func tryPlaceRegister(v reflect.Value, addFloat func(uintptr), addInt func(uintp | |||
| 177 | 180 | } | |
| 178 | 181 | ||
| 179 | 182 | place(v) | |
| 180 | - | if !flushed { | |
| 181 | - | flush() | |
| 182 | - | } | |
| 183 | + | flushIfNeeded() | |
| 183 | 184 | return ok | |
| 184 | 185 | } | |
| 185 | 186 | ||
| @@ -76,7 +76,10 @@ func tryPlaceRegister(v reflect.Value, addFloat func(uintptr), addInt func(uintp | |||||
| 76 | var shift byte // # of bits to shift | 76 | var shift byte // # of bits to shift | ||
| 77 | var flushed bool | 77 | var flushed bool | ||
| 78 | class := _NO_CLASS | 78 | class := _NO_CLASS | ||
| 79 | - | flush := func() { | 79 | + | flushIfNeeded := func() { |
| 80 | + | if flushed { | |||
| 81 | + | return | |||
| 82 | + | } | |||
| 80 | flushed = true | 83 | flushed = true | ||
| 81 | if class == _SSE { | 84 | if class == _SSE { | ||
| 82 | addFloat(uintptr(val)) | 85 | addFloat(uintptr(val)) | ||
| @@ -167,7 +170,7 @@ func tryPlaceRegister(v reflect.Value, addFloat func(uintptr), addInt func(uintp | |||||
| 167 | } | 170 | } | ||
| 168 | 171 | ||||
| 169 | if shift == 64 { | 172 | if shift == 64 { | ||
| 170 | - | flush() | 173 | + | flushIfNeeded() |
| 171 | } else if shift > 64 { | 174 | } else if shift > 64 { | ||
| 172 | // Should never happen, but may if we forget to reset shift after flush (or forget to flush), | 175 | // Should never happen, but may if we forget to reset shift after flush (or forget to flush), | ||
| 173 | // better fall apart here, than corrupt arguments. | 176 | // better fall apart here, than corrupt arguments. | ||
| @@ -177,9 +180,7 @@ func tryPlaceRegister(v reflect.Value, addFloat func(uintptr), addInt func(uintp | |||||
| 177 | } | 180 | } | ||
| 178 | 181 | ||||
| 179 | place(v) | 182 | place(v) | ||
| 180 | - | if !flushed { | 183 | + | flushIfNeeded() |
| 181 | - | flush() | |||
| 182 | - | } | |||
| 183 | return ok | 184 | return ok | ||
| 184 | } | 185 | } | ||
| 185 | 186 | ||||