-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: test | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
example: | ||
name: example | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-go@v4 | ||
- name: Install clang | ||
uses: ConorMacBride/install-package@v1 | ||
with: | ||
apt: clang libc6-dev-i386 | ||
- name: Install GOAT | ||
run: go install . | ||
- name: Run GOAT | ||
run: goat src/avx_mul_to.c -O3 -mavx -mfma | ||
working-directory: example | ||
- name: Run tests | ||
run: go test -v ./... | ||
working-directory: example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package example | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
"unsafe" | ||
) | ||
|
||
func AVXMulTo(a, b, c []float32) { | ||
if len(a) != len(b) || len(a) != len(c) { | ||
panic("floats: slice lengths do not match") | ||
} | ||
avx_mul_to(unsafe.Pointer(&a[0]), unsafe.Pointer(&b[0]), unsafe.Pointer(&c[0]), unsafe.Pointer(uintptr(len(a)))) | ||
} | ||
|
||
func TestAVXMulTo(t *testing.T) { | ||
a := []float32{1, 2, 3, 4} | ||
b := []float32{5, 6, 7, 8} | ||
c := make([]float32, len(a)) | ||
AVXMulTo(a, b, c) | ||
if !reflect.DeepEqual(c, []float32{5, 12, 21, 32}) { | ||
t.Errorf("AVXMulTo(%v, %v, %v) = %v, want %v", a, b, c, c, []float32{5, 12, 21, 32}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <immintrin.h> | ||
#include <stdint.h> | ||
|
||
void avx_mul_to(float *a, float *b, float *c, int64_t n) | ||
{ | ||
int epoch = n / 8; | ||
int remain = n % 8; | ||
for (int i = 0; i < epoch; i++) | ||
{ | ||
__m256 v1 = _mm256_loadu_ps(a); | ||
__m256 v2 = _mm256_loadu_ps(b); | ||
__m256 v = _mm256_mul_ps(v1, v2); | ||
_mm256_storeu_ps(c, v); | ||
a += 8; | ||
b += 8; | ||
c += 8; | ||
} | ||
for (int i = 0; i < remain; i++) | ||
{ | ||
c[i] = a[i] * b[i]; | ||
} | ||
} |