From patchwork Fri May 12 03:35:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 761429 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wPFyZ5sW9z9s8V for ; Fri, 12 May 2017 13:36:54 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="sCc0hLbY"; dkim-atps=neutral Received: from localhost ([::1]:51149 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d91Nr-0006Ve-F2 for incoming@patchwork.ozlabs.org; Thu, 11 May 2017 23:36:51 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HiaPev6/xKPbNKgmODGn0D/jCcJnrxxJojbY1WdUb9g=; b=sCc0hLbYnify9l1DB6GXtiBZ8lYAThY4rYOIWyTurQLHd41xov3asL3MgqdEbsx3Yk uomrii/9cjsNnJBtvwqlOQM+54JszVBb7b8K8i/yIWP/9xEv64Eh73MNevvNkn5+6OEs 2MtcAZgXwgPkNTgiAWGZmZqZmFGY447SsXHUN2GFrMDkQEK8NdWYuf1Pm75kSAt8Z567 DJRYmq5EKPmGTmmE770Or3KniGElz53iTdVHrK+v4hbcms87PFw26o208OPuwWiUAnp8 SUfq3lznlm1DmQ6vLypUJwg/UWQkSo5B6YmU2AW/zoyLhSxQea4UHS9qsvrUNNins74w Kjdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=HiaPev6/xKPbNKgmODGn0D/jCcJnrxxJojbY1WdUb9g=; b=GQad1kQBta5IV85ZsMynh68M5Seq5li91nCJF0daLc2FGQ+Fj3DhNMYdZVSrZvQc+q K/rwMMQE2HM6HdwnZPCVHxaujaG3F/d/HD/Ir9jUQ7K+w6oY9qBRDqqIiXvnYfKX6Ehk Yx+295mFYaRyJ4m3DnweZ7CedMeOB1EAQvWOVyMd2SsqoT4li0xjHhzKWs4779WtJ27d Cb0XR5b1cFx1gvQavN1t0eOhFRooXF8J4icr79JeAIDMQVHwnLNXE3grenmJb0Qd4P1Q BQwOgf2ZZzGVaPxfSL3u8VXERxnxKw/+w7LY7fEtacPMZ7P2RwkNrB1okQf/OTmhomHw lFlg== X-Gm-Message-State: AODbwcDCIokEPCQZvDPIZ9KVSvIDKsG3eQ7pVTl8+cbOALItvFtA4UAj Q7fliGCz4X3C8w== X-Received: by 10.55.134.2 with SMTP id i2mr1662567qkd.43.1494560169208; Thu, 11 May 2017 20:36:09 -0700 (PDT) Received: from localhost.localdomain ([138.117.48.226]) by smtp.gmail.com with ESMTPSA id m188sm1443267qkc.5.2017.05.11.20.36.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 May 2017 20:36:08 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Aurelien Jarno , Richard Henderson , Nikunj A Dadhania , Eric Blake , Markus Armbruster , Laurent Vivier , Michael Tokarev , Eduardo Habkost , Paolo Bonzini Date: Fri, 12 May 2017 00:35:39 -0300 Message-Id: <20170512033543.6789-2-f4bug@amsat.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170512033543.6789-1-f4bug@amsat.org> References: <20170512033543.6789-1-f4bug@amsat.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::243 Subject: [Qemu-devel] [RFC PATCH v3 1/5] coccinelle: add a script to optimize tcg op using tcg_gen_extract() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Julia Lawall , Nicolas Palix , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Elfring Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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