From patchwork Fri Oct 29 04:33:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 516429 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp427186iml; Thu, 28 Oct 2021 22:31:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOoF6R/D5ETQC48AqqQcTOcktrWcZLgYgvlqWZ0jqG/zk4WU8buxF9pWJ6jzfPYP2vff1f X-Received: by 2002:a05:6830:1d45:: with SMTP id p5mr6821792oth.119.1635485495757; Thu, 28 Oct 2021 22:31:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635485495; cv=none; d=google.com; s=arc-20160816; b=ACbzK2Bga1MCmg1T+dIcvnk0nlBLyOpKMRocSCIPszUH20qznZiFQV7hAYT3/ie3vh iNrFF/jc0EZBq4PGLnx+N8Jary9Gs+mTpTdwFi8Yt6dddR2CCWQi0o6aOdopvlKS56OC JD1z5g1F/XGitt0IxEd22VTLheJdqmQ7nVrVx63On1nyK3m8ERbEkSxQi+OyYO7fkjg9 Ov9K0n29EO/+ozbpFwcXdR7FMhhgWCZheosXBVOK0NOxP69Hxkx+gyVA22+kGmcr7oAa 1lG41ofFm6/GlK0QO8tMdVmPRlZ9pGvHBdUZzHOLRUiXD8wXgOQWDFWTmbQvIiDGI923 q3hQ== 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=sNZW+SE7IkpCycmJxNFsxBL0QVYPzgqHpcz72Yg09Ec=; b=f0APIRoEPMzzME7V5JqyWSnvvpDiX6BaH7nQZPSisNh/keqioOT2IiRl0z/spGcAZD Xg3dpyQ1PHj5ZIOr8SZolEKlqnS5FFo0GzTUtHcJLcf9fxdhVcadsFu7A80D9Q6bAcZr PSplr5wBf35T12WHbUX9Vxe3ZmcTdFkuezz4VidnMFVSpJBm+u4BE+mP3QjUI6Oxz5sA jp+1WslPrxjARdswaNeYZC9ND0aPtnqQCVynjJ0DibF4bibst4WGipSPVkGyOqMT1d1h 3lY4LA9KyxS3fz0pdDL/X26o0Fhn2+DU5ioJl1S8WTYBs2t+N7j5pxEv+NNKWfZ8gs6f hKTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=lbCBOdrg; 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 u37si7545415oiw.0.2021.10.28.22.31.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Oct 2021 22:31:35 -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=lbCBOdrg; 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]:42818 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mgKUJ-0006Gw-0s for patch@linaro.org; Fri, 29 Oct 2021 01:31:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52144) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mgJdl-0002X6-SW for qemu-devel@nongnu.org; Fri, 29 Oct 2021 00:37:17 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:44973) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mgJdd-0000MJ-Vk for qemu-devel@nongnu.org; Fri, 29 Oct 2021 00:37:16 -0400 Received: by mail-pj1-x102e.google.com with SMTP id oa12-20020a17090b1bcc00b0019f715462a8so6505538pjb.3 for ; Thu, 28 Oct 2021 21:37:08 -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=sNZW+SE7IkpCycmJxNFsxBL0QVYPzgqHpcz72Yg09Ec=; b=lbCBOdrgkyFMoy3VnaIexBjKaAO6WEZQQii25kdGJBAf08/8eo0MflE5nRWVdfyOrU mij4l2YeD59d2KYdcDwfVCXuWt5MmAspITTC3NcYvThNALnOFb2T9Ka3OtZ8zvKRUGAF eK8mH327pxEJFgQqMRer2r/JLXotvpKRjsgLPiJiZbpDMi+YDyxTnsxwEdE5ljAIOpDT gpvYiUgS2/5sVbDSqCHGAoGabsZa3R1uKCJmS4LWv+kNG0QIZq9EroASaAT0DpBUJpLm WMiEFuTpclLkhZloi3+76TrWF3chnj213Vfzc94DT8vjutTUL0Kua2uMIRfLDL2F429y P4tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sNZW+SE7IkpCycmJxNFsxBL0QVYPzgqHpcz72Yg09Ec=; b=L6H/nl+ChEa0Pj3mfWgJy+LxFJz1XH/kOGaIMyDvZ7Jzi9J968ms8om4HL9aZBYoYW qE6Xv1AISvjx3t7H6xodbk1arJ5vIG2wheBjIN8JkmPF1yob6bCFCFp8ZHkF3gqjrsHo 85IqMoHZkb8RabuiISZQPXbN5/xyjj73elXgoXbrkr1s+GS/z/OCwtUFe6eCXngNMweH L83DYrLxqIQiWXH8J4wGRWwDFL04b+G1UuG19s8dIvyEIDoxzQjXTRUIIxMvaBo6ZxDL bMXHLbJH1xLmYjBog8tOLHV1vOuDqbBtrasNlq9t/lLFCqE0HR4vPehUmhf/zi3M7e1o GJtQ== X-Gm-Message-State: AOAM531czkl6u/QZuWdonYyqXc01swWq8RodsKlTXyLzbxMYYrltjUJC mKOyARSTUju4AoRm6LK83CsAVIXhEnAM8w== X-Received: by 2002:a17:90b:4d0f:: with SMTP id mw15mr17391678pjb.207.1635482227756; Thu, 28 Oct 2021 21:37:07 -0700 (PDT) Received: from localhost.localdomain (174-21-75-75.tukw.qwest.net. [174.21.75.75]) by smtp.gmail.com with ESMTPSA id b8sm5228232pfv.56.2021.10.28.21.37.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 21:37:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL v2 45/60] tcg/optimize: Expand fold_addsub2_i32 to 64-bit ops Date: Thu, 28 Oct 2021 21:33:14 -0700 Message-Id: <20211029043329.1518029-46-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211029043329.1518029-1-richard.henderson@linaro.org> References: <20211029043329.1518029-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Rename to fold_addsub2. Use Int128 to implement the wider operation. Reviewed-by: Alex Bennée Reviewed-by: Luis Pires Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- tcg/optimize.c | 65 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 21 deletions(-) -- 2.25.1 diff --git a/tcg/optimize.c b/tcg/optimize.c index e2ecad2884..f723deaafe 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -24,6 +24,7 @@ */ #include "qemu/osdep.h" +#include "qemu/int128.h" #include "tcg/tcg-op.h" #include "tcg-internal.h" @@ -838,37 +839,59 @@ static bool fold_add(OptContext *ctx, TCGOp *op) return false; } -static bool fold_addsub2_i32(OptContext *ctx, TCGOp *op, bool add) +static bool fold_addsub2(OptContext *ctx, TCGOp *op, bool add) { if (arg_is_const(op->args[2]) && arg_is_const(op->args[3]) && arg_is_const(op->args[4]) && arg_is_const(op->args[5])) { - uint32_t al = arg_info(op->args[2])->val; - uint32_t ah = arg_info(op->args[3])->val; - uint32_t bl = arg_info(op->args[4])->val; - uint32_t bh = arg_info(op->args[5])->val; - uint64_t a = ((uint64_t)ah << 32) | al; - uint64_t b = ((uint64_t)bh << 32) | bl; + uint64_t al = arg_info(op->args[2])->val; + uint64_t ah = arg_info(op->args[3])->val; + uint64_t bl = arg_info(op->args[4])->val; + uint64_t bh = arg_info(op->args[5])->val; TCGArg rl, rh; - TCGOp *op2 = tcg_op_insert_before(ctx->tcg, op, INDEX_op_mov_i32); + TCGOp *op2; - if (add) { - a += b; + if (ctx->type == TCG_TYPE_I32) { + uint64_t a = deposit64(al, 32, 32, ah); + uint64_t b = deposit64(bl, 32, 32, bh); + + if (add) { + a += b; + } else { + a -= b; + } + + al = sextract64(a, 0, 32); + ah = sextract64(a, 32, 32); } else { - a -= b; + Int128 a = int128_make128(al, ah); + Int128 b = int128_make128(bl, bh); + + if (add) { + a = int128_add(a, b); + } else { + a = int128_sub(a, b); + } + + al = int128_getlo(a); + ah = int128_gethi(a); } rl = op->args[0]; rh = op->args[1]; - tcg_opt_gen_movi(ctx, op, rl, (int32_t)a); - tcg_opt_gen_movi(ctx, op2, rh, (int32_t)(a >> 32)); + + /* The proper opcode is supplied by tcg_opt_gen_mov. */ + op2 = tcg_op_insert_before(ctx->tcg, op, 0); + + tcg_opt_gen_movi(ctx, op, rl, al); + tcg_opt_gen_movi(ctx, op2, rh, ah); return true; } return false; } -static bool fold_add2_i32(OptContext *ctx, TCGOp *op) +static bool fold_add2(OptContext *ctx, TCGOp *op) { - return fold_addsub2_i32(ctx, op, true); + return fold_addsub2(ctx, op, true); } static bool fold_and(OptContext *ctx, TCGOp *op) @@ -1725,9 +1748,9 @@ static bool fold_sub(OptContext *ctx, TCGOp *op) return false; } -static bool fold_sub2_i32(OptContext *ctx, TCGOp *op) +static bool fold_sub2(OptContext *ctx, TCGOp *op) { - return fold_addsub2_i32(ctx, op, false); + return fold_addsub2(ctx, op, false); } static bool fold_tcg_ld(OptContext *ctx, TCGOp *op) @@ -1873,8 +1896,8 @@ void tcg_optimize(TCGContext *s) CASE_OP_32_64_VEC(add): done = fold_add(&ctx, op); break; - case INDEX_op_add2_i32: - done = fold_add2_i32(&ctx, op); + CASE_OP_32_64(add2): + done = fold_add2(&ctx, op); break; CASE_OP_32_64_VEC(and): done = fold_and(&ctx, op); @@ -2011,8 +2034,8 @@ void tcg_optimize(TCGContext *s) CASE_OP_32_64_VEC(sub): done = fold_sub(&ctx, op); break; - case INDEX_op_sub2_i32: - done = fold_sub2_i32(&ctx, op); + CASE_OP_32_64(sub2): + done = fold_sub2(&ctx, op); break; CASE_OP_32_64_VEC(xor): done = fold_xor(&ctx, op);