Closed mrd0ll4r closed 7 years ago
You need to pass in unsafe.Pointer(&s[0])
-- you are now getting the pointer to the slice struct, and not the data itself
But s
is a [2]uint64
, not a []uint64
?
(Also I just tried it and it doesn't work.)
Thanks for the quick reply still!
EDIT: I also just tried to have the C function accept a pointer to the value to be returned, instead of actually returning the value, still nothing...
Was too quick, I see what is wrong (has to do with C vs C++ name mangling), will create a fix for this.
The C++ name mangling parsing errored out which takes the form of eg. _ZN4Simd4Avx213Yuv444pToBgraEPKhmS2_mS2_mmmPhmh
where the digits contain the length of the next part.
In this case it was a plain style C name (XORShift128Plus
) that happened to contain the 128 digits which threw the parsing off... 😄
For your reference here is the accompanying Go code (note that in line 7 the return parameter is also named: (result uint64)
):
package main
import "unsafe"
import "fmt"
//go:noescape
func _XORShift128Plus(s unsafe.Pointer) (result uint64)
func XORShift128Plus(s [2]uint64) uint64 {
return _XORShift128Plus(unsafe.Pointer(&s))
}
func main() {
test := [2]uint64{}
test[0] = 1
test[1] = 2
fmt.Println(XORShift128Plus(test))
}
Also make sure you move out the xor128plus.s
file before you go build
because otherwise go will try to include this as well.
This sounded like a cool project, so I tried it out!
go env
:C: (
xor128plus.c
)Compiling this with
yields (
xor128plus.s
):Accompanied by
xor128plusg_amd64.go
:And finally running
c2goasm -a -f xor128plus.s xor128plus_amd64.s
yields: