From patchwork Wed Jan 18 01:11:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 643663 Delivered-To: patch@linaro.org Received: by 2002:a17:522:b9de:b0:4b9:b062:db3b with SMTP id fj30csp1489526pvb; Tue, 17 Jan 2023 17:12:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXsQbpr8oCVThkicobGDb2W4f6dPha4ahDFlF9esVYrz9Nwk3JRcaaaAySq3dK5+CJX+z5us X-Received: by 2002:ac8:754f:0:b0:3b6:2ed3:9de3 with SMTP id b15-20020ac8754f000000b003b62ed39de3mr6154173qtr.17.1674004329475; Tue, 17 Jan 2023 17:12:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674004329; cv=none; d=google.com; s=arc-20160816; b=JUpBHcYDgi3Oe8Nl/kDeJ2ifTIITCBbW6jMepR0KNa0vJ2cmGURsUBw7Y8xSXMtHl0 LoIlcxw06+1yOrY0pEy5aTJYliMXLKUY7NMpvc/UXkY52adnYx9v2kDaC8l0V9ETE/Hs NtYEBvggWfgbvSQ6vRwP2eWm8D+vrHoymSE0k/Da2pwQzE4z/ysFK80UD5Bd6z71d8mP nHO04GPrPo7zRLa5L8AJgj9zGEBJPR/ywRhdahXRkDFoNTI3Q1KOLz39y7Wm+43yPECD FPEGxfYBgHmQh/mxnYRB1VgKw5RPhCGuqrShIrov/iBinfDrgOT7Y7yvGgK/6LjnN6Rt wHdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qJICZPpEEH1YcFNc4HKSAZHC1I0j/ycDAOKP1+ciRvM=; b=ed1yn13jsgt0Wybf476AlViC7Z27dSZ15r+9WB5NmiR9TTlRya3+RLZUjn12ppLj4z APvGoG1wdUf33J+9M10wimAwauAS/ZE57/Ua4Y5S7TSOQBsSEoIfEer90m+orfyxJkUx p6Tp0e5xkKFLBGRdWNzrQplSQUB60pNujR6oOcdUdM427XSz9ZTaAiv78hDmuva39JfI 7+VdMwVHe+rpgdg0I4Q8uwPQc8Z9kvxF6ZZTZqK4fFLTxGv3KbSTbVL01UU1Gt440qzi E8KEpbs1dnLWFZSsGXeUN51ejxj+cvsTvNEWOA+JPueMztqLdeAuHatFSRV/XJ9Z2Hvb MI9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZDdSPp1l; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g19-20020ac870d3000000b003b631753228si3591969qtp.282.2023.01.17.17.12.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Jan 2023 17:12:09 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZDdSPp1l; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHwzF-0001zp-Qm; Tue, 17 Jan 2023 20:11:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pHwzD-0001yM-KL for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:31 -0500 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHwzC-0002E7-1J for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:31 -0500 Received: by mail-pl1-x629.google.com with SMTP id b17so27832080pld.7 for ; Tue, 17 Jan 2023 17:11:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qJICZPpEEH1YcFNc4HKSAZHC1I0j/ycDAOKP1+ciRvM=; b=ZDdSPp1lvFUT3nkatBK0VpJ036GL0DmupgGx9xVzbbAe4BFuCTfJr1iCQFUztPIzD8 Ez7HPemwTiwpX/3CE1+EAhzHsz5vovEXGDUu1ohEHGLBoI/8+EU8TIDwbNY84owiOm7v AHDNihsIBx3muvavpx6eUTpN1ptf9oA3uzgKVJ2QvWXr28f4r98dVzCHRWhkpqafXNP6 IZ209/ysTYTeELxYS1EEsUHLUaHtJNktTaJ4rcxeiHgwLrjaEyy4iPRgEl+qm+CyHC4S ncn5LXloorspmhmLbiZ9QiwpmIsGcJWErNozo/pRpiCIUOMwoVpQaReFGa3z7gvdRufh eWUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qJICZPpEEH1YcFNc4HKSAZHC1I0j/ycDAOKP1+ciRvM=; b=pH0gu7NCZ9yW0yokrwfWbXVq5jR7/TAycbiA4fBj8UNgRWaji7zNxeGZ++FLW3rk+i mqnWe3AO85fF3IULTjmnawPCGVFGOLqJ3Oibi5Y7OVnFjG2Vf319Gv3OtHEAO3+JnjnP Pvf2Ac0HqQ78Y5euSWS21i64j9a02RiOgu0WiEgfBBMugzpmCe0vezdEzq9Sv56JFtSy ktjTk5oYusgd+pebSyEmtdLtR1iw5Cj5ulsSAXUeyz9D3hQ9lRPrQJJ0dek67eeVSSmm 5gqFvItX50ac5ZgrwjAslI96ZHKqOn2bJK1jmQqhDTFMxXgSjqKRKO807c1sFXDcNULA 8HVw== X-Gm-Message-State: AFqh2kq5v50n5pPxgVsDu+ewdkXlvo1kOOAYRa0OT0KZSTMC3M0wr6bi wHWMNV69s1YNEZUoTeTZJ97e+VpQfZZ1XASI X-Received: by 2002:a17:902:ce08:b0:193:3594:82e4 with SMTP id k8-20020a170902ce0800b00193359482e4mr6337015plg.18.1674004288619; Tue, 17 Jan 2023 17:11:28 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b0017ec1b1bf9fsm21660259plp.217.2023.01.17.17.11.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 17:11:28 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name Subject: [PATCH v2 01/10] target/loongarch: Enable the disassembler for host tcg Date: Tue, 17 Jan 2023 15:11:14 -1000 Message-Id: <20230118011123.392823-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118011123.392823-1-richard.henderson@linaro.org> References: <20230118011123.392823-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Reuse the decodetree based disassembler from target/loongarch/ for tcg/loongarch64/. The generation of decode-insns.c.inc into ./libcommon.fa.p/ could eventually result in conflict, if any other host requires the same trick, but this is good enough for now. Signed-off-by: Richard Henderson Reviewed-by: WANG Xuerui Reviewed-by: Philippe Mathieu-Daudé --- disas.c | 2 ++ target/loongarch/meson.build | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/disas.c b/disas.c index 3b31315f40..c9fa38e6d7 100644 --- a/disas.c +++ b/disas.c @@ -198,6 +198,8 @@ static void initialize_debug_host(CPUDebug *s) s->info.cap_insn_split = 6; #elif defined(__hppa__) s->info.print_insn = print_insn_hppa; +#elif defined(__loongarch64) + s->info.print_insn = print_insn_loongarch; #endif } diff --git a/target/loongarch/meson.build b/target/loongarch/meson.build index 6376f9e84b..690633969f 100644 --- a/target/loongarch/meson.build +++ b/target/loongarch/meson.build @@ -3,7 +3,6 @@ gen = decodetree.process('insns.decode') loongarch_ss = ss.source_set() loongarch_ss.add(files( 'cpu.c', - 'disas.c', )) loongarch_tcg_ss = ss.source_set() loongarch_tcg_ss.add(gen) @@ -24,6 +23,8 @@ loongarch_softmmu_ss.add(files( 'iocsr_helper.c', )) +common_ss.add(when: 'CONFIG_LOONGARCH_DIS', if_true: [files('disas.c'), gen]) + loongarch_ss.add_all(when: 'CONFIG_TCG', if_true: [loongarch_tcg_ss]) target_arch += {'loongarch': loongarch_ss} From patchwork Wed Jan 18 01:11:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 643668 Delivered-To: patch@linaro.org Received: by 2002:a17:522:b9de:b0:4b9:b062:db3b with SMTP id fj30csp1489758pvb; Tue, 17 Jan 2023 17:12:45 -0800 (PST) X-Google-Smtp-Source: AMrXdXvm7mKd5+WZkz8XhTco4vFgK1gXwT2hr7kFNnzd3u1+5O8X4GJZ6VGAsK5lrTt6P2wNVPcv X-Received: by 2002:a05:622a:5d9a:b0:3b4:d5ce:9f1f with SMTP id fu26-20020a05622a5d9a00b003b4d5ce9f1fmr6656171qtb.45.1674004365038; Tue, 17 Jan 2023 17:12:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674004365; cv=none; d=google.com; s=arc-20160816; b=wduNPN8HQaalgHjIao8LcLPtErHMrXjAcaCpBeF9+BecItRGT3PSihze2dUufRrnlo C0qIiTNeTxBEWdzijGakW7bB+vSJsPgYF0LLmJghJrcDn+sJ/FuymWhqJ8+osmFc325g ZRaHTvRIz2J0OPao18jjdyAhkZ0HyJ5jVyg//vOXPdPSsprl9b51d2dzrAvH5mzej4Yi TxLMzvKMFdaVNO15+CX0Q7RxkrpQTa76HEo4U2jE09xWl2FHjW9XPy5RdhAebpfb9w5E 1GShpWYpPf87toemVUmCcAECh8+PEZPKpE41pkSG1vLsoRNt5VpiT2zbtqBypx5MKAC1 cPlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vX/i9PddUxPpu4wKsNIpRjvexpTXXwf910s7846V1ss=; b=lShYMLQhn3sIWKZmk+maOmUjDGuJNWm7u6yGZp+HFYVOkRczXEOqt62egdo1fz0TQ/ aOR/b/HhAiNyuTs5PzAQfcSAV/9Gn/6iZpr4XX2e2YscVQswOk64/56CFLZazncHK3G0 fUbS3OvPDLnMg2k84wivvZApa4ufbqJMg1L2y8iT6ByT40UPK90J08UguBo64IdlvQIq +WDeln6Gio18ilkB1t9JE5gto0lhuCWuNYmmJ6ic7rgHg1bJu1vsmMQ3Ve09af0gXMp8 Zd45ameE9CmiWlYnum7ahHSyh6YyO7sgQ+8mxzy6prizBOU7tySOgeig590PZi6O3rOh dHSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=s3UPhLDx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d12-20020ac847cc000000b003b4155467b2si6745423qtr.232.2023.01.17.17.12.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Jan 2023 17:12:45 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=s3UPhLDx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHwzG-00020W-TU; Tue, 17 Jan 2023 20:11:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pHwzF-0001zS-Dw for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:33 -0500 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHwzD-0002EI-Pm for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:33 -0500 Received: by mail-pj1-x102c.google.com with SMTP id a14-20020a17090a70ce00b00229a2f73c56so708566pjm.3 for ; Tue, 17 Jan 2023 17:11:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vX/i9PddUxPpu4wKsNIpRjvexpTXXwf910s7846V1ss=; b=s3UPhLDxxfSmawKS23EyN6J7QF1stx430KGbnjPhvJn8vqi0SkDH3UPJfsQ1dTuei/ ssP5O34Kl8C+2ReW7a+DEai5ra5MFlOadnfm1edNwvRb0p6TEDblc9b9YhlFa+DgI6lH uEenrbqAsowGcXJhaMgprMdCEUssJ3lUJWMdCoU2BayBa7nh1QTAsgUxznpjGJtzZcUG 50ssdK0xiOyDwzPU74XlSRMSC2bFPFS7R+fWbgm2ZUz/416ozrH2+5MMIC/DZiCOnsdT nQdkc+HVg/gzp9Dk07Tge9/BtLI+AZdTZE40KlpuFN8F7ECeswSVoPwEOGu/RiwHB/NY M6lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vX/i9PddUxPpu4wKsNIpRjvexpTXXwf910s7846V1ss=; b=LCs8on5aEIy6vxu9dNanojTyB3qXfbBhJGU6Bk8hysczVuClLdX4p+4xz/NtDsX5v2 NmR5KT0oNFppkPS33FUuAF43fWRLfOWKlcqHsz4jYVsb1jkhE4XbGdwTH12/0lyT+D3B YLPBZUK/4qaSGOS9zkF0YhNIKK8m/Cs0IrPJCKgUFVr64iExlt/rz3E4nErhpkZ6sK4q ZTMcss75rji3Yq2S0p9jjS+DS9oM6bquKLT2oAOEDb0OCxl39xHPdlY8Jc4q1J1w9Wyb B34LEVBW7CvhNZC8gHCAPXfk3CfciZtoa5sstc8097KKulbRZIN1IIbZGtWECSx+pvP3 BbjQ== X-Gm-Message-State: AFqh2kpx5csVDt/j3WOiPgY0Ij+RZjJJgkniKRcVMDTBbHM5DqOjOMKp 3O1GolvCvZrAQVsuVZ2pHN+dBYp8eHD2XOTj X-Received: by 2002:a17:902:bf03:b0:194:9847:9cd4 with SMTP id bi3-20020a170902bf0300b0019498479cd4mr5092959plb.60.1674004290009; Tue, 17 Jan 2023 17:11:30 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b0017ec1b1bf9fsm21660259plp.217.2023.01.17.17.11.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 17:11:29 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name Subject: [PATCH v2 02/10] target/loongarch: Disassemble jirl properly Date: Tue, 17 Jan 2023 15:11:15 -1000 Message-Id: <20230118011123.392823-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118011123.392823-1-richard.henderson@linaro.org> References: <20230118011123.392823-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org While jirl shares the same instruction format as bne etc, it is not assembled the same. In particular, rd is printed first not second and the immediate is not pc-relative. Decode into the arg_rr_i structure, which prints correctly. This changes the "offs" member to "imm", to update translate. Signed-off-by: Richard Henderson Reviewed-by: WANG Xuerui --- target/loongarch/disas.c | 2 +- target/loongarch/insn_trans/trans_branch.c.inc | 2 +- target/loongarch/insns.decode | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/target/loongarch/disas.c b/target/loongarch/disas.c index 858dfcc53a..7cffd853ec 100644 --- a/target/loongarch/disas.c +++ b/target/loongarch/disas.c @@ -628,7 +628,7 @@ INSN(beqz, r_offs) INSN(bnez, r_offs) INSN(bceqz, c_offs) INSN(bcnez, c_offs) -INSN(jirl, rr_offs) +INSN(jirl, rr_i) INSN(b, offs) INSN(bl, offs) INSN(beq, rr_offs) diff --git a/target/loongarch/insn_trans/trans_branch.c.inc b/target/loongarch/insn_trans/trans_branch.c.inc index 65dbdff41e..a860f7e733 100644 --- a/target/loongarch/insn_trans/trans_branch.c.inc +++ b/target/loongarch/insn_trans/trans_branch.c.inc @@ -23,7 +23,7 @@ static bool trans_jirl(DisasContext *ctx, arg_jirl *a) TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE); TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); - tcg_gen_addi_tl(cpu_pc, src1, a->offs); + tcg_gen_addi_tl(cpu_pc, src1, a->imm); tcg_gen_movi_tl(dest, ctx->base.pc_next + 4); gen_set_gpr(a->rd, dest, EXT_NONE); tcg_gen_lookup_and_goto_ptr(); diff --git a/target/loongarch/insns.decode b/target/loongarch/insns.decode index 3fdc6e148c..de7b8f0f3c 100644 --- a/target/loongarch/insns.decode +++ b/target/loongarch/insns.decode @@ -67,6 +67,7 @@ @rr_ui12 .... ...... imm:12 rj:5 rd:5 &rr_i @rr_i14s2 .... .... .............. rj:5 rd:5 &rr_i imm=%i14s2 @rr_i16 .... .. imm:s16 rj:5 rd:5 &rr_i +@rr_i16s2 .... .. ................ rj:5 rd:5 &rr_i imm=%offs16 @hint_r_i12 .... ...... imm:s12 rj:5 hint:5 &hint_r_i @rrr_sa2p1 .... ........ ... .. rk:5 rj:5 rd:5 &rrr_sa sa=%sa2p1 @rrr_sa2 .... ........ ... sa:2 rk:5 rj:5 rd:5 &rrr_sa @@ -444,7 +445,7 @@ beqz 0100 00 ................ ..... ..... @r_offs21 bnez 0100 01 ................ ..... ..... @r_offs21 bceqz 0100 10 ................ 00 ... ..... @c_offs21 bcnez 0100 10 ................ 01 ... ..... @c_offs21 -jirl 0100 11 ................ ..... ..... @rr_offs16 +jirl 0100 11 ................ ..... ..... @rr_i16s2 b 0101 00 .......................... @offs26 bl 0101 01 .......................... @offs26 beq 0101 10 ................ ..... ..... @rr_offs16 From patchwork Wed Jan 18 01:11:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 643672 Delivered-To: patch@linaro.org Received: by 2002:a17:522:b9de:b0:4b9:b062:db3b with SMTP id fj30csp1489987pvb; Tue, 17 Jan 2023 17:13:17 -0800 (PST) X-Google-Smtp-Source: AMrXdXuFsKdlMIDf5BeSuwNWljMZzobPCGYmUgu7Efwm7uwd8yCpJOCRBOuKK5WoHL3iR282ZbUN X-Received: by 2002:ac8:5405:0:b0:3b6:30ea:e95 with SMTP id b5-20020ac85405000000b003b630ea0e95mr7502885qtq.18.1674004397058; Tue, 17 Jan 2023 17:13:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674004397; cv=none; d=google.com; s=arc-20160816; b=G1Eh+AeF1yHvdkw7iYiX+up3sgJW8Y8+NzpMaAg+Za5WWB0KD5XwRQyyQkE9ix2T2b Z02qBkl55KoZYwk2ne+JEudaerRggdFqITNvPaSHsvtIiKkIJwkLrIRo5cHdER6zu9do wK8hpo2BY61EH45ozZNhDcCyML2NxkGKsuZ/LogTiNaYBmIPiEpi5M+T1FO1TojA8z58 AUS0G/kbTPoyjyhebfNGCArhCfrQ/qD5YmB83z0kUAT7NNYrf7YCKyZns2T/EWmQir7y ccXiHl7bESMG3XVzCn20BioVUpxYeP0QHs8u+aE635HFjS/iuqo5oQp6ggodDBQci0Q8 tKdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Q2Z9v9cYvm0JH0FW34M0lXW5HnvaE2SPN1rqJqhu+FM=; b=ALGW14hMEFV61nxsFXuNAkn2eNnXW+GABSw0yGiBe1F6qLFp4EeJlzewEWBX0VbhYD kOv5YwNtN3ZS/fpcom/8VF0zXPPbkgYr9qbfXLiKfl3vM4SKO/fCRU28Rc3WvYDpANtP v74LIWU6UtIN3ip0XUXM8IOfFHOA37/zPhUkqym8y+MbcgH0TeQ9pU4ak1aOaCAS5+s2 t2nJxv622QvZM6qZO3dBHBa1v5iWUGbtDdcVMd2rteayoJSK69+cj9gmZusCCBaeJNBH m9223qSQy8p6ca/kQuW7wnfm/Lfj9FB3jAmtQDxayDreGm8xlVJUTIClch20l+BNlOd5 DAuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sSp3k1kO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id gc5-20020a05622a59c500b003a6a7728c2fsi5639766qtb.753.2023.01.17.17.13.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Jan 2023 17:13:17 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sSp3k1kO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHwzI-000215-E3; Tue, 17 Jan 2023 20:11:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pHwzG-00020C-BN for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:34 -0500 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHwzE-0002EU-R6 for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:34 -0500 Received: by mail-pj1-x102a.google.com with SMTP id bj3so31015314pjb.0 for ; Tue, 17 Jan 2023 17:11:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q2Z9v9cYvm0JH0FW34M0lXW5HnvaE2SPN1rqJqhu+FM=; b=sSp3k1kOwCGQm9fVKfiK9B7k75+stPVLywi6h5odTQpQ8aNTD7up3DUf5sF91rwo73 ZIeD5SF4GsZc2fFZqPx0aeQRP0fa/M2fEcmxic/hDdR4j1hCc+7eE6KRwGU7Pn2mD+Mw z9IQTpqJfSFtD9c9rywZy9jNjboU01KdX8DdBEZmyZFJTChRMSGOdv1XotzIZDvgAIpT SNmf2tka27bhGjolzUpsVwZTk6vY24HAP6FQK62cDsjzr72AIgq3uzCrZuMBYLn5hdfc EZV0vvWqUsROnbgXU710ashIW0mduAy2CuoDGlBfvwaQa/leKXScsv3ahzS0KWUDcoTx KyWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q2Z9v9cYvm0JH0FW34M0lXW5HnvaE2SPN1rqJqhu+FM=; b=EBlFCxTrJzDLgJX+dyM9apjty3+LlxXXZqijhL7pzWKfhjavlMY83GPHAzPxk4+to0 vbIzhSpxcRKYl/yVLQRlj49qQLtjGEC2jIoei+MfLtrl6bmP1aycjlJP7hR8koXOvIf2 iPXZWTd1gQAt1/KhxgHfUnXEHvrWg+BoUIrHeFnO0/EfOrSLcghqlaw6lw27dHxeE1mq lZmU2SNo7cApdHERJDkGBptai2VaZhxoM+VQRGN+kKQooDihu1d4aiZvV8Vw08NzdM3G UbthiEqgtc3cQuzVT30HlLyWNEdbzZEYLF4fiOfDzBa/Myu8BTuAOgqB83mPBZ+u3LMY I3ZQ== X-Gm-Message-State: AFqh2kpa++X6idvhpP3z/eQnALFzO/hjV3ZOXOA9f3VkrrKz+It7kLxL KXIq6d91ypiV55UxtqB6SiXAtfcnn5pEeD6h X-Received: by 2002:a17:902:8c94:b0:18f:a27c:fe with SMTP id t20-20020a1709028c9400b0018fa27c00femr5919952plo.55.1674004291390; Tue, 17 Jan 2023 17:11:31 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b0017ec1b1bf9fsm21660259plp.217.2023.01.17.17.11.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 17:11:30 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name Subject: [PATCH v2 03/10] target/loongarch: Disassemble pcadd* addresses Date: Tue, 17 Jan 2023 15:11:16 -1000 Message-Id: <20230118011123.392823-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118011123.392823-1-richard.henderson@linaro.org> References: <20230118011123.392823-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Print both the raw field and the resolved pc-relative address, as we do for branches. Signed-off-by: Richard Henderson Reviewed-by: WANG Xuerui --- target/loongarch/disas.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/target/loongarch/disas.c b/target/loongarch/disas.c index 7cffd853ec..2e93e77e0d 100644 --- a/target/loongarch/disas.c +++ b/target/loongarch/disas.c @@ -519,10 +519,6 @@ INSN(fsel, fffc) INSN(addu16i_d, rr_i) INSN(lu12i_w, r_i) INSN(lu32i_d, r_i) -INSN(pcaddi, r_i) -INSN(pcalau12i, r_i) -INSN(pcaddu12i, r_i) -INSN(pcaddu18i, r_i) INSN(ll_w, rr_i) INSN(sc_w, rr_i) INSN(ll_d, rr_i) @@ -755,3 +751,36 @@ static bool trans_fcmp_cond_##suffix(DisasContext *ctx, \ FCMP_INSN(s) FCMP_INSN(d) + +#define PCADD_INSN(name) \ +static bool trans_##name(DisasContext *ctx, arg_##name *a) \ +{ \ + output(ctx, #name, "r%d, %d # 0x%" PRIx64, \ + a->rd, a->imm, gen_##name(ctx->pc, a->imm)); \ + return true; \ +} + +static uint64_t gen_pcaddi(uint64_t pc, int imm) +{ + return pc + (imm << 2); +} + +static uint64_t gen_pcalau12i(uint64_t pc, int imm) +{ + return (pc + (imm << 12)) & ~0xfff; +} + +static uint64_t gen_pcaddu12i(uint64_t pc, int imm) +{ + return pc + (imm << 12); +} + +static uint64_t gen_pcaddu18i(uint64_t pc, int imm) +{ + return pc + ((uint64_t)(imm) << 18); +} + +PCADD_INSN(pcaddi) +PCADD_INSN(pcalau12i) +PCADD_INSN(pcaddu12i) +PCADD_INSN(pcaddu18i) From patchwork Wed Jan 18 01:11:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 643662 Delivered-To: patch@linaro.org Received: by 2002:a17:522:b9de:b0:4b9:b062:db3b with SMTP id fj30csp1489495pvb; Tue, 17 Jan 2023 17:12:06 -0800 (PST) X-Google-Smtp-Source: AMrXdXuK9PBqoyh3TEqOuomVq/AHO13PS1Xt3MlKrzq22H7/su6N1kQwEH1CixMdABa0Da8AiGJK X-Received: by 2002:a05:6214:424e:b0:534:8770:6fc7 with SMTP id ne14-20020a056214424e00b0053487706fc7mr6823253qvb.21.1674004325983; Tue, 17 Jan 2023 17:12:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674004325; cv=none; d=google.com; s=arc-20160816; b=qvuiLLe+qNjzvusR9uE75nu9Tkqlvk+09OnrqS/JTOXcnTIFB/ovDS4oA2RKK2Pipv UX6IPLKRzdVLqAoiO6cWx3ehUkNoDTUtiIwQEw862Qr4vexICBl4+SH4v7CFQXaXgR5+ 5dkR/ay63T+shVRRwG5FnTwq1eQW6MO2FAHFHJUtU0HRIk1Wn5W2D3uhGyndv+iHybQm xX8X+pxq872IboGqyKzBrpou6aheY4avrKaIA/w2TxTHMZCulXJa/TxrEF7ukZOYGSbU eV4cNhwi3XDa4z4CrqT37HAmMRatJC900wQERR92CF8K6SpI+sy9MfTi4PWWyD+rt2KK +H9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=us8czsx2kIC6irS16c66/8rQTL9kieqCt5u2bB0B4KM=; b=Yn7n/3xKtGbITh1iYg62YJv9Nfjo3WOvFJ4lQSeJI98KLTdfpBncoNj5KaY24ek4zL 6kdsxxil/rve5NVPKMSyMuQRqio4sePSTscf+t/UU9k+afsZ2zzcl3nbkMWN6ko01kmu Yrt7Ujy/QSmnk3RFuIgLB/je6DHuMPA/ub2ftjivAi3Gq5Whr9B550sz2EGG/DJ3GSLs bDj/qCXab11OgoJoPet66gWtEDXEJWnO14wkH2whETvdKMSDSIV/x0ii+V0TDzLI4tLy p2b8x4VfPtjY9h85/5xvhHMR6+Jdpg95+mluA5pM0ew3frrJ51AKRIUpkxO+CjaMoZJZ 54Fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iPotovUu; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 4-20020a05621420c400b005322ddb2b4fsi7979709qve.245.2023.01.17.17.12.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Jan 2023 17:12:05 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iPotovUu; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHwzJ-00021R-Ca; Tue, 17 Jan 2023 20:11:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pHwzH-00020w-S9 for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:36 -0500 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHwzG-0002Ec-4p for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:35 -0500 Received: by mail-pl1-x62b.google.com with SMTP id d3so35321538plr.10 for ; Tue, 17 Jan 2023 17:11:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=us8czsx2kIC6irS16c66/8rQTL9kieqCt5u2bB0B4KM=; b=iPotovUuOdodeMf1wHccQkEnUoBN0C15nINJ1kUkRt+EKZORPTnTaGCCHbPzmbV9TO YvnAioBzdJp4t+Rni9Lrp6a6P/M3PPtyhLa2tvn3phUj46Sn+ObToG8svdIYj4g/R/rf zvrF4kQHRfgHXzoXDzFbaf3dtOOdTjBzSXvPuklXVaKKidhjWCTFg906X4vkxBGdD6hd 0w/YmeHOmTXe/AHfcrWqIWAbBWNAp62YIsx3wVGtAa6IcccqkYdnuPBokkYZ46OTRm9e 3NOPbdmlap5vJUxqk5qF/oPXDB+F2CWMhKydKkCXuI/acFNFl0VHb2xS2f+w88duoTaF kqHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=us8czsx2kIC6irS16c66/8rQTL9kieqCt5u2bB0B4KM=; b=ZAGlSKi9PAyCsAqVGKrvN/4ZNz9B5dkpPNE3QSNxlnvVtGsN+eaCwGlYecpjf5kCfe KpvW9b8wbPT3KDARB2nuwmGsBdOv00OJMlL4/rslwH9Fjzmdt4Q2Y2xB4PP+Yb2lbwQl knWIwEqZ/R9/dNLnDJHTpxgU05RXsCbO5/B6e3fen65FOlhCv4EqNifgYlAPukt3CHNy W1DrrL+Q1J+fntTFtAkN2AZyjQTpWpuZjACkrV11TZs6++7vGLtRnvfN+77+SE670pIT H1WR/ck5IARHvYp9tBCU52lhtADz1LHNtFvJqFwnvDdfxehqFimZZphWT8QeTIp9ZowP 84wg== X-Gm-Message-State: AFqh2kr3zuxLd68d17plGhqPCyzSt23yp3TPoNyGgLlnfW6QLAyYmeS1 4NwWwwcktMXt2jOPrnrXlb+P22A8WnTG9xpS X-Received: by 2002:a17:902:6904:b0:193:3354:1c22 with SMTP id j4-20020a170902690400b0019333541c22mr4212123plk.39.1674004292840; Tue, 17 Jan 2023 17:11:32 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b0017ec1b1bf9fsm21660259plp.217.2023.01.17.17.11.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 17:11:32 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name, Rui Wang Subject: [PATCH v2 04/10] tcg/loongarch64: Optimize immediate loading Date: Tue, 17 Jan 2023 15:11:17 -1000 Message-Id: <20230118011123.392823-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118011123.392823-1-richard.henderson@linaro.org> References: <20230118011123.392823-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Rui Wang diff: Imm Before After 0000000000000000 addi.w rd, zero, 0 addi.w rd, zero, 0 lu52i.d rd, zero, 0 00000000fffff800 lu12i.w rd, -1 addi.w rd, zero, -2048 ori rd, rd, 2048 lu32i.d rd, 0 lu32i.d rd, 0 ... Signed-off-by: Rui Wang Message-Id: <20221107144713.845550-1-wangrui@loongson.cn> Signed-off-by: Richard Henderson Reviewed-by: WANG Xuerui --- tcg/loongarch64/tcg-target.c.inc | 35 +++++++++++--------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/tcg/loongarch64/tcg-target.c.inc b/tcg/loongarch64/tcg-target.c.inc index 3174557ce3..428f3abd71 100644 --- a/tcg/loongarch64/tcg-target.c.inc +++ b/tcg/loongarch64/tcg-target.c.inc @@ -274,16 +274,6 @@ static bool tcg_out_mov(TCGContext *s, TCGType type, TCGReg ret, TCGReg arg) return true; } -static bool imm_part_needs_loading(bool high_bits_are_ones, - tcg_target_long part) -{ - if (high_bits_are_ones) { - return part != -1; - } else { - return part != 0; - } -} - /* Loads a 32-bit immediate into rd, sign-extended. */ static void tcg_out_movi_i32(TCGContext *s, TCGReg rd, int32_t val) { @@ -291,16 +281,16 @@ static void tcg_out_movi_i32(TCGContext *s, TCGReg rd, int32_t val) tcg_target_long hi12 = sextreg(val, 12, 20); /* Single-instruction cases. */ - if (lo == val) { - /* val fits in simm12: addi.w rd, zero, val */ - tcg_out_opc_addi_w(s, rd, TCG_REG_ZERO, val); - return; - } - if (0x800 <= val && val <= 0xfff) { + if (hi12 == 0) { /* val fits in uimm12: ori rd, zero, val */ tcg_out_opc_ori(s, rd, TCG_REG_ZERO, val); return; } + if (hi12 == sextreg(lo, 12, 20)) { + /* val fits in simm12: addi.w rd, zero, val */ + tcg_out_opc_addi_w(s, rd, TCG_REG_ZERO, val); + return; + } /* High bits must be set; load with lu12i.w + optional ori. */ tcg_out_opc_lu12i_w(s, rd, hi12); @@ -334,8 +324,7 @@ static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg rd, intptr_t pc_offset; tcg_target_long val_lo, val_hi, pc_hi, offset_hi; - tcg_target_long hi32, hi52; - bool rd_high_bits_are_ones; + tcg_target_long hi12, hi32, hi52; /* Value fits in signed i32. */ if (type == TCG_TYPE_I32 || val == (int32_t)val) { @@ -366,25 +355,25 @@ static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg rd, return; } + hi12 = sextreg(val, 12, 20); hi32 = sextreg(val, 32, 20); hi52 = sextreg(val, 52, 12); /* Single cu52i.d case. */ - if (ctz64(val) >= 52) { + if ((hi52 != 0) && (ctz64(val) >= 52)) { tcg_out_opc_cu52i_d(s, rd, TCG_REG_ZERO, hi52); return; } /* Slow path. Initialize the low 32 bits, then concat high bits. */ tcg_out_movi_i32(s, rd, val); - rd_high_bits_are_ones = (int32_t)val < 0; - if (imm_part_needs_loading(rd_high_bits_are_ones, hi32)) { + /* Load hi32 and hi52 explicitly when they are unexpected values. */ + if (hi32 != sextreg(hi12, 20, 20)) { tcg_out_opc_cu32i_d(s, rd, hi32); - rd_high_bits_are_ones = hi32 < 0; } - if (imm_part_needs_loading(rd_high_bits_are_ones, hi52)) { + if (hi52 != sextreg(hi32, 20, 12)) { tcg_out_opc_cu52i_d(s, rd, rd, hi52); } } From patchwork Wed Jan 18 01:11:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 643665 Delivered-To: patch@linaro.org Received: by 2002:a17:522:b9de:b0:4b9:b062:db3b with SMTP id fj30csp1489619pvb; Tue, 17 Jan 2023 17:12:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXswtWyB9EKGqkNfXCN4YtHeIc3cDhpkfDiqH5s1prut3UR6uc0Mp5mT4vzJsV/EdMx4wu33 X-Received: by 2002:ac8:6a0e:0:b0:3ab:7928:526c with SMTP id t14-20020ac86a0e000000b003ab7928526cmr6498561qtr.17.1674004340941; Tue, 17 Jan 2023 17:12:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674004340; cv=none; d=google.com; s=arc-20160816; b=iVMwp6x0GBqQejwjUQLiSpTji0BOPMo3/ZZ35sOzORToCova1ae/MWaLfC4Y27HcQo jB0+Zfx96DIIL1GVa+oLue0NiDnRrD+9ByGtRdlOcjhZGcHLVfzNlY1KDm+Iwt8sLN5q QC5T95Hov8lN48YYPtJ4g8743WKBbWg2BTjihUCnWl45rcgj3vqHvPljn+lTWcjwp5KT gq3VWaLJdzMdM2HErko6LuB2bTCwNC1pZNnTkXXLsaVMlaXX7UouZxnWySVOoICM6ccT 3cE/A+mN7LvgQgeaXqIFT0xvLdjZ6N4UAFijNxFrXyoRj01MeyKlWLLRtKf+73/verhI H4zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=eXmkIhIsuv2GneKn/fEVnv+GUooitbhPBGl3nWaEWcQ=; b=iuUHLgGNk4cRl0Gj5zI727V1fS3oBK5evtcSmyG0/h4JlGIIL3lFM5Ay9GKblgO0Pd a5HbuGoR4RTCbD7bXomfvXKuoVJfPf69r1MwbOOa5HbH6/ZJUzqZNB3xsQRd7BpBx/oP bxmXw1J0P2nas6nATqHJNhbdHCZssLkLfqDiPgXf9j01pfVE2ov3C+q92yypQvnaTyKe JBsIjO2WoPFMQcXcdmBvkMvzGL35pGwcopRMS3vCUqMffPWS1Mskr84dsLnwjE9g3UVS TztwrI4nAndh504TE/RfyAFWDn9XDkTwogjJoZI4ynnPf5eP/TpbKkOA6rb9pHB719sl rpnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=j7bLVCaQ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id fg26-20020a05622a581a00b003a7e5da777esi21107939qtb.206.2023.01.17.17.12.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Jan 2023 17:12:20 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=j7bLVCaQ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHwzK-000228-Qs; Tue, 17 Jan 2023 20:11:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pHwzJ-00021S-Fj for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:37 -0500 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHwzH-0002Ep-NT for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:37 -0500 Received: by mail-pl1-x634.google.com with SMTP id k18so11306936pll.5 for ; Tue, 17 Jan 2023 17:11:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eXmkIhIsuv2GneKn/fEVnv+GUooitbhPBGl3nWaEWcQ=; b=j7bLVCaQ+kGVkaNNYh7B0+LHYsh49B2n8JQTgiMj7zN0zoob2FEwNH42wFf3Iwv4tW /1E48c6kmtnQi6y9NPxAvQyfsr32sLpwjoJS4HLHhjFfx/aYdRU4aubNzl26s+4gFEDs FqbGUmJKORiLwN+TNDIff3PWdSHNPd6Uh7rrhrToX+GccOzzVA9vHwJ0pO3bcsytROnt FDRYEhG5CrGUDoui6Qznh1W3tmn8Qp8K2DgLXc3LxZSrOO5RvwSnpXlIfGhMZFFVEaJe je4GF+7lwlBDiofYPTKeBuXVw/B1O6U7A3NsSHcJv22cSk0HJS3Zej95rPR22VqUb4kP nIeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eXmkIhIsuv2GneKn/fEVnv+GUooitbhPBGl3nWaEWcQ=; b=2Fyp0MItIXeXDg330FpXKN4aduHZ2incMjvkwY7VXJkQVcMsRcQdjdWPiM44fON2Vb IKaKq+epATUYpaZWbdmPp0WJNUehxEvPKTFEn8GyW91sptKlTyF+UFRcT+ahIzkV8199 kTKaxva7NrRVtZXV84vaVUfPN2fA9xMT87ekxgb//+IlLEByYQaXd34nDjsKdcmADIX+ Kxy/XHeSRITY1sIR9Enypy41z/NdWwlA5cEN1toZPlq8AkJ1SboM1xw5hf8p9/L9GGts XHDf9avso/02UZKO25QSltUSWfYBJQfYDJy0kJSQDs4s+UF9EK+THQOanXTr8kthGnsz yRWw== X-Gm-Message-State: AFqh2kr883na593Uhgbq/v+l99pNC5jdJaXHrzHxepsy+zcX10xEoxDe UL37+tjSgAeSWSQgbpEtGX45fFBvx0Ym1htb X-Received: by 2002:a17:903:182:b0:194:7532:fb10 with SMTP id z2-20020a170903018200b001947532fb10mr7403618plg.40.1674004294218; Tue, 17 Jan 2023 17:11:34 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b0017ec1b1bf9fsm21660259plp.217.2023.01.17.17.11.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 17:11:33 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name Subject: [PATCH v2 05/10] tcg/loongarch64: Update tcg-insn-defs.c.inc Date: Tue, 17 Jan 2023 15:11:18 -1000 Message-Id: <20230118011123.392823-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118011123.392823-1-richard.henderson@linaro.org> References: <20230118011123.392823-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Regenerate with ADDU16I included: $ cd loongarch-opcodes/scripts/go $ go run ./genqemutcgdefs > $QEMU/tcg/loongarch64/tcg-insn-defs.c.inc Signed-off-by: Richard Henderson Reviewed-by: WANG Xuerui Reviewed-by: Philippe Mathieu-Daudé --- tcg/loongarch64/tcg-insn-defs.c.inc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) mode change 100644 => 100755 tcg/loongarch64/tcg-insn-defs.c.inc diff --git a/tcg/loongarch64/tcg-insn-defs.c.inc b/tcg/loongarch64/tcg-insn-defs.c.inc old mode 100644 new mode 100755 index d162571856..b5bb0c5e73 --- a/tcg/loongarch64/tcg-insn-defs.c.inc +++ b/tcg/loongarch64/tcg-insn-defs.c.inc @@ -4,7 +4,7 @@ * * This file is auto-generated by genqemutcgdefs from * https://github.com/loongson-community/loongarch-opcodes, - * from commit 961f0c60f5b63e574d785995600c71ad5413fdc4. + * from commit 25ca7effe9d88101c1cf96c4005423643386d81f. * DO NOT EDIT. */ @@ -74,6 +74,7 @@ typedef enum { OPC_ANDI = 0x03400000, OPC_ORI = 0x03800000, OPC_XORI = 0x03c00000, + OPC_ADDU16I_D = 0x10000000, OPC_LU12I_W = 0x14000000, OPC_CU32I_D = 0x16000000, OPC_PCADDU2I = 0x18000000, @@ -710,6 +711,13 @@ tcg_out_opc_xori(TCGContext *s, TCGReg d, TCGReg j, uint32_t uk12) tcg_out32(s, encode_djuk12_insn(OPC_XORI, d, j, uk12)); } +/* Emits the `addu16i.d d, j, sk16` instruction. */ +static void __attribute__((unused)) +tcg_out_opc_addu16i_d(TCGContext *s, TCGReg d, TCGReg j, int32_t sk16) +{ + tcg_out32(s, encode_djsk16_insn(OPC_ADDU16I_D, d, j, sk16)); +} + /* Emits the `lu12i.w d, sj20` instruction. */ static void __attribute__((unused)) tcg_out_opc_lu12i_w(TCGContext *s, TCGReg d, int32_t sj20) From patchwork Wed Jan 18 01:11:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 643671 Delivered-To: patch@linaro.org Received: by 2002:a17:522:b9de:b0:4b9:b062:db3b with SMTP id fj30csp1489979pvb; Tue, 17 Jan 2023 17:13:15 -0800 (PST) X-Google-Smtp-Source: AMrXdXviYtfQ4NWLI35heuI4zTvQUKL22Pbvlyz+wcl8L2g0Z3ZmlJr6xibuVJokH1mePeiW1ftT X-Received: by 2002:ac8:6bda:0:b0:3a7:e22d:e316 with SMTP id b26-20020ac86bda000000b003a7e22de316mr6651954qtt.21.1674004395504; Tue, 17 Jan 2023 17:13:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674004395; cv=none; d=google.com; s=arc-20160816; b=Tm6V/f+gJ184ggz+LVGJr2ow/88OwZPHDQZJ8UKUu9Z7qW9ZdnBO2fzZ6CSYztdk1k nlbu5eKlOOSYTMW+zho3J3ketMrM3hC4LJljgmq4vtWsS1zRuIhh7tDh21ZPU8zfW1Nq lKo+nQSVaqOQus+yd2xZqdS1dRiwTeg6CG0qvk21czbe/3t92T60Ms229zuuS1YIeFwB RIM5ACiRLRXnNTelO1MGJ6fHZZJmBZeZYMKQgSW2MvCYpoxYEPPXa9TbKjETbOxtUnUN HGVxBky0+9LgcclPbcuXA5DO5ES1lIrCdgAuFT6+a4G6hxk9u8363kdyldg5dDkC4i3H uGDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BFlw89atOzM4lr6R+FnGh+9BiIOC0mo/qQqa+yTQyuU=; b=MLkodD/tTz+0Gfwxos6ipYg/ykUYi31y+l5dGI0IpHYREVvoGrWRr4nHpUxAqP+FaQ kyxl2wsmBSoCMjNROmt4dO4rMYQXkluh8cw5THYlfbGSf5fDU0lx+Vsom0TZO4tXALxB bU56Bj1GwN+Ht/F78boU6qVM+JWhymtRRqzpSUNXbrJ4B5lQ6PDSJ7X42sV2oxK/AO/P 1YEjl7kdt+GuzoC4G7tF7nadU9qDz44I9aZDOYid1/0NbVvafYvKfOTROV5ifM3TeuRF xxRsHf+X8W8DWYDGzvJCokEnrgfycai+/RUlra4rnvZc0LSl3w7lDecJNCkkoxXHRN/6 1yoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JOC5E+1R; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y10-20020ac8708a000000b003a5226e267fsi18738302qto.626.2023.01.17.17.13.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Jan 2023 17:13:15 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JOC5E+1R; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHwzN-00024F-1y; Tue, 17 Jan 2023 20:11:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pHwzL-00022K-1u for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:39 -0500 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHwzJ-0002F1-98 for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:38 -0500 Received: by mail-pj1-x102e.google.com with SMTP id z1-20020a17090a66c100b00226f05b9595so693722pjl.0 for ; Tue, 17 Jan 2023 17:11:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BFlw89atOzM4lr6R+FnGh+9BiIOC0mo/qQqa+yTQyuU=; b=JOC5E+1R0IlDT3m9m4VboAUnM07Jx0rcVvzv9g68MOMqjmJHoxWh5v3gRmBVanWx9R Bs2EiWaZ+iMETFMaZCjZ5Z+9PRTh/0mDEaS390c9UoZmEiTLR011BCWSeHbdmeXI05VJ edajM5ujkIvlYugxfcpsiCy8xsJU8PX4fHcU/tMPxgxu+yeLMKrOHsje+kk9ib94oSkS uVIjkFYTJuuGR/ppY8LW6GeRdao2sKBlZqynfKIGNhypk+uNo8hernz7Zrrr8djB/GWJ KjHfZyyekMBfB8cYX3Th8w5yrTB4FqUnrZq5h/DGYCNziO5KhnDLQBKkD2T1O8LFbVya VIBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BFlw89atOzM4lr6R+FnGh+9BiIOC0mo/qQqa+yTQyuU=; b=6D2UACFztmEPDKWIBQm4pmAAiPCRRZ42BG1yNU6zrfM61b1alKXn4y4MVIBpsUtESZ vl/70RzaaoRIB/zNKPGPWIi9Rq/zFAdkuF3XYJKToTxAY1dNUTp1R02gwkHxudngDzWC vxc2gDOI6kRK+ppwdqcMsiZCfRX/+9fRWbOaYpwjvV8oEoC3TfAGe+Vo2qyg/iJaHOA8 zRi55CFec2p0xEqUvYwUH4mO3kqVqpd23vdFzvGB0gTud5T+tY5TGs4JbK73Lxs8PRuO Jtrou338eLwMLiRT+WntVWGMPBvtzWKakxPT9LaNynxJNIpahoUOAtLBKjCh43CsVIZg 1PyA== X-Gm-Message-State: AFqh2kqUv83GequBB3Zk+9qeMDBVaR3I4oB92tHf4du9aCd2TugHBpdw 0VHGb1nsnE1+ED8t8kBhkrGdhhwLLHvkoDgO X-Received: by 2002:a17:903:32c1:b0:194:7c95:dc3c with SMTP id i1-20020a17090332c100b001947c95dc3cmr7607094plr.12.1674004295626; Tue, 17 Jan 2023 17:11:35 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b0017ec1b1bf9fsm21660259plp.217.2023.01.17.17.11.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 17:11:35 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name Subject: [PATCH v2 06/10] tcg/loongarch64: Introduce tcg_out_addi Date: Tue, 17 Jan 2023 15:11:19 -1000 Message-Id: <20230118011123.392823-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118011123.392823-1-richard.henderson@linaro.org> References: <20230118011123.392823-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Adjust the constraints to allow any int32_t for immediate addition. Split immediate adds into addu16i + addi, which covers quite a lot of the immediate space. For the hole in the middle, load the constant into TMP0 instead. Signed-off-by: Richard Henderson Reviewed-by: WANG Xuerui --- tcg/loongarch64/tcg-target-con-set.h | 4 +- tcg/loongarch64/tcg-target-con-str.h | 2 +- tcg/loongarch64/tcg-target.c.inc | 57 ++++++++++++++++++++++++---- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/tcg/loongarch64/tcg-target-con-set.h b/tcg/loongarch64/tcg-target-con-set.h index 349c672687..7b5a7a3f5d 100644 --- a/tcg/loongarch64/tcg-target-con-set.h +++ b/tcg/loongarch64/tcg-target-con-set.h @@ -23,9 +23,11 @@ C_O1_I1(r, L) C_O1_I2(r, r, rC) C_O1_I2(r, r, ri) C_O1_I2(r, r, rI) +C_O1_I2(r, r, rJ) C_O1_I2(r, r, rU) C_O1_I2(r, r, rW) C_O1_I2(r, r, rZ) C_O1_I2(r, 0, rZ) -C_O1_I2(r, rZ, rN) +C_O1_I2(r, rZ, ri) +C_O1_I2(r, rZ, rJ) C_O1_I2(r, rZ, rZ) diff --git a/tcg/loongarch64/tcg-target-con-str.h b/tcg/loongarch64/tcg-target-con-str.h index c3986a4fd4..541ff47fa9 100644 --- a/tcg/loongarch64/tcg-target-con-str.h +++ b/tcg/loongarch64/tcg-target-con-str.h @@ -21,7 +21,7 @@ REGS('L', ALL_GENERAL_REGS & ~SOFTMMU_RESERVE_REGS) * CONST(letter, TCG_CT_CONST_* bit set) */ CONST('I', TCG_CT_CONST_S12) -CONST('N', TCG_CT_CONST_N12) +CONST('J', TCG_CT_CONST_S32) CONST('U', TCG_CT_CONST_U12) CONST('Z', TCG_CT_CONST_ZERO) CONST('C', TCG_CT_CONST_C12) diff --git a/tcg/loongarch64/tcg-target.c.inc b/tcg/loongarch64/tcg-target.c.inc index 428f3abd71..8cc6c5eec2 100644 --- a/tcg/loongarch64/tcg-target.c.inc +++ b/tcg/loongarch64/tcg-target.c.inc @@ -126,7 +126,7 @@ static const int tcg_target_call_oarg_regs[] = { #define TCG_CT_CONST_ZERO 0x100 #define TCG_CT_CONST_S12 0x200 -#define TCG_CT_CONST_N12 0x400 +#define TCG_CT_CONST_S32 0x400 #define TCG_CT_CONST_U12 0x800 #define TCG_CT_CONST_C12 0x1000 #define TCG_CT_CONST_WSZ 0x2000 @@ -161,7 +161,7 @@ static bool tcg_target_const_match(int64_t val, TCGType type, int ct) if ((ct & TCG_CT_CONST_S12) && val == sextreg(val, 0, 12)) { return true; } - if ((ct & TCG_CT_CONST_N12) && -val == sextreg(-val, 0, 12)) { + if ((ct & TCG_CT_CONST_S32) && val == (int32_t)val) { return true; } if ((ct & TCG_CT_CONST_U12) && val >= 0 && val <= 0xfff) { @@ -378,6 +378,45 @@ static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg rd, } } +static void tcg_out_addi(TCGContext *s, TCGType type, TCGReg rd, + TCGReg rs, tcg_target_long imm) +{ + tcg_target_long lo12 = sextreg(imm, 0, 12); + tcg_target_long hi16 = sextreg(imm - lo12, 16, 16); + + /* + * Note that there's a hole in between hi16 and lo12: + * + * 3 2 1 0 + * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 + * ...+-------------------------------+-------+-----------------------+ + * | hi16 | | lo12 | + * ...+-------------------------------+-------+-----------------------+ + * + * For bits within that hole, it's more efficient to use LU12I and ADD. + */ + if (imm == (hi16 << 16) + lo12) { + if (hi16) { + tcg_out_opc_addu16i_d(s, rd, rs, hi16); + rs = rd; + } + if (type == TCG_TYPE_I32) { + tcg_out_opc_addi_w(s, rd, rs, lo12); + } else if (lo12) { + tcg_out_opc_addi_d(s, rd, rs, lo12); + } else { + tcg_out_mov(s, type, rd, rs); + } + } else { + tcg_out_movi(s, type, TCG_REG_TMP0, imm); + if (type == TCG_TYPE_I32) { + tcg_out_opc_add_w(s, rd, rs, TCG_REG_TMP0); + } else { + tcg_out_opc_add_d(s, rd, rs, TCG_REG_TMP0); + } + } +} + static void tcg_out_ext8u(TCGContext *s, TCGReg ret, TCGReg arg) { tcg_out_opc_andi(s, ret, arg, 0xff); @@ -1350,14 +1389,14 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, case INDEX_op_add_i32: if (c2) { - tcg_out_opc_addi_w(s, a0, a1, a2); + tcg_out_addi(s, TCG_TYPE_I32, a0, a1, a2); } else { tcg_out_opc_add_w(s, a0, a1, a2); } break; case INDEX_op_add_i64: if (c2) { - tcg_out_opc_addi_d(s, a0, a1, a2); + tcg_out_addi(s, TCG_TYPE_I64, a0, a1, a2); } else { tcg_out_opc_add_d(s, a0, a1, a2); } @@ -1365,14 +1404,14 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, case INDEX_op_sub_i32: if (c2) { - tcg_out_opc_addi_w(s, a0, a1, -a2); + tcg_out_addi(s, TCG_TYPE_I32, a0, a1, -a2); } else { tcg_out_opc_sub_w(s, a0, a1, a2); } break; case INDEX_op_sub_i64: if (c2) { - tcg_out_opc_addi_d(s, a0, a1, -a2); + tcg_out_addi(s, TCG_TYPE_I64, a0, a1, -a2); } else { tcg_out_opc_sub_d(s, a0, a1, a2); } @@ -1586,8 +1625,9 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) return C_O1_I2(r, r, ri); case INDEX_op_add_i32: + return C_O1_I2(r, r, ri); case INDEX_op_add_i64: - return C_O1_I2(r, r, rI); + return C_O1_I2(r, r, rJ); case INDEX_op_and_i32: case INDEX_op_and_i64: @@ -1616,8 +1656,9 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) return C_O1_I2(r, 0, rZ); case INDEX_op_sub_i32: + return C_O1_I2(r, rZ, ri); case INDEX_op_sub_i64: - return C_O1_I2(r, rZ, rN); + return C_O1_I2(r, rZ, rJ); case INDEX_op_mul_i32: case INDEX_op_mul_i64: From patchwork Wed Jan 18 01:11:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 643664 Delivered-To: patch@linaro.org Received: by 2002:a17:522:b9de:b0:4b9:b062:db3b with SMTP id fj30csp1489560pvb; Tue, 17 Jan 2023 17:12:15 -0800 (PST) X-Google-Smtp-Source: AMrXdXudLJLqMS3GefMBrxJ7p/FYquKVm589s9TFBu8tfRE7HWOQK7jEEkU7XpZWYF8XqowBNa96 X-Received: by 2002:ac8:5358:0:b0:3b6:6d85:8812 with SMTP id d24-20020ac85358000000b003b66d858812mr909296qto.40.1674004335402; Tue, 17 Jan 2023 17:12:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674004335; cv=none; d=google.com; s=arc-20160816; b=gX7/UYliV3th6N76CvJYgUfNxXBiY/W/ijXD0KrvSa7EbrvH5BeIEtwyyTZ2iNLJy/ qIx8/lzUUV0piJGeQiCrMLDrhshNMxp404ldX3fduaCBiAMBToDQGmB+rnJ9T6H5HPNT SR9XDZpGnhY/xbzcfI+/m1QcZc7MJnXNfU8Ll1QCquHgP4Fv64nXoHoQae2Db4TvFS9q OfynBQV5sVSYp4BOJn8+X6jy07491Xsq+IbAu1q+fFxTE41eYyV6jpoBEVVf+D8QH4o+ xh3/rG1sDcVh3w6Sgrs/IXBiFHvZgi8vQv9oD5NMns0ak4jSQP3VtOWppMS/iICygUeC 0SXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gExyabd9pGuUtJyQvwd0z6FyfSDRDLkdZQb2qbC5yco=; b=Zvrhh4FKuIcyD6VVrhGFVfUkfAg1FbwmyqanXlDI+OJKE40czB91p170mO72D1MzWS ZzfrrVDozq/A4azyaeW4sXS/B/Chn4VxNiM+gLHmv1hpvweXGs/3bn0vou/fJvDC1SyN ankAzV/e8UovHflrbIKO0PGMRMckG/BIfCx58VHhye/N7XAATRyyYT8PeSYgxkOUaTL5 hHbe++8owGBchzidoCIqfapvBc1WN2hSq9LMKpIhRaZda4GtfRI3vwxkrF59eMPDacEz f5iEr8wSREjBp+uE9idfPiQwErusCJEFP/Xas5meG+bFYYP4MwSqhG+Tg+0wxHiXS0v4 QebA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xOeBK20g; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ay8-20020a05622a228800b003b63546d524si3202384qtb.397.2023.01.17.17.12.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Jan 2023 17:12:15 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xOeBK20g; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHwzN-00024Z-OQ; Tue, 17 Jan 2023 20:11:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pHwzM-00023p-5s for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:40 -0500 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHwzK-0002FC-BA for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:39 -0500 Received: by mail-pj1-x1029.google.com with SMTP id y3-20020a17090a390300b00229add7bb36so653027pjb.4 for ; Tue, 17 Jan 2023 17:11:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gExyabd9pGuUtJyQvwd0z6FyfSDRDLkdZQb2qbC5yco=; b=xOeBK20givcp1kwuiZRvPzEWTDCETB5hhwsJntKrSPV+NF3LEHNArMoAzgj6UzWmVu 9hskHrQ7iTKnqw1Zu5Mswj1U4AkQBkKJxQobD0yFizVCF6n3Vy1rOHDscGhGd0ad2M0P R0kktujnZ6GCB5qxKU7poWcPKyiRYIpVCPmYEmYZzixpnjAFGTorD5Hzq9DZWpi/Onud nIi0ElXTpkFSuxbEfn8oO/Vr70ZcHAgXXF8GvC9pqJKjChx5FUfnhmEtKNunaiQNmt+L UmaVazj8OVxb5nIhbKa+YEgOi4HW1mBuUxKLUfIKMnm3ti1PH0Haz9L7c1nTov7ImtGv Ub9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gExyabd9pGuUtJyQvwd0z6FyfSDRDLkdZQb2qbC5yco=; b=3oFCGfeXONO1qxPp2xKVqjVlxNPMzdhrQH8hjYKfpF1QRI/8luhZowqH0j/tWaO5CE CGMtatsYzd+VYMlTedGBMCpGsWlddDdleLuIv+hyR5ro+kQpdfGx2MhldUf2OBU/heQN bp0jYp+Jcu7Gm4xsmF1qrcxVxSxH3jL2vpTjKgYchvEKJSyRJHXkVtLiQk+9Hj9yCcWj NbeLx9ZqF+sXH3tHNIbUJIYJuNVj1RtQR+kVYmHmygIqXSb83uOlIK5hEQ1zpd+/dC9k EmCBgC5jrd/fxV9USqwBEIrNE7nppNKPlj1IPlrWuhM6EFtfqn94YDHx8En46liwa4uQ l6HQ== X-Gm-Message-State: AFqh2kp8twRsuOA1cTkX6kdkV6ohDseKo5MLm4h3NHfE7E8F5tdur9jN toFmCk8l4igCXj9sueRqJK00aHA8e6EtRzGS X-Received: by 2002:a17:903:2289:b0:194:9290:fa6f with SMTP id b9-20020a170903228900b001949290fa6fmr7831031plh.25.1674004296913; Tue, 17 Jan 2023 17:11:36 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b0017ec1b1bf9fsm21660259plp.217.2023.01.17.17.11.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 17:11:36 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name Subject: [PATCH v2 07/10] tcg/loongarch64: Improve setcond expansion Date: Tue, 17 Jan 2023 15:11:20 -1000 Message-Id: <20230118011123.392823-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118011123.392823-1-richard.henderson@linaro.org> References: <20230118011123.392823-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1029.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Split out a helper function, tcg_out_setcond_int, which does not always produce the complete boolean result, but returns a set of flags to do so. Accept all int32_t as constant input, so that LE/GT can adjust the constant to LT. Signed-off-by: Richard Henderson Reviewed-by: WANG Xuerui --- tcg/loongarch64/tcg-target.c.inc | 165 +++++++++++++++++++++---------- 1 file changed, 115 insertions(+), 50 deletions(-) diff --git a/tcg/loongarch64/tcg-target.c.inc b/tcg/loongarch64/tcg-target.c.inc index 8cc6c5eec2..ccc1c0f392 100644 --- a/tcg/loongarch64/tcg-target.c.inc +++ b/tcg/loongarch64/tcg-target.c.inc @@ -469,64 +469,131 @@ static void tcg_out_clzctz(TCGContext *s, LoongArchInsn opc, tcg_out_opc_or(s, a0, TCG_REG_TMP0, a0); } -static void tcg_out_setcond(TCGContext *s, TCGCond cond, TCGReg ret, - TCGReg arg1, TCGReg arg2, bool c2) -{ - TCGReg tmp; +#define SETCOND_INV TCG_TARGET_NB_REGS +#define SETCOND_NEZ (SETCOND_INV << 1) +#define SETCOND_FLAGS (SETCOND_INV | SETCOND_NEZ) - if (c2) { - tcg_debug_assert(arg2 == 0); +static int tcg_out_setcond_int(TCGContext *s, TCGCond cond, TCGReg ret, + TCGReg arg1, tcg_target_long arg2, bool c2) +{ + int flags = 0; + + switch (cond) { + case TCG_COND_EQ: /* -> NE */ + case TCG_COND_GE: /* -> LT */ + case TCG_COND_GEU: /* -> LTU */ + case TCG_COND_GT: /* -> LE */ + case TCG_COND_GTU: /* -> LEU */ + cond = tcg_invert_cond(cond); + flags ^= SETCOND_INV; + break; + default: + break; } switch (cond) { - case TCG_COND_EQ: - if (c2) { - tmp = arg1; - } else { - tcg_out_opc_sub_d(s, ret, arg1, arg2); - tmp = ret; - } - tcg_out_opc_sltui(s, ret, tmp, 1); - break; - case TCG_COND_NE: - if (c2) { - tmp = arg1; - } else { - tcg_out_opc_sub_d(s, ret, arg1, arg2); - tmp = ret; - } - tcg_out_opc_sltu(s, ret, TCG_REG_ZERO, tmp); - break; - case TCG_COND_LT: - tcg_out_opc_slt(s, ret, arg1, arg2); - break; - case TCG_COND_GE: - tcg_out_opc_slt(s, ret, arg1, arg2); - tcg_out_opc_xori(s, ret, ret, 1); - break; case TCG_COND_LE: - tcg_out_setcond(s, TCG_COND_GE, ret, arg2, arg1, false); - break; - case TCG_COND_GT: - tcg_out_setcond(s, TCG_COND_LT, ret, arg2, arg1, false); - break; - case TCG_COND_LTU: - tcg_out_opc_sltu(s, ret, arg1, arg2); - break; - case TCG_COND_GEU: - tcg_out_opc_sltu(s, ret, arg1, arg2); - tcg_out_opc_xori(s, ret, ret, 1); - break; case TCG_COND_LEU: - tcg_out_setcond(s, TCG_COND_GEU, ret, arg2, arg1, false); + /* + * If we have a constant input, the most efficient way to implement + * LE is by adding 1 and using LT. Watch out for wrap around for LEU. + * We don't need to care for this for LE because the constant input + * is still constrained to int32_t, and INT32_MAX+1 is representable + * in the 64-bit temporary register. + */ + if (c2) { + if (cond == TCG_COND_LEU) { + /* unsigned <= -1 is true */ + if (arg2 == -1) { + tcg_out_movi(s, TCG_TYPE_REG, ret, !(flags & SETCOND_INV)); + return ret; + } + cond = TCG_COND_LTU; + } else { + cond = TCG_COND_LT; + } + arg2 += 1; + } else { + TCGReg tmp = arg2; + arg2 = arg1; + arg1 = tmp; + cond = tcg_swap_cond(cond); /* LE -> GE */ + cond = tcg_invert_cond(cond); /* GE -> LT */ + flags ^= SETCOND_INV; + } break; - case TCG_COND_GTU: - tcg_out_setcond(s, TCG_COND_LTU, ret, arg2, arg1, false); + default: break; + } + + switch (cond) { + case TCG_COND_NE: + flags |= SETCOND_NEZ; + if (!c2) { + tcg_out_opc_xor(s, ret, arg1, arg2); + } else if (arg2 == 0) { + ret = arg1; + } else if (arg2 >= 0 && arg2 <= 0xfff) { + tcg_out_opc_xori(s, ret, arg1, arg2); + } else { + tcg_out_addi(s, TCG_TYPE_REG, ret, arg1, -arg2); + } + break; + + case TCG_COND_LT: + case TCG_COND_LTU: + if (c2) { + if (arg2 >= -0x800 && arg2 <= 0x7ff) { + if (cond == TCG_COND_LT) { + tcg_out_opc_slti(s, ret, arg1, arg2); + } else { + tcg_out_opc_sltui(s, ret, arg1, arg2); + } + break; + } + tcg_out_movi(s, TCG_TYPE_REG, TCG_REG_TMP0, arg2); + arg2 = TCG_REG_TMP0; + } + if (cond == TCG_COND_LT) { + tcg_out_opc_slt(s, ret, arg1, arg2); + } else { + tcg_out_opc_sltu(s, ret, arg1, arg2); + } + break; + default: g_assert_not_reached(); break; } + + return ret | flags; +} + +static void tcg_out_setcond(TCGContext *s, TCGCond cond, TCGReg ret, + TCGReg arg1, tcg_target_long arg2, bool c2) +{ + int tmpflags = tcg_out_setcond_int(s, cond, ret, arg1, arg2, c2); + + if (tmpflags != ret) { + TCGReg tmp = tmpflags & ~SETCOND_FLAGS; + + switch (tmpflags & SETCOND_FLAGS) { + case SETCOND_INV: + /* Intermediate result is boolean: simply invert. */ + tcg_out_opc_xori(s, ret, tmp, 1); + break; + case SETCOND_NEZ: + /* Intermediate result is zero/non-zero: test != 0. */ + tcg_out_opc_sltu(s, ret, TCG_REG_ZERO, tmp); + break; + case SETCOND_NEZ | SETCOND_INV: + /* Intermediate result is zero/non-zero: test == 0. */ + tcg_out_opc_sltui(s, ret, tmp, 1); + break; + default: + g_assert_not_reached(); + } + } } /* @@ -1646,18 +1713,16 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) case INDEX_op_ctz_i64: return C_O1_I2(r, r, rW); - case INDEX_op_setcond_i32: - case INDEX_op_setcond_i64: - return C_O1_I2(r, r, rZ); - case INDEX_op_deposit_i32: case INDEX_op_deposit_i64: /* Must deposit into the same register as input */ return C_O1_I2(r, 0, rZ); case INDEX_op_sub_i32: + case INDEX_op_setcond_i32: return C_O1_I2(r, rZ, ri); case INDEX_op_sub_i64: + case INDEX_op_setcond_i64: return C_O1_I2(r, rZ, rJ); case INDEX_op_mul_i32: From patchwork Wed Jan 18 01:11:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 643667 Delivered-To: patch@linaro.org Received: by 2002:a17:522:b9de:b0:4b9:b062:db3b with SMTP id fj30csp1489699pvb; Tue, 17 Jan 2023 17:12:36 -0800 (PST) X-Google-Smtp-Source: AMrXdXuPwHMsanNVHDK5vidgKSx1LvspsI+os8LjbPItB71UGjTSKlK/CFMmzpGRrESavxf7KuSb X-Received: by 2002:a1f:5e4c:0:b0:3dd:fcae:155a with SMTP id s73-20020a1f5e4c000000b003ddfcae155amr2622126vkb.0.1674004356477; Tue, 17 Jan 2023 17:12:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674004356; cv=none; d=google.com; s=arc-20160816; b=xUHYtmACsDC7TUwZH9pdSw+2sd6/NerkVmkdQ/0vRPlZH/RMxzWfui7wMsLmc8QLxY lZQgr4HnzBfgPwJWQvVIv9NAHwOD5CxKvoZCFM9q0LjJtywow9WPeFCTDnQT3UWQjdj/ ccCr0QCJCJDOHqTIu00M2lSmlg7Bu7FmvuIkLD29S4zfZGaZ+J6JnvTlnlzMFwiaZtQv Kopzo7jcMN+o1qlV15BTYUKFRCrz874qFKh5sFaBw/WwRIry26g+FsEoiGakDD9DtfIJ VMG+iGaJOZzAyjU5ENa2t5lhwF3YSUBK93Q79MO8kcZTrHQ4iItCmAxxEQJ8+fDsh4vd EMvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=di6N0vCGrpxWgO4hD16WY7qQUgaqSSofB9q2lj/lJG4=; b=qGlpoHJcSm/dyZNRFbVvY77qM3jbyTB0hLqBPtXxNWfbyp2hIGaiedm1FvW4dtSolv u8YfEinUc6Jl25DHVnbW50+WeTpa1X8ICXZDlAp3zqPBTowsz4GBa71CqLwdmdgLg45I fla4jSK6+1t2mxauaDLRXb83G3ERj05dYF9fPm4WRWmNGhoijiczb/rNSJpqg2D5oSEt 7LgtGYNkjTyZ9aqnB8gjKuXbreOGmniuwMgu8lJDAPmVIfUE9PWmr+/mTxSbt0SBSMCr Nq1NN2Hj9+/KwMlrNpukjMNF2GDXbqLYdNTWja9eEPY3JtVlMl36eOYoa/ri7HPw5Mag cIFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tmIYp5OI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ow9-20020a05620a820900b006fa9e4de9c3si17896044qkn.408.2023.01.17.17.12.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Jan 2023 17:12:36 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tmIYp5OI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHwzO-00027F-Ga; Tue, 17 Jan 2023 20:11:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pHwzN-00024S-DH for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:41 -0500 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHwzL-0002FV-Nk for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:41 -0500 Received: by mail-pj1-x102e.google.com with SMTP id gz9-20020a17090b0ec900b002290bda1b07so635809pjb.1 for ; Tue, 17 Jan 2023 17:11:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=di6N0vCGrpxWgO4hD16WY7qQUgaqSSofB9q2lj/lJG4=; b=tmIYp5OIpIWHVYofD6pgKSZYCAKeY0nUi6RiH0NXATZfGILkug6rO0X2feiuT4386p ZYA7Sevznhv2b4ie8X2Y0VJXHO3R8VR1TfL0hyYK9k82XsEX1Ttn5JDk/483sdDx9Lx+ 3cNHH7ko7eODorOl1Lx2onFdBUyRHi0SP+xqKVl/oZIhZH7nUhOM2vOcAZZrdZijBfPe 9SIW3wiyPQFypdU9/CmxMT7p/fB8aMYauqAGZCzW62+0hxJyOCZEfQayl9MQxOvtpObs cNn9My7H1INYU2yoPWObXchjO1yUzelQ+xSoogqxuQzs+k95ZeTwpa1uNiguqamq3sv3 w7UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=di6N0vCGrpxWgO4hD16WY7qQUgaqSSofB9q2lj/lJG4=; b=MUF9l4nX9E6Q8hYAXGci4p0Nkd8LF9c88TePJGrsw1z5MReqHInkSPCTQPVywAEig5 CitNRcFF1LziHizhjY9IonE6FsMO98tx7bIGyB9VhgT0QQDaWSVTT31z3wK75boOX+eb p1ywCsippGk5zw40AI+Xkc4tpow3ezxs+lXQn6I2qS6ysjkV9m0zJnviKZ6pJWg/w+FV 2rbjiuPoH/CFX+paVfRUvw1XoilRXG8dO8rY5Ulty18zRSLKqHtapNaA4gkpQujl30Gb +rvloz3Ffof2Aft+VnU8Hmvdn2X3hcD9DNKo7+oiKoGjZGyAb9hryD+pslsTcFaSFb2N 8u7g== X-Gm-Message-State: AFqh2kpmghJNopKW66i/PDEOIY2LZ9mrB4LVpX3zThVF0aR3ERktxg/5 JR+d4N/dBsVBkILhhv89zW3GGZprC4GXPGdu X-Received: by 2002:a17:902:c1d2:b0:194:7400:7c14 with SMTP id c18-20020a170902c1d200b0019474007c14mr5792877plc.34.1674004298492; Tue, 17 Jan 2023 17:11:38 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b0017ec1b1bf9fsm21660259plp.217.2023.01.17.17.11.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 17:11:38 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name Subject: [PATCH v2 08/10] tcg/loongarch64: Implement movcond Date: Tue, 17 Jan 2023 15:11:21 -1000 Message-Id: <20230118011123.392823-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118011123.392823-1-richard.henderson@linaro.org> References: <20230118011123.392823-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Signed-off-by: Richard Henderson Reviewed-by: WANG Xuerui --- tcg/loongarch64/tcg-target-con-set.h | 1 + tcg/loongarch64/tcg-target.h | 4 ++-- tcg/loongarch64/tcg-target.c.inc | 33 ++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/tcg/loongarch64/tcg-target-con-set.h b/tcg/loongarch64/tcg-target-con-set.h index 7b5a7a3f5d..172c107289 100644 --- a/tcg/loongarch64/tcg-target-con-set.h +++ b/tcg/loongarch64/tcg-target-con-set.h @@ -31,3 +31,4 @@ C_O1_I2(r, 0, rZ) C_O1_I2(r, rZ, ri) C_O1_I2(r, rZ, rJ) C_O1_I2(r, rZ, rZ) +C_O1_I4(r, rZ, rJ, rZ, rZ) diff --git a/tcg/loongarch64/tcg-target.h b/tcg/loongarch64/tcg-target.h index 1c3e48d662..533a539ce9 100644 --- a/tcg/loongarch64/tcg-target.h +++ b/tcg/loongarch64/tcg-target.h @@ -97,7 +97,7 @@ typedef enum { #define TCG_TARGET_CALL_ARG_I64 TCG_CALL_ARG_NORMAL /* optional instructions */ -#define TCG_TARGET_HAS_movcond_i32 0 +#define TCG_TARGET_HAS_movcond_i32 1 #define TCG_TARGET_HAS_div_i32 1 #define TCG_TARGET_HAS_rem_i32 1 #define TCG_TARGET_HAS_div2_i32 0 @@ -133,7 +133,7 @@ typedef enum { #define TCG_TARGET_HAS_qemu_st8_i32 0 /* 64-bit operations */ -#define TCG_TARGET_HAS_movcond_i64 0 +#define TCG_TARGET_HAS_movcond_i64 1 #define TCG_TARGET_HAS_div_i64 1 #define TCG_TARGET_HAS_rem_i64 1 #define TCG_TARGET_HAS_div2_i64 0 diff --git a/tcg/loongarch64/tcg-target.c.inc b/tcg/loongarch64/tcg-target.c.inc index ccc1c0f392..29d75c80eb 100644 --- a/tcg/loongarch64/tcg-target.c.inc +++ b/tcg/loongarch64/tcg-target.c.inc @@ -596,6 +596,30 @@ static void tcg_out_setcond(TCGContext *s, TCGCond cond, TCGReg ret, } } +static void tcg_out_movcond(TCGContext *s, TCGCond cond, TCGReg ret, + TCGReg c1, tcg_target_long c2, bool const2, + TCGReg v1, TCGReg v2) +{ + int tmpflags = tcg_out_setcond_int(s, cond, TCG_REG_TMP0, c1, c2, const2); + TCGReg t; + + /* Standardize the test below to t != 0. */ + if (tmpflags & SETCOND_INV) { + t = v1, v1 = v2, v2 = t; + } + + t = tmpflags & ~SETCOND_FLAGS; + if (v1 == TCG_REG_ZERO) { + tcg_out_opc_masknez(s, ret, v2, t); + } else if (v2 == TCG_REG_ZERO) { + tcg_out_opc_maskeqz(s, ret, v1, t); + } else { + tcg_out_opc_masknez(s, TCG_REG_TMP2, v2, t); /* t ? 0 : v2 */ + tcg_out_opc_maskeqz(s, TCG_REG_TMP1, v1, t); /* t ? v1 : 0 */ + tcg_out_opc_or(s, ret, TCG_REG_TMP1, TCG_REG_TMP2); + } +} + /* * Branch helpers */ @@ -1538,6 +1562,11 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, tcg_out_setcond(s, args[3], a0, a1, a2, c2); break; + case INDEX_op_movcond_i32: + case INDEX_op_movcond_i64: + tcg_out_movcond(s, args[5], a0, a1, a2, c2, args[3], args[4]); + break; + case INDEX_op_ld8s_i32: case INDEX_op_ld8s_i64: tcg_out_ldst(s, OPC_LD_B, a0, a1, a2); @@ -1741,6 +1770,10 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) case INDEX_op_remu_i64: return C_O1_I2(r, rZ, rZ); + case INDEX_op_movcond_i32: + case INDEX_op_movcond_i64: + return C_O1_I4(r, rZ, rJ, rZ, rZ); + default: g_assert_not_reached(); } From patchwork Wed Jan 18 01:11:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 643670 Delivered-To: patch@linaro.org Received: by 2002:a17:522:b9de:b0:4b9:b062:db3b with SMTP id fj30csp1489978pvb; Tue, 17 Jan 2023 17:13:15 -0800 (PST) X-Google-Smtp-Source: AMrXdXsOKDZEhx/VTyfS8IzPgVql/go/BsvaIGnuQnAI9PDzpbhbQWR5SCBIGlNxRNwBVlO4jBlg X-Received: by 2002:a05:6214:5f8a:b0:534:ba67:47c5 with SMTP id ls10-20020a0562145f8a00b00534ba6747c5mr8468593qvb.48.1674004395426; Tue, 17 Jan 2023 17:13:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674004395; cv=none; d=google.com; s=arc-20160816; b=uXT8A41QTvXe+2dDJEFJdVZ61AloLDBVFEIwO8sPJn9JJhDBIZHnvykuRIcs+JyG6l rNSe4RMDnAbQyD7RtXmycpsAJUNwoqtDmh24OOB43n+iBOnytIVcrMaPOeRUMUEK1sCM QQ3IZ2YkKou1e28nFGD3aC+g7vsWy8Y71Jt3rZ/B8J8m0rEkGPWZbcPTtoiSi4JeLr/c vVa93lYNRIJTILqgWPFxI8oqs5jWkEStpS75YGdaxzwId3LjnxeoFvMlScaEyhjxG1Th DLKJM4m6TZ7fH6q92/3JNJOwka+VOyodtCaazMzeugGsaiu68UeynIehAtqskdDj2HOD 6TBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oe653jAwb+trclLqO5xizolsekcbMLByW/eiNLY2YMk=; b=eWloowgwxc4zribkDy9LA+jyrvvwfZDpyrB3mKKuvH8zGPFFYABpRRhnlF+lPyhvjS XDKVlup2t5uioQhteYaeQFYm0Mg65y6NcrH8xBnV9UkmkN0Xo7Rpvh1cxv9Oy2Um+bHB Vu4+c2m4X/9iY86ars2X1norLCsIgEmR/PvB7DPU/xvlY+oVijakMDpVvBEI43a9ftXN QL5IGgo+uBcte5Kl4dg9kHZaTo0Plwmbu5pG1L6/QQFSJxxe8ckScrYfKgRGRiP2z9p0 w2/ZFUSgyvAMt/yocQKbTp5nIaV0sRCfi2WmMjxWWnX2ubS6F2/Hx7I2YNMdZGM6BkrF ByUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=T8Ni+FSx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h13-20020a05620a284d00b006ee8f3ec6e3si19992346qkp.90.2023.01.17.17.13.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Jan 2023 17:13:15 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=T8Ni+FSx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHwzR-0002BN-Fn; Tue, 17 Jan 2023 20:11:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pHwzP-00028I-14 for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:43 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHwzN-0002Fl-B4 for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:42 -0500 Received: by mail-pl1-x630.google.com with SMTP id r21so3249119plg.13 for ; Tue, 17 Jan 2023 17:11:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oe653jAwb+trclLqO5xizolsekcbMLByW/eiNLY2YMk=; b=T8Ni+FSxd8awv/RgOySrM1axkRtVYW3VxzPhJ6km9unzqRLP1T/q8JqS7I19wG+r0Q zZe92g1lSnpPjTREUrx5g+azQXSZVBHVXgoMMlCAmtn2P5I1HycPvTBEXASuIQFBWou8 BTSRaFENSLVADRfZleKt1kNsKkRXzKrki+ZIuq9yv88OvEvGBx0brYPEy8ctHKJvC9Vh d8vz9sSS1NEWw40xk5ofZN1Q8jrdbc5JWL2AL52I2ai6fBnkAs6l1dpC3dIcQdR/JfT+ /lxiB1bVwH9e00DLDYXyHuZ0QUYwWdQZZP/ynRRC9bXAV7+dn0MwqDYVwbb7sh4UVAmQ iKAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oe653jAwb+trclLqO5xizolsekcbMLByW/eiNLY2YMk=; b=dfOcnMRGq5ilMBk2pgDzFD824riwxizanvNiszXd2IXasyl2IsWOoXbhdQbSDbpJ1j MJ73pdG+VobxDaL6btGJlKVn3bLZ2biXxIXNdxtqqUsYoRnf0eKyYzG5peqoCb0q7Oyh QF4CV12nlbEQhHMYZKki17g7J49az/hoyuEsfCbo5LuQt3UpjZzOb0axBfZw57QRvg87 9A0N9VBcEQKutVpdhMQTximCyC2236jxjwA5X798P5m5o09v72iL4OdS2Lfhn//C75M6 VSooa+YlHO/rj82eIEtXcz2sHIH/jKH7XGAeAQz2y+ae9z3h1/NdhPmzCh1NSUOrTlwp 4xxA== X-Gm-Message-State: AFqh2kpZB2zNHDpS2cvx/9rMiEasRLT0O5jk3UlOQjeZ1cl3csUBF30P Xxe/Eo20bD06iIzASfGpdFLKwLQqG8DOcxq3 X-Received: by 2002:a17:902:ab94:b0:194:62d9:9a86 with SMTP id f20-20020a170902ab9400b0019462d99a86mr5490670plr.59.1674004299900; Tue, 17 Jan 2023 17:11:39 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b0017ec1b1bf9fsm21660259plp.217.2023.01.17.17.11.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 17:11:39 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name Subject: [PATCH v2 09/10] tcg/loongarch64: Use tcg_pcrel_diff in tcg_out_ldst Date: Tue, 17 Jan 2023 15:11:22 -1000 Message-Id: <20230118011123.392823-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118011123.392823-1-richard.henderson@linaro.org> References: <20230118011123.392823-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Take the w^x split into account when computing the pc-relative distance to an absolute pointer. Signed-off-by: Richard Henderson Reviewed-by: WANG Xuerui Reviewed-by: Philippe Mathieu-Daudé --- tcg/loongarch64/tcg-target.c.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcg/loongarch64/tcg-target.c.inc b/tcg/loongarch64/tcg-target.c.inc index 29d75c80eb..d6926bdb83 100644 --- a/tcg/loongarch64/tcg-target.c.inc +++ b/tcg/loongarch64/tcg-target.c.inc @@ -702,7 +702,7 @@ static void tcg_out_ldst(TCGContext *s, LoongArchInsn opc, TCGReg data, intptr_t imm12 = sextreg(offset, 0, 12); if (offset != imm12) { - intptr_t diff = offset - (uintptr_t)s->code_ptr; + intptr_t diff = tcg_pcrel_diff(s, (void *)offset); if (addr == TCG_REG_ZERO && diff == (int32_t)diff) { imm12 = sextreg(diff, 0, 12); From patchwork Wed Jan 18 01:11:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 643666 Delivered-To: patch@linaro.org Received: by 2002:a17:522:b9de:b0:4b9:b062:db3b with SMTP id fj30csp1489666pvb; Tue, 17 Jan 2023 17:12:30 -0800 (PST) X-Google-Smtp-Source: AMrXdXt2hIHnFajzrYjPGwe3eV1hYDam3w1lFwQg4S1lw/7cwKBb76RQQq465pN6NZs/Bc7zIHUu X-Received: by 2002:ac8:47ca:0:b0:3a8:84f:1d3a with SMTP id d10-20020ac847ca000000b003a8084f1d3amr6216699qtr.9.1674004350463; Tue, 17 Jan 2023 17:12:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674004350; cv=none; d=google.com; s=arc-20160816; b=dJHeGXEWzUdKrYJ3MjjLuiKnxxdt9heAD7HEUh2SFVFjJZba6Z2b4OG0NYHhUD+yPa 7zs3wPbyE7uB1qbe/QabdyXRalKGwuNvEXaP7+RAzox/dtpHtarwuQoasrPntqgc1VRt KFcsVXf+53S38YWCdsAM/7hkx0bvgj9VMhqxXrCcFeDpNOACFbsDopkhxWagNlTCyfaC g8e8PVO+nMe2K+HyvV16W099CeV608ZUGBPoR5t09jSNXYQ/CQO4b4yH6VZKcQVelG71 B9JLA1XUEMZAEWaooHHv2ABCu/hVdPqkdL65JM1Bg/fAtWUfm9x0LdFFJlxftamH5KDw keWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ytAJL1IPjLRLHB3vJNA4P2zaPkmMQ8wgfVfWBQ9Mma4=; b=iYf6RnF8zo7H+OGzCeswhkZ0HgaGtAmmN1VJiaaZj5fOm/Q3UaCW2Ct8Fd8X8z8/Lf k3pjn2x5V2P2S+sWQmDmbvphTFrMPirqt/7FTTYUvvXH3HvcaVyHl0P5ns7kZmuIAVsO jEV1p5urM6HfBMUfHUEHwDBznSrQZ3vlNHW8PPtQRDfGRGpvanItcxq23oLsjQj5lgO/ hpSdYlg5XcEL3ZakQ7hWfOGFoP4gGEJZT364hclqolt57c+QE19K7o0p/cYsk8tFZxk6 z8EUsmSbq9kE0UmpejedWfYodF9KskwzVLg2lCgXprd+FHaSquv9H/zFNLmiXLoB1C/6 ZlLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KOb1kpEm; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v8-20020a05620a0a8800b006fee7e2a71esi5906363qkg.204.2023.01.17.17.12.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Jan 2023 17:12:30 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KOb1kpEm; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHwzS-0002BP-17; Tue, 17 Jan 2023 20:11:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pHwzQ-0002Au-H2 for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:44 -0500 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHwzO-0002Fv-OK for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:44 -0500 Received: by mail-pl1-x631.google.com with SMTP id d9so35315880pll.9 for ; Tue, 17 Jan 2023 17:11:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ytAJL1IPjLRLHB3vJNA4P2zaPkmMQ8wgfVfWBQ9Mma4=; b=KOb1kpEm2GplxDBXYq6B8uP0gY1w0nXw/C6X3A9FUahCjK0YPyRuq7C997NyJJGOxi xMKOmWfsOCdSWAW8uxCD16zHsCG1AlGEPHW1nV3H5EBAE8f0ZQlGLfEiVcBJTvknPzPp wT4oOXlHY+H8JiJtGbio9nAZA45/IGJizrSCQz5cSHMmy+os+WYptacIii7IdQ2PEbpR VkaitHwz6pJhj1IahiHjyKBQAL45ZPCpKk0/xAcD3TbZU1smDFBbXsNxQaIAtTp7sIm1 JivnqvvkN9+dU7/tpygJIIowZUXiy7dWX7N/87k/w+D/n9BrBMk8kpt4BYE1B0MKS90O A34w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ytAJL1IPjLRLHB3vJNA4P2zaPkmMQ8wgfVfWBQ9Mma4=; b=WKErP0sH/p7pZzWtzlx1I98XUny0rbKbFwtqowWpGbqQ90dXySBEgBLqAzrw01ichb PlyKcmo/a6vaAij7tgjomBXhg63n6GFtIwEJC1rUSxBYaIkP57T/zVy8jQZcmC+StZlz UWCUeQJ8TZmUPaQ5HNvXFtOM3kd56eK0WzaTn6/Y/bMgZ25TpaQ3/gRRbUty3VLXkL/N Zk4fRH+w3Ran+cgqSq/z/xLA4OWZ33FIO13eCdqnWmj05qmfMYu15891pde5itPSFnTl Fbl36og+wree40Yio2Gwd1BxsSamCs4/5Gx4PxnxgQdB49NL6whbxAYPcxozpQzEAb92 CDXQ== X-Gm-Message-State: AFqh2krCO+vZ+lrWFvfLbhHflhJ9+fKjN+7wTcJpud7aPpFjd37syAax fUCIAhhdi3AXox1s+lhNmNbvvAkWHW39aVhq X-Received: by 2002:a17:902:c409:b0:194:a854:6274 with SMTP id k9-20020a170902c40900b00194a8546274mr5761898plk.60.1674004301194; Tue, 17 Jan 2023 17:11:41 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b0017ec1b1bf9fsm21660259plp.217.2023.01.17.17.11.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 17:11:40 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name Subject: [PATCH v2 10/10] tcg/loongarch64: Reorg goto_tb implementation Date: Tue, 17 Jan 2023 15:11:23 -1000 Message-Id: <20230118011123.392823-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118011123.392823-1-richard.henderson@linaro.org> References: <20230118011123.392823-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org The old implementation replaces two insns, swapping between b nop and pcaddu18i tmp, jirl zero, tmp, & 0xffff There is a race condition in which a thread could be stopped at the jirl, i.e. with the top of the address loaded, and when restarted we have re-linked to a different TB, so that the top half no longer matches the bottom half. Note that while we never directly re-link to a different TB, we can link, unlink, and link again all while the stopped thread remains stopped. The new implementation replaces only one insn, swapping between b and pcadd tmp, falling through to load the address from tmp, and branch. Signed-off-by: Richard Henderson Reviewed-by: WANG Xuerui --- tcg/loongarch64/tcg-target.h | 7 +--- tcg/loongarch64/tcg-target.c.inc | 72 ++++++++++++++------------------ 2 files changed, 33 insertions(+), 46 deletions(-) diff --git a/tcg/loongarch64/tcg-target.h b/tcg/loongarch64/tcg-target.h index 533a539ce9..8b151e7f6f 100644 --- a/tcg/loongarch64/tcg-target.h +++ b/tcg/loongarch64/tcg-target.h @@ -42,11 +42,8 @@ #define TCG_TARGET_INSN_UNIT_SIZE 4 #define TCG_TARGET_NB_REGS 32 -/* - * PCADDU18I + JIRL sequence can give 20 + 16 + 2 = 38 bits - * signed offset, which is +/- 128 GiB. - */ -#define MAX_CODE_GEN_BUFFER_SIZE (128 * GiB) + +#define MAX_CODE_GEN_BUFFER_SIZE ((size_t)-1) typedef enum { TCG_REG_ZERO, diff --git a/tcg/loongarch64/tcg-target.c.inc b/tcg/loongarch64/tcg-target.c.inc index d6926bdb83..ce4a153887 100644 --- a/tcg/loongarch64/tcg-target.c.inc +++ b/tcg/loongarch64/tcg-target.c.inc @@ -1151,37 +1151,6 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args) #endif } -/* LoongArch uses `andi zero, zero, 0` as NOP. */ -#define NOP OPC_ANDI -static void tcg_out_nop(TCGContext *s) -{ - tcg_out32(s, NOP); -} - -void tb_target_set_jmp_target(const TranslationBlock *tb, int n, - uintptr_t jmp_rx, uintptr_t jmp_rw) -{ - tcg_insn_unit i1, i2; - ptrdiff_t upper, lower; - uintptr_t addr = tb->jmp_target_addr[n]; - ptrdiff_t offset = (ptrdiff_t)(addr - jmp_rx) >> 2; - - if (offset == sextreg(offset, 0, 26)) { - i1 = encode_sd10k16_insn(OPC_B, offset); - i2 = NOP; - } else { - tcg_debug_assert(offset == sextreg(offset, 0, 36)); - lower = (int16_t)offset; - upper = (offset - lower) >> 16; - - i1 = encode_dsj20_insn(OPC_PCADDU18I, TCG_REG_TMP0, upper); - i2 = encode_djsk16_insn(OPC_JIRL, TCG_REG_ZERO, TCG_REG_TMP0, lower); - } - uint64_t pair = ((uint64_t)i2 << 32) | i1; - qatomic_set((uint64_t *)jmp_rw, pair); - flush_idcache_range(jmp_rx, jmp_rw, 8); -} - /* * Entry-points */ @@ -1202,22 +1171,43 @@ static void tcg_out_exit_tb(TCGContext *s, uintptr_t a0) static void tcg_out_goto_tb(TCGContext *s, int which) { /* - * Ensure that patch area is 8-byte aligned so that an - * atomic write can be used to patch the target address. + * Direct branch, or load indirect address, to be patched + * by tb_target_set_jmp_target. Check indirect load offset + * in range early, regardless of direct branch distance, + * via assert within tcg_out_opc_pcaddu2i. */ - if ((uintptr_t)s->code_ptr & 7) { - tcg_out_nop(s); - } + uintptr_t i_addr = get_jmp_target_addr(s, which); + intptr_t i_disp = tcg_pcrel_diff(s, (void *)i_addr); + set_jmp_insn_offset(s, which); - /* - * actual branch destination will be patched by - * tb_target_set_jmp_target later - */ - tcg_out_opc_pcaddu18i(s, TCG_REG_TMP0, 0); + tcg_out_opc_pcaddu2i(s, TCG_REG_TMP0, i_disp >> 2); + + /* Finish the load and indirect branch. */ + tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_TMP0, TCG_REG_TMP0, 0); tcg_out_opc_jirl(s, TCG_REG_ZERO, TCG_REG_TMP0, 0); set_jmp_reset_offset(s, which); } +void tb_target_set_jmp_target(const TranslationBlock *tb, int n, + uintptr_t jmp_rx, uintptr_t jmp_rw) +{ + uintptr_t d_addr = tb->jmp_target_addr[n]; + ptrdiff_t d_disp = (ptrdiff_t)(d_addr - jmp_rx) >> 2; + tcg_insn_unit insn; + + /* Either directly branch, or load slot address for indirect branch. */ + if (d_disp == sextreg(d_disp, 0, 26)) { + insn = encode_sd10k16_insn(OPC_B, d_disp); + } else { + uintptr_t i_addr = (uintptr_t)&tb->jmp_target_addr[n]; + intptr_t i_disp = i_addr - jmp_rx; + insn = encode_dsj20_insn(OPC_PCADDU2I, TCG_REG_TMP0, i_disp >> 2); + } + + qatomic_set((tcg_insn_unit *)jmp_rw, insn); + flush_idcache_range(jmp_rx, jmp_rw, 4); +} + static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg args[TCG_MAX_OP_ARGS], const int const_args[TCG_MAX_OP_ARGS])