0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

RaspberryPiでGolang(cgo)でNEONを動かす

Posted at

RaspberryPiでGolang(cgo)でNEONを動かす

動機

raspberry pi コンピュータリソースの最大使用に向けて。

機材

Raspberry Pi4 4GB
go version go1.11.6 linux/arm
gcc version 8.3.0 (Raspbian 8.3.0-6+rpi1)

元プログラム

neonとかについてはこちらから

test1.cpp
  1 #include <iostream>
  2 #include <arm_neon.h>
  3 
  4 using namespace std;
  5 
  6 int main () {
  7 
  8   cout << "hoge" << endl;
  9 
 10   int array1[2] = {31, 22};
 11   int array2[2] = {11, 20};
 12   int arrayAns[2];
 13 
 14   int32x2_t v1, v2, vans;
 15   v1 = vld1_s32(array1);
 16   v2 = vld1_s32(array2);
 17   vans = vqadd_s32(v1, v2);
 18 
 19   vst1_s32(arrayAns, vans);
 20 
 21   cout << arrayAns[0] << ", " << arrayAns[1] << endl;    
 22 
 23   return 0;
 24 }
$ clang++ -o test1 test1.cpp -mfpu=neon -march=armv7-a -O3
$ ./test1
hoge
42, 42

Gonlang プログラム

main.go
package main

/*
#include <arm_neon.h>

int sum(int a, int b) {
	return a + b;
}

int sum4(int a, int b, int c, int d) {
	int array1[2] = {a, b};
	int array2[2] = {c, d};
	int arrayAns[2];

	int32x2_t v1, v2, vans;
	v1 = vld1_s32(array1);
	v2 = vld1_s32(array2);
	vans = vqadd_s32(v1, v2);

	vst1_s32(arrayAns, vans);

	return sum(vans[0], vans[1]);
}
*/
// #cgo CFLAGS: -mfpu=neon -march=armv7-a
import "C"

func  main() {
	println("HELLO", C.sum4(1, 2, 3, 4))
}

#cgo CFLAGS: -mfpu=neon -march=armv7-a
はコンパイルオプション(gccの)

$ go run main.go
HELLO 10
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?