add go support (#59)
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"ruapu-go/ruapu"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ruapu.Init()
|
||||
avx2Status := ruapu.Supports("avx2")
|
||||
fmt.Println("avx2:" + strconv.Itoa(avx2Status))
|
||||
rua := ruapu.Rua()
|
||||
fmt.Println(rua)
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package ruapu
|
||||
|
||||
/*
|
||||
#cgo CFLAGS: -I ../../
|
||||
#define RUAPU_IMPLEMENTATION
|
||||
#include "ruapu.h"
|
||||
#include "stdlib.h"
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func Init() {
|
||||
C.ruapu_init()
|
||||
}
|
||||
|
||||
func Supports(isa string) int {
|
||||
ptr := C.CString(isa)
|
||||
defer C.free(unsafe.Pointer(ptr))
|
||||
result := int(C.ruapu_supports(ptr))
|
||||
return result
|
||||
}
|
||||
|
||||
func Rua() []string {
|
||||
p := unsafe.Pointer(C.ruapu_rua())
|
||||
s := make([]string, 0, 1)
|
||||
for i := 0; ; i++ {
|
||||
q := *(*unsafe.Pointer)(unsafe.Pointer(uintptr(p) + uintptr(i)*unsafe.Sizeof(p)))
|
||||
if q == nil {
|
||||
break
|
||||
}
|
||||
s = append(s, C.GoString((*C.char)(q)))
|
||||
}
|
||||
return s
|
||||
}
|
||||
Reference in New Issue
Block a user