From aed0611fb8bacef429fdc50725c24c5226484351 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 2 Feb 2024 06:16:33 +0530 Subject: [PATCH] Avoid double trailing RET --- tools/simdstring/generate.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/simdstring/generate.go b/tools/simdstring/generate.go index fdbd2bf80..5ecca2b60 100644 --- a/tools/simdstring/generate.go +++ b/tools/simdstring/generate.go @@ -1052,7 +1052,21 @@ func (s *Function) OutputASM(w io.Writer) { fmt.Fprintln(w, "\tVZEROUPPER // zero upper bits of AVX registers to avoid dependencies when switching between SSE and AVX code") } - s.Return() + has_trailing_return := false + for _, i := range s.Instructions { + if len(i) == 0 { + continue + } + if strings.HasPrefix(i, "\tRET ") { + has_trailing_return = true + } else { + has_trailing_return = false + } + } + + if !has_trailing_return { + s.Return() + } for _, i := range s.Instructions { fmt.Fprintln(w, i) }