fix(windows): capture scalar float returns - #65
Conversation
kolkov
left a comment
There was a problem hiding this comment.
Good find. We had this documented as a known limitation ("Go's syscall package on Windows only exposes RAX") — turns out syscall.SyscallN was already giving us XMM0 in the second return slot, we just weren't reading it.
The fix is minimal and correct:
floatRetcaptured fromsyscall.SyscallNsecond return- Selected only for
FloatType/DoubleType— integer/pointer paths unchanged - Old limitation comment and README entry removed (no longer applies)
The end-to-end test with real Windows DLL (structtest.dll) covers both float32 (0.125) and float64 (0.625) with a pointer argument — same call shape as native APIs like wgpuQueueGetTimestampPeriod.
LGTM.
kolkov
left a comment
There was a problem hiding this comment.
Clean fix for a long-standing known issue (TASK-019). The XMM0 bits were already in SyscallN's second return — we just weren't reading them. E2E test on real DLL, no regressions. LGTM.
|
Released as goffi v0.6.2. This closes a limitation that was open since v0.4.1 — nice catch that webgpu#23 can now bump to v0.6.2. Side note: you're now in goffi CODEOWNERS for Android paths (v0.6.1). We plan the same for wgpu |
Summary
float32/float64returns from the raw XMM0 bits exposed assyscall.SyscallN's second resultWhy
This is the bounded goffi-side fix for the Windows correctness blocker @kolkov found while reviewing go-webgpu/webgpu#23.
It does not require another custom assembly trampoline. Go's Windows AMD64
asmstdcalldeliberately copies XMM0 intoSyscallN's second return slot; goffi was already receiving that value and discarding it. Selecting that slot only for scalar float return types keeps integer/pointer behavior unchanged.Verification
go test -count=1 ./ffi ./typesGOOS=windows GOARCH=amd64 CGO_ENABLED=0 go test -count=1 -run '^$' -exec=true ./...GOOS=windows GOARCH=amd64 CGO_ENABLED=1 go test -count=1 -run '^$' -exec=true ./...TestWindowsAMD64ScalarFloatReturnsagainst the generated DLL, rather than only cross-compiling itThis should let webgpu consume the next canonical goffi release and keep
Queue.GetTimestampPeriodcorrect without a fork or Windows-only fallback.