From nobody Wed May 1 09:38:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1494460399938660.2939705024593; Wed, 10 May 2017 16:53:19 -0700 (PDT) Received: from localhost ([::1]:45221 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8bPx-0000hM-Ok for importer@patchew.org; Wed, 10 May 2017 19:53:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52330) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8bP8-0000Ix-U6 for qemu-devel@nongnu.org; Wed, 10 May 2017 19:52:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8bP5-0007y3-1v for qemu-devel@nongnu.org; Wed, 10 May 2017 19:52:27 -0400 Received: from mail-qt0-x22a.google.com ([2607:f8b0:400d:c0d::22a]:33412) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d8bP4-0007xo-SS for qemu-devel@nongnu.org; Wed, 10 May 2017 19:52:22 -0400 Received: by mail-qt0-x22a.google.com with SMTP id t26so5392724qtg.0 for ; Wed, 10 May 2017 16:52:22 -0700 (PDT) Received: from localhost.localdomain ([138.117.48.226]) by smtp.gmail.com with ESMTPSA id y17sm43379qtc.29.2017.05.10.16.52.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 May 2017 16:52:21 -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=vfd9rfeY+s8IkT7Q2uGUVyIdEf43c1t7ko/DqrU8qH4=; b=ldpx//At5gQxeMjIueRWxOhzxKSXI9up5ZvQIy/WuEoL1GJnRJyiy05gwlEzhU1IBk G/wa27QyKwPIyD+C2/+/ajVHxqCyJaytCibZGsufu9I24JfPggQWExQ8qLRddK0/0Zmm bULr9uB9VSw5J6e3Aiv+iAolKg8QKc5aiCDWcXKm5Ds3KaTy6bmjylw+uJP1hZNxhcAh m/yv8CQErzHFRtu8Z6UsQItQT/HaXtQriypt5GUhgHw+Z7hPQG2PwkmbgBv8B1DpisES ayBK8a53X6WqrVmzS0Lp/Ijkh874Z1EAs9hSIFeyIJGFmMpMK1pw6fVdlcMxS5IvzAjB +znw== 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=vfd9rfeY+s8IkT7Q2uGUVyIdEf43c1t7ko/DqrU8qH4=; b=lqxLRkPCBX6cAsaymeg6KiNB3e1Sx8qxJUJtfFT/emFXre/mTH+hPtl2RDrhJZSww3 F+Ib/bBoLw684ujmng2kdKMH6YF3exoAmHmK7qjBtM+u4pN6eF9xgYeLdgtNYkx49kd2 sIjBiy9aYsC8/vsaj80Pg20iVUawX69N0mBiu+lNZke/SkYJOizGZAtQ5l/A7xic9u+k LZNJYyn30Wz05HrU5PCxgn/JwazYje9azGyxtuK6s8uZnuzVQusN+CriO/Rxrl4wDGRg o4sKvnCaTY7Jy70AMop+7Kt7YmgbRgj9+rdJLq1tGcg7NP4+J0IY9mvVzPNLG7fY92Ka aPIg== X-Gm-Message-State: AODbwcClXnL9uPGNSD01YGTpY4puZh7J9r882XuZSRhNjv+s/5eraOs1 5lFGK6mxVKkxmw== X-Received: by 10.200.34.242 with SMTP id g47mr1142215qta.109.1494460342208; Wed, 10 May 2017 16:52:22 -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: Wed, 10 May 2017 20:52:04 -0300 Message-Id: <20170510235204.9657-1-f4bug@amsat.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <0f1f5bcd-815a-c070-5ba7-281f5a0ee146@twiddle.net> References: <0f1f5bcd-815a-c070-5ba7-281f5a0ee146@twiddle.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::22a Subject: [Qemu-devel] [RFC PATCH v2] 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: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Apply this script using: $ 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 Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- This is a new version of the coccinelle script addressing Richard comments = and trying to do it correctly. Also changed license to GPLv2+. The first rule matches, it calls a python2 script that basically checks the target_ulong is not overflowed: (msk << ofs) >> sizeof(target_ulong) =3D=3D= 0=20 I think this is enough but if I'm wrong I can try to do as Richard suggested (counting the low bits). If this rule fails, there is no further processing, else the 3rd rule doing= the patch is called. I couldn't figure still how to reuse args from rule2 in rule3 so it is most= ly a copy of rule1. I also don't know yet how to process target-generic functions (ending _tl instead of _32 or _64) eventually the correct --include-option may resolve = this. Applied it verified the ARM/M68K/PPC patches (2,3,5,7 from serie v1). The other archs weren't patched since they use _tl generic functions. I apologize for my python! Regards, Phil. scripts/coccinelle/tcg_gen_extract.cocci | 61 ++++++++++++++++++++++++++++= ++++ 1 file changed, 61 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..d75ef7d98c --- /dev/null +++ b/scripts/coccinelle/tcg_gen_extract.cocci @@ -0,0 +1,61 @@ +// optimize TCG using extract op +// +// Copyright: (C) 2017 Philippe Mathieu-Daud=C3=A9. GPLv2+. +// Confidence: Low +// Options: --macro-file scripts/cocci-macro-file.h + +@match@ // match shri*+andi* pattern, calls script check_len_correct +identifier ret, arg; +constant ofs, len; +identifier tcg_gen_shri =3D~ "^tcg_gen_shri_"; +identifier tcg_gen_andi =3D~ "^tcg_gen_andi_"; +position p; +@@ +( +tcg_gen_shri(ret, arg, ofs); +tcg_gen_andi(ret, ret, len);@p +) + +@script:python check_len_correct@ +ret_s << match.ret; +arg_s << match.arg; +ofs_s << match.ofs; +msk_s << match.len; +shr_s << match.tcg_gen_shri; +and_s << match.tcg_gen_andi; +@@ +try: + # only eval integer, no #define like 'SR_M' + ofs =3D long(ofs_s, 0) + msk =3D long(msk_s, 0) + # get op_size: 32/64 + shr_sz =3D int(shr_s[-2:]) + and_sz =3D int(and_s[-2:]) + # op_size shr and_sz or (msk << ofs) >> and_sz: + cocci.include_match(False) # no further process +except ValueError: # op_size: "tl" not handled yet + cocci.include_match(False) # no further process + +@use_extract depends on check_len_correct@ // ofs/len are valid, we can re= place +identifier ret, arg; +constant ofs, len; +@@ +( +// from Nikunj A Dadhania comment: +// http://lists.nongnu.org/archive/html/qemu-devel/2017-02/msg05211.html +-tcg_gen_shri_tl(ret, arg, ofs); +-tcg_gen_andi_tl(ret, ret, len); ++tcg_gen_extract_tl(ret, arg, ofs, len); +| +// from Aurelien Jarno comment: +// http://lists.nongnu.org/archive/html/qemu-devel/2017-05/msg01466.html +-tcg_gen_shri_i32(ret, arg, ofs); +-tcg_gen_andi_i32(ret, ret, len); ++tcg_gen_extract_i32(ret, arg, ofs, len); +| +-tcg_gen_shri_i64(ret, arg, ofs); +-tcg_gen_andi_i64(ret, ret, len); ++tcg_gen_extract_i64(ret, arg, ofs, len); +) --=20 2.11.0