add vlang binding (#67)
This commit is contained in:
parent
00eef8352f
commit
b42485d56e
38
README.md
38
README.md
@ -331,6 +331,44 @@ main = do
|
||||
</td></tr>
|
||||
</table>
|
||||
|
||||
### ruapu with Vlang
|
||||
|
||||
<table>
|
||||
|
||||
|
||||
<tr><td>
|
||||
|
||||
Compile ruapu library
|
||||
|
||||
```shell
|
||||
cd vlang
|
||||
v .
|
||||
```
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
Use ruapu in Vlang
|
||||
|
||||
```go
|
||||
module main
|
||||
|
||||
import ruapu
|
||||
|
||||
fn main() {
|
||||
ruapu.ruapu_init()
|
||||
mut avx2_status := ruapu.ruapu_supports('avx2')
|
||||
if avx2_status {
|
||||
println('avx2: ' + avx2_status.str())
|
||||
}
|
||||
|
||||
println(ruapu.ruapu_rua())
|
||||
}
|
||||
```
|
||||
|
||||
</td></tr>
|
||||
</table>
|
||||
|
||||
<details>
|
||||
<summary>Github-hosted runner result (Linux)</summary>
|
||||
|
||||
|
13
vlang/ruapu.v
Normal file
13
vlang/ruapu.v
Normal file
@ -0,0 +1,13 @@
|
||||
module main
|
||||
|
||||
import ruapu
|
||||
|
||||
fn main() {
|
||||
ruapu.ruapu_init()
|
||||
mut avx2_status := ruapu.ruapu_supports('avx2')
|
||||
if avx2_status {
|
||||
println('avx2: ' + avx2_status.str())
|
||||
}
|
||||
|
||||
println(ruapu.ruapu_rua())
|
||||
}
|
33
vlang/ruapu/wrapper.c.v
Normal file
33
vlang/ruapu/wrapper.c.v
Normal file
@ -0,0 +1,33 @@
|
||||
module ruapu
|
||||
|
||||
#flag -I @VMODROOT/../
|
||||
#flag -D RUAPU_IMPLEMENTATION
|
||||
#include "ruapu.h"
|
||||
|
||||
fn C.ruapu_init()
|
||||
|
||||
fn C.ruapu_supports(&char) int
|
||||
|
||||
fn C.ruapu_rua() &&char
|
||||
|
||||
pub fn ruapu_init() {
|
||||
C.ruapu_init()
|
||||
}
|
||||
|
||||
pub fn ruapu_supports(isa string) bool {
|
||||
return C.ruapu_supports(unsafe { isa.str }) == 1
|
||||
}
|
||||
|
||||
pub fn ruapu_rua() []string {
|
||||
mut cstr_array := C.ruapu_rua()
|
||||
mut v_strings := []string{}
|
||||
|
||||
unsafe {
|
||||
for i := 0; cstr_array[i] != 0; i++ {
|
||||
str := cstring_to_vstring(cstr_array[i])
|
||||
v_strings << str
|
||||
}
|
||||
}
|
||||
|
||||
return v_strings
|
||||
}
|
5
vlang/v.mod
Normal file
5
vlang/v.mod
Normal file
@ -0,0 +1,5 @@
|
||||
Module {
|
||||
name: 'ruapu',
|
||||
description: 'Detect CPU ISA features with single-file.',
|
||||
dependencies: []
|
||||
}
|
Loading…
Reference in New Issue
Block a user