From a022e13ade43c9bd2784c993a4a374f61bcf926c Mon Sep 17 00:00:00 2001 From: Asdine El Hrychy Date: Fri, 14 Jul 2023 15:36:39 +0200 Subject: [PATCH 1/6] fix: avoid panic on empty lines when parsing amd64 assembly --- parser_amd64.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/parser_amd64.go b/parser_amd64.go index faa7bca..c001067 100644 --- a/parser_amd64.go +++ b/parser_amd64.go @@ -122,7 +122,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 = "" } } From 20e7f614aa41952b4ac32e8d527bcf45d52b43a9 Mon Sep 17 00:00:00 2001 From: Asdine El Hrychy Date: Fri, 14 Jul 2023 15:38:08 +0200 Subject: [PATCH 2/6] fix: avoid panic on empty lines when parsing arm64 assembly --- parser_arm64.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/parser_arm64.go b/parser_arm64.go index d41f67d..ceb39f2 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 = "" } } From f1837e45372207a8df42f8e14d5f926daf2df08d Mon Sep 17 00:00:00 2001 From: Asdine El Hrychy Date: Tue, 18 Jul 2023 18:19:38 +0200 Subject: [PATCH 3/6] Add test for empty line --- tests/empty_line.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/empty_line.c diff --git a/tests/empty_line.c b/tests/empty_line.c new file mode 100644 index 0000000..42c618b --- /dev/null +++ b/tests/empty_line.c @@ -0,0 +1,41 @@ +#include + +#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; +} From 1e29e6bf52e532bc27bf96c77176224796d39918 Mon Sep 17 00:00:00 2001 From: Asdine El Hrychy Date: Tue, 18 Jul 2023 18:36:45 +0200 Subject: [PATCH 4/6] Add amd64-only tests --- .circleci/config.yml | 6 ++++++ .github/workflows/test.yml | 9 +++++++-- tests/{ => amd64}/empty_line.c | 2 -- tests/arm64/.gitkeep | 0 4 files changed, 13 insertions(+), 4 deletions(-) rename tests/{ => amd64}/empty_line.c (97%) create mode 100644 tests/arm64/.gitkeep diff --git a/.circleci/config.yml b/.circleci/config.yml index 8990036..a27b1d9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -21,6 +21,12 @@ jobs: for file in tests/*.c; do goat $file -O3 -mavx -mfma done + - run: + name: Run arm64-only tests + command: | + for file in tests/arm64/*.c; do + goat $file -O3 -mavx -mfma + done workflows: test: 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/tests/empty_line.c b/tests/amd64/empty_line.c similarity index 97% rename from tests/empty_line.c rename to tests/amd64/empty_line.c index 42c618b..fa753db 100644 --- a/tests/empty_line.c +++ b/tests/amd64/empty_line.c @@ -1,7 +1,5 @@ #include -#include - void l2(float *a, float *b, float *res, long *len) { int n = *len; diff --git a/tests/arm64/.gitkeep b/tests/arm64/.gitkeep new file mode 100644 index 0000000..e69de29 From 810bb7ba2abb98b7dc62eb2e3aca8bc54d84e358 Mon Sep 17 00:00:00 2001 From: Asdine El Hrychy Date: Fri, 5 Apr 2024 07:08:12 +0000 Subject: [PATCH 5/6] fix mismatched parsed and output lengths --- parser_amd64.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/parser_amd64.go b/parser_amd64.go index f6e6daa..00a2b85 100644 --- a/parser_amd64.go +++ b/parser_amd64.go @@ -111,20 +111,23 @@ 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 { - lines[len(lines)-1].Assembly = asm + if len(lines) == 0 { + functions[functionName] = append(functions[functionName], Line{Label: labelName}) + lines = functions[functionName] } + + lines[len(lines)-1].Assembly = asm labelName = "" } } @@ -136,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 @@ -163,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") || From 851fb6d1fbb2f3d04102ac66cce3762908f12dbe Mon Sep 17 00:00:00 2001 From: Asdine El Hrychy Date: Fri, 5 Apr 2024 07:11:37 +0000 Subject: [PATCH 6/6] remove arm64 job --- .circleci/config.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a27b1d9..8990036 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -21,12 +21,6 @@ jobs: for file in tests/*.c; do goat $file -O3 -mavx -mfma done - - run: - name: Run arm64-only tests - command: | - for file in tests/arm64/*.c; do - goat $file -O3 -mavx -mfma - done workflows: test: