Received: from eggs.gnu.org ([2001:4830:134:3::10]:47208) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d91ND-0006U2-0A for qemu-devel@nongnu.org; Thu, 11 May 2017 23:36:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d91NB-0003bN-Tp for qemu-devel@nongnu.org; Thu, 11 May 2017 23:36:11 -0400 Received: from mail-qk0-x243.google.com ([2607:f8b0:400d:c09::243]:35783) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d91NB-0003bE-Pl for qemu-devel@nongnu.org; Thu, 11 May 2017 23:36:09 -0400 Received: by mail-qk0-x243.google.com with SMTP id k74so6323280qke.2 for ; Thu, 11 May 2017 20:36:09 -0700 (PDT) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Fri, 12 May 2017 00:35:39 -0300 Message-Id: <20170512033543.6789-2-f4bug@amsat.org> In-Reply-To: <20170512033543.6789-1-f4bug@amsat.org> References: <20170512033543.6789-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [RFC PATCH v3 1/5] coccinelle: add a script to optimize tcg op using tcg_gen_extract() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Aurelien Jarno , Richard Henderson , Nikunj A Dadhania , Eric Blake , Markus Armbruster , Laurent Vivier , Michael Tokarev , Eduardo Habkost , Paolo Bonzini Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Elfring , Julia Lawall , Nicolas Palix If you have coccinelle installed you can apply this script using: $ spatch \ --macro-file scripts/cocci-macro-file.h \ --dir target --in-place You can also use directly Peter Senna Tschudin docker image (easier): $ docker run -v `pwd`:`pwd` -w `pwd` petersenna/coccinelle \ --sp-file scripts/coccinelle/tcg_gen_extract.cocci \ --macro-file scripts/cocci-macro-file.h \ --dir target --in-place Then verified that no manual touchups are required. The following thread was helpful while writing this script: https://github.com/coccinelle/coccinelle/issues/86 Signed-off-by: Philippe Mathieu-Daudé --- scripts/coccinelle/tcg_gen_extract.cocci | 71 ++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 scripts/coccinelle/tcg_gen_extract.cocci diff --git a/scripts/coccinelle/tcg_gen_extract.cocci b/scripts/coccinelle/tcg_gen_extract.cocci new file mode 100644 index 0000000000..4823073005 --- /dev/null +++ b/scripts/coccinelle/tcg_gen_extract.cocci @@ -0,0 +1,71 @@ +// optimize TCG using extract op +// +// Copyright: (C) 2017 Philippe Mathieu-Daudé. GPLv2+. +// Confidence: High +// Options: --macro-file scripts/cocci-macro-file.h +// +// Nikunj A Dadhania optimization: +// http://lists.nongnu.org/archive/html/qemu-devel/2017-02/msg05211.html +// Aurelien Jarno optimization: +// http://lists.nongnu.org/archive/html/qemu-devel/2017-05/msg01466.html +// Coccinelle helpful issue: +// https://github.com/coccinelle/coccinelle/issues/86 + +@match@ // match shri*+andi* pattern, calls script verify_len +identifier ret, arg; +constant ofs, len; +identifier shr_fn =~ "^tcg_gen_shri_"; +identifier and_fn =~ "^tcg_gen_andi_"; +position shr_p; +position and_p; +@@ +( +shr_fn@shr_p(ret, arg, ofs); +and_fn@and_p(ret, ret, len); +) + +@script:python verify_len@ +ret_s << match.ret; +len_s << match.len; +shr_s << match.shr_fn; +and_s << match.and_fn; +shr_p << match.shr_p; +extract_fn; +@@ +print "candidate at %s:%s" % (shr_p[0].file, shr_p[0].line) +len_fn=len("tcg_gen_shri_") +shr_sz=shr_s[len_fn:] +and_sz=and_s[len_fn:] +# TODO: op_size shr