From patchwork Tue Aug 17 21:17:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 498125 Delivered-To: patch@linaro.org Received: by 2002:a02:a11a:0:0:0:0:0 with SMTP id f26csp3001168jag; Tue, 17 Aug 2021 14:19:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtVFriWdR82d73U60EXEy/g62PVb5LfBAp4mMj5gLqjwykgH0iICS8tFVFJeXvh3vqddZU X-Received: by 2002:a05:620a:204e:: with SMTP id d14mr5936217qka.147.1629235153890; Tue, 17 Aug 2021 14:19:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629235153; cv=none; d=google.com; s=arc-20160816; b=RWzNPbxBRujU4MrgGYN+5KEH+CqepKp2PiDa2wK2G6DWWLrVO4TvgkiV4mxCheqnKR TeVE5pVpHdxweNr1aPM8eYhIW3XgoiAA/QI61EL8eIkR/PVWpvGHdS2nnAke4qTdysE5 tKRMwb5T8HLD05k/ojKbf3yyTZe7Ehuy4nONqowojXpcB4xd4258QG5puJj+XdzHqOy2 jJOh3R+8ukpE2pdzoPkn1beJtmSBMD1fWXIzzfGwP9XFkGb+tEimmmjgRiDUvHZMbE8f 76TI0SSg/ZPDjyh8fCAP1ngNfRVcogqaJPOIE+qkPBXnyGDkwvpJwzisOES1amRdwQ6U NMAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from :dkim-signature; bh=2Xc3Px5ShBpZaeyehmX8yBaiKpHgzNYihXevPMdNzj8=; b=t3aft+LuGRrsc9IGlo/1JuNDC3jjTK4xk8NwVdb4um4vy6AfZv0CEzu6FlkbRx7kuq yVXjVVRtwtw5EYkUsH8LezoebGNPGYrNYp6v0FQ8pua6OI6GH7afcUuOpj96znefk4Ku mltKE6UpxCOMnxdBPF3ytIH67svu/+pfnwAKnQphwlMd0prVzZRlyL/1M/gUSO3HEj3M 4eUMMwpNKit7s3UV+f1Y5PmQt+3yXmpmr1pSPsbxAn9ubA7fvVzf3Lj/N6FaMjwRSh/K zqsfR49+pVJNnNf5sxgJZMOlYxfFLrev+lDL6JHTKpLO4LrOrlDdHtcWTYMoEmoz9AyL oVaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=IIC04dDz; 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=fail (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 d9si1623594qti.182.2021.08.17.14.19.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Aug 2021 14:19:13 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=IIC04dDz; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:40000 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mG6UL-000160-76 for patch@linaro.org; Tue, 17 Aug 2021 17:19:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43336) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mG6TP-0000wS-JV for qemu-devel@nongnu.org; Tue, 17 Aug 2021 17:18:15 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:37732) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mG6TM-00011G-0k for qemu-devel@nongnu.org; Tue, 17 Aug 2021 17:18:15 -0400 Received: by mail-pj1-x1035.google.com with SMTP id cp15-20020a17090afb8fb029017891959dcbso7507780pjb.2 for ; Tue, 17 Aug 2021 14:18:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2Xc3Px5ShBpZaeyehmX8yBaiKpHgzNYihXevPMdNzj8=; b=IIC04dDz4BEnCGXCfZTBuDM9mXne/xrtXazzb+WEi87GFK7XhWmYpi+Fv5RjcU806m OJoxM8uMX4O3WLHh0VOhC3Ls06eDBoGLRPEL5bilINJ/mE4Ac+0wYojpOAuizZj6+A17 +S+jnFY1RrY2qp8gxRGWC6l1YS57gnfLXOXQc/HoYpJAmeH8uUpg0BqJ3WmXwuFlZLwD w1w2HT+pDf5ZJtazdp+seQsN5btb7n8ph7xoX3Rb6+QCKB8/SH0EfsLRyQ9NAPq3d2xb smecWiEtNgqMQWwJ4pkLTKOnf32yg0KKHqVvVWtFKBsXIke/Ehb6/CbV6yeXJpjt/UPG Pw3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2Xc3Px5ShBpZaeyehmX8yBaiKpHgzNYihXevPMdNzj8=; b=eqSi9ZJuffmR/NtrXKPnGRdPfs/ATbJnbMMHSwSGjvrknTBYurqKUqiPsbmypgGx/g Su8WEmFsUleUpuk83htK4RzUpIn6UVZZiNe338LkvPf8k4C/2hSoXeHq4bgHhYzgVovZ flM98ucNQgdYb9DPFgTCDbCnQQ/OH0ur/MBgG7ehGhq/UflKNMd95UIbo4tciyoENbmy 6Uxq6u9vIQI8LcBhziXmwsjTy7YbraEcZT8fl1Od1fWv8W8CRzr1Esej0frw1BA41wx7 HWE4nsbqhSTjf6yj+CAGfARCwKhpyJn705mc4c6pBdZnF+qFzJl2Y3srKb2Rim4fSdUc N3Ew== X-Gm-Message-State: AOAM531CMGvY20yKHSUsEqLJtLK/eVDmDGHrR/TW31+3G0boYA6J0lJG h60UIymN8crJdYPyQGRB7V5TnbOxKsPlTg== X-Received: by 2002:a17:903:1cb:b0:12d:b9c8:4e22 with SMTP id e11-20020a17090301cb00b0012db9c84e22mr4335930plh.42.1629235090599; Tue, 17 Aug 2021 14:18:10 -0700 (PDT) Received: from localhost.localdomain ([173.197.107.15]) by smtp.gmail.com with ESMTPSA id q1sm2978637pjl.44.2021.08.17.14.18.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 14:18:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 02/21] target/riscv: Clean up division helpers Date: Tue, 17 Aug 2021 11:17:44 -1000 Message-Id: <20210817211803.283639-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210817211803.283639-1-richard.henderson@linaro.org> References: <20210817211803.283639-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1035.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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alistair.Francis@wdc.com, bin.meng@windriver.com, qemu-riscv@nongnu.org, zhiwei_liu@c-sky.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Utilize the condition in the movcond more; this allows some of the setcond that were feeding into movcond to be removed. Do not write into source1 and source2. Re-name "condN" to "tempN" and use the temporaries for more than holding conditions. Signed-off-by: Richard Henderson --- target/riscv/translate.c | 137 +++++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 72 deletions(-) -- 2.25.1 diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 20a55c92fb..6ae7e140d0 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -213,106 +213,99 @@ static void gen_mulhsu(TCGv ret, TCGv arg1, TCGv arg2) static void gen_div(TCGv ret, TCGv source1, TCGv source2) { - TCGv cond1, cond2, zeroreg, resultopt1; + TCGv temp1, temp2, zero, one, mone, min; + /* * Handle by altering args to tcg_gen_div to produce req'd results: - * For overflow: want source1 in source1 and 1 in source2 - * For div by zero: want -1 in source1 and 1 in source2 -> -1 result + * For overflow: want source1 in temp1 and 1 in temp2 + * For div by zero: want -1 in temp1 and 1 in temp2 -> -1 result */ - cond1 = tcg_temp_new(); - cond2 = tcg_temp_new(); - zeroreg = tcg_constant_tl(0); - resultopt1 = tcg_temp_new(); + temp1 = tcg_temp_new(); + temp2 = tcg_temp_new(); + zero = tcg_constant_tl(0); + one = tcg_constant_tl(1); + mone = tcg_constant_tl(-1); + min = tcg_constant_tl(1ull << (TARGET_LONG_BITS - 1)); + + tcg_gen_setcond_tl(TCG_COND_EQ, temp2, source2, mone); + tcg_gen_setcond_tl(TCG_COND_EQ, temp1, source1, min); + tcg_gen_and_tl(temp1, temp1, temp2); /* temp1 = overflow */ + tcg_gen_setcond_tl(TCG_COND_EQ, temp2, source2, zero); /* temp2 = div0 */ + tcg_gen_or_tl(temp2, temp2, temp1); /* temp2 = overflow | div0 */ - tcg_gen_movi_tl(resultopt1, (target_ulong)-1); - tcg_gen_setcondi_tl(TCG_COND_EQ, cond2, source2, (target_ulong)(~0L)); - tcg_gen_setcondi_tl(TCG_COND_EQ, cond1, source1, - ((target_ulong)1) << (TARGET_LONG_BITS - 1)); - tcg_gen_and_tl(cond1, cond1, cond2); /* cond1 = overflow */ - tcg_gen_setcondi_tl(TCG_COND_EQ, cond2, source2, 0); /* cond2 = div 0 */ /* if div by zero, set source1 to -1, otherwise don't change */ - tcg_gen_movcond_tl(TCG_COND_EQ, source1, cond2, zeroreg, source1, - resultopt1); - /* if overflow or div by zero, set source2 to 1, else don't change */ - tcg_gen_or_tl(cond1, cond1, cond2); - tcg_gen_movi_tl(resultopt1, (target_ulong)1); - tcg_gen_movcond_tl(TCG_COND_EQ, source2, cond1, zeroreg, source2, - resultopt1); - tcg_gen_div_tl(ret, source1, source2); + tcg_gen_movcond_tl(TCG_COND_NE, temp1, source2, zero, source1, mone); - tcg_temp_free(cond1); - tcg_temp_free(cond2); - tcg_temp_free(resultopt1); + /* if overflow or div by zero, set source2 to 1, else don't change */ + tcg_gen_movcond_tl(TCG_COND_EQ, temp2, temp2, zero, source2, one); + + tcg_gen_div_tl(ret, temp1, temp2); + + tcg_temp_free(temp1); + tcg_temp_free(temp2); } static void gen_divu(TCGv ret, TCGv source1, TCGv source2) { - TCGv cond1, zeroreg, resultopt1; - cond1 = tcg_temp_new(); + TCGv temp1, temp2, zero, one, mone; - zeroreg = tcg_constant_tl(0); - resultopt1 = tcg_temp_new(); + temp1 = tcg_temp_new(); + temp2 = tcg_temp_new(); + zero = tcg_constant_tl(0); + one = tcg_constant_tl(1); + mone = tcg_constant_tl(-1); - tcg_gen_setcondi_tl(TCG_COND_EQ, cond1, source2, 0); - tcg_gen_movi_tl(resultopt1, (target_ulong)-1); - tcg_gen_movcond_tl(TCG_COND_EQ, source1, cond1, zeroreg, source1, - resultopt1); - tcg_gen_movi_tl(resultopt1, (target_ulong)1); - tcg_gen_movcond_tl(TCG_COND_EQ, source2, cond1, zeroreg, source2, - resultopt1); - tcg_gen_divu_tl(ret, source1, source2); + tcg_gen_movcond_tl(TCG_COND_NE, temp1, source2, zero, source1, mone); + tcg_gen_movcond_tl(TCG_COND_NE, temp2, source2, zero, source2, one); + tcg_gen_divu_tl(ret, temp1, temp2); - tcg_temp_free(cond1); - tcg_temp_free(resultopt1); + tcg_temp_free(temp1); + tcg_temp_free(temp2); } static void gen_rem(TCGv ret, TCGv source1, TCGv source2) { - TCGv cond1, cond2, zeroreg, resultopt1; + TCGv temp1, temp2, zero, one, mone, min; - cond1 = tcg_temp_new(); - cond2 = tcg_temp_new(); - zeroreg = tcg_constant_tl(0); - resultopt1 = tcg_temp_new(); + temp1 = tcg_temp_new(); + temp2 = tcg_temp_new(); + zero = tcg_constant_tl(0); + one = tcg_constant_tl(1); + mone = tcg_constant_tl(-1); + min = tcg_constant_tl(1ull << (TARGET_LONG_BITS - 1)); + + tcg_gen_setcond_tl(TCG_COND_EQ, temp2, source2, mone); + tcg_gen_setcond_tl(TCG_COND_EQ, temp1, source1, min); + tcg_gen_and_tl(temp1, temp1, temp2); /* temp1 = overflow */ + tcg_gen_setcondi_tl(TCG_COND_EQ, temp2, source2, 0); /* temp2 = div0 */ + tcg_gen_or_tl(temp2, temp2, temp1); /* temp2 = overflow | div0 */ - tcg_gen_movi_tl(resultopt1, 1L); - tcg_gen_setcondi_tl(TCG_COND_EQ, cond2, source2, (target_ulong)-1); - tcg_gen_setcondi_tl(TCG_COND_EQ, cond1, source1, - (target_ulong)1 << (TARGET_LONG_BITS - 1)); - tcg_gen_and_tl(cond2, cond1, cond2); /* cond1 = overflow */ - tcg_gen_setcondi_tl(TCG_COND_EQ, cond1, source2, 0); /* cond2 = div 0 */ /* if overflow or div by zero, set source2 to 1, else don't change */ - tcg_gen_or_tl(cond2, cond1, cond2); - tcg_gen_movcond_tl(TCG_COND_EQ, source2, cond2, zeroreg, source2, - resultopt1); - tcg_gen_rem_tl(resultopt1, source1, source2); - /* if div by zero, just return the original dividend */ - tcg_gen_movcond_tl(TCG_COND_EQ, ret, cond1, zeroreg, resultopt1, - source1); + tcg_gen_movcond_tl(TCG_COND_EQ, temp2, temp2, zero, source2, one); + tcg_gen_rem_tl(temp1, temp1, temp2); - tcg_temp_free(cond1); - tcg_temp_free(cond2); - tcg_temp_free(resultopt1); + /* if div by zero, just return the original dividend */ + tcg_gen_movcond_tl(TCG_COND_NE, ret, source2, zero, temp1, source1); + + tcg_temp_free(temp1); + tcg_temp_free(temp2); } static void gen_remu(TCGv ret, TCGv source1, TCGv source2) { - TCGv cond1, zeroreg, resultopt1; - cond1 = tcg_temp_new(); - zeroreg = tcg_constant_tl(0); - resultopt1 = tcg_temp_new(); + TCGv temp2, zero, one; + + temp2 = tcg_temp_new(); + zero = tcg_constant_tl(0); + one = tcg_constant_tl(1); + + tcg_gen_movcond_tl(TCG_COND_EQ, temp2, source2, zero, source2, one); + tcg_gen_remu_tl(temp2, source1, temp2); - tcg_gen_movi_tl(resultopt1, (target_ulong)1); - tcg_gen_setcondi_tl(TCG_COND_EQ, cond1, source2, 0); - tcg_gen_movcond_tl(TCG_COND_EQ, source2, cond1, zeroreg, source2, - resultopt1); - tcg_gen_remu_tl(resultopt1, source1, source2); /* if div by zero, just return the original dividend */ - tcg_gen_movcond_tl(TCG_COND_EQ, ret, cond1, zeroreg, resultopt1, - source1); + tcg_gen_movcond_tl(TCG_COND_NE, ret, source2, zero, temp2, source1); - tcg_temp_free(cond1); - tcg_temp_free(resultopt1); + tcg_temp_free(temp2); } static void gen_jal(DisasContext *ctx, int rd, target_ulong imm)