diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8257ce5..6dcae51 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,9 +2,9 @@ name: test on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] + branches: [main] jobs: example: @@ -43,3 +43,8 @@ jobs: for file in tests/*.c; do goat $file -O3 -mavx -mfma done + - name: Run amd64-only tests + run: | + for file in tests/amd64/*.c; do + goat $file -O3 -mavx -mfma + done diff --git a/parser_amd64.go b/parser_amd64.go index 7d92fe1..00a2b85 100644 --- a/parser_amd64.go +++ b/parser_amd64.go @@ -111,17 +111,22 @@ func parseAssembly(path string) (map[string][]Line, error) { } else if nameLine.MatchString(line) { functionName = strings.Split(line, ":")[0] functions[functionName] = make([]Line, 0) + labelName = "" } else if labelLine.MatchString(line) { labelName = strings.Split(line, ":")[0] labelName = labelName[1:] functions[functionName] = append(functions[functionName], Line{Label: labelName}) } else if codeLine.MatchString(line) { - asm := strings.Split(line, "#")[0] - asm = strings.TrimSpace(asm) + asm := sanitizeAsm(line) if labelName == "" { functions[functionName] = append(functions[functionName], Line{Assembly: asm}) } else { lines := functions[functionName] + if len(lines) == 0 { + functions[functionName] = append(functions[functionName], Line{Label: labelName}) + lines = functions[functionName] + } + lines[len(lines)-1].Assembly = asm labelName = "" } @@ -134,6 +139,14 @@ func parseAssembly(path string) (map[string][]Line, error) { return functions, nil } +func sanitizeAsm(asm string) string { + asm = strings.TrimSpace(asm) + asm = strings.Split(asm, "//")[0] + asm = strings.TrimSpace(asm) + + return asm +} + func parseObjectDump(dump string, functions map[string][]Line) error { var ( functionName string @@ -161,6 +174,12 @@ func parseObjectDump(dump string, functions map[string][]Line) error { } binary = append(binary, s) } + + assembly = sanitizeAsm(assembly) + if strings.Contains(assembly, "nop") { + continue + } + if assembly == "" { return fmt.Errorf("try to increase --insn-width of objdump") } else if strings.HasPrefix(assembly, "nop") || diff --git a/parser_arm64.go b/parser_arm64.go index ef50919..5427105 100644 --- a/parser_arm64.go +++ b/parser_arm64.go @@ -99,7 +99,9 @@ func parseAssembly(path string) (map[string][]Line, error) { functions[functionName] = append(functions[functionName], Line{Assembly: asm}) } else { lines := functions[functionName] - lines[len(lines)-1].Assembly = asm + if len(lines) > 0 { + lines[len(lines)-1].Assembly = asm + } labelName = "" } } diff --git a/tests/amd64/empty_line.c b/tests/amd64/empty_line.c new file mode 100644 index 0000000..fa753db --- /dev/null +++ b/tests/amd64/empty_line.c @@ -0,0 +1,39 @@ +#include + +void l2(float *a, float *b, float *res, long *len) +{ + int n = *len; + float sum = 0; + + __m256 acc[4]; + acc[0] = _mm256_setzero_ps(); + acc[1] = _mm256_setzero_ps(); + + while (n) + { + __m256 a_vec0 = _mm256_loadu_ps(a); + __m256 b_vec0 = _mm256_loadu_ps(b); + + __m256 diff0 = _mm256_sub_ps(a_vec0, b_vec0); + + acc[0] = _mm256_fmadd_ps(diff0, diff0, acc[0]); + + n--; + a++; + b++; + } + + acc[0] = _mm256_add_ps(acc[1], acc[0]); + if (*len >= 32) + { + acc[2] = _mm256_add_ps(acc[3], acc[2]); + acc[0] = _mm256_add_ps(acc[2], acc[0]); + } + + __m256 t1 = _mm256_hadd_ps(acc[0], acc[0]); + __m256 t2 = _mm256_hadd_ps(t1, t1); + __m128 t3 = _mm256_extractf128_ps(t2, 1); + __m128 t4 = _mm_add_ps(_mm256_castps256_ps128(t2), t3); + sum += _mm_cvtss_f32(t4); + *res = sum; +} diff --git a/tests/arm64/.gitkeep b/tests/arm64/.gitkeep new file mode 100644 index 0000000..e69de29