From patchwork Wed Nov 1 04:11:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 740050 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp97186wrv; Tue, 31 Oct 2023 21:14:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEpRV2vJteeY8BHKavQhq5/Y9zCajId+PxEMDz4nbXd8JlSkR9bkMOKCeNdkYgDdcYTvujx X-Received: by 2002:a05:620a:4395:b0:778:909b:58c8 with SMTP id a21-20020a05620a439500b00778909b58c8mr13753917qkp.78.1698812085130; Tue, 31 Oct 2023 21:14:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698812085; cv=none; d=google.com; s=arc-20160816; b=WAh7KLr3h7YRLBxQCF66AVymmpVfq0divKVE693pxHkUvsiYMqSl4ziHztevVAUqyR 0p7r5tzeFNyd+F0PRABuLeKExRapfSIIEfdaQ4+NTd3O7v6lbrvzJ4zb4aukmUEiZbY6 NattXRI2liT8d0wMWqQkClBA1/ZaFAPb2kZ36NlDdTQIDpy4A5Lu8mJSTveN6zbEIkYa EnHoAl1nbd35tDp8BjFSCr2H2YMYZxqDqD6RNp2W3KNtcw0CWr2SqFMOvWlQTDhtF22x 4ILA5E7pelNYxhN9nOMSIJOo1rW3grLyPIHIWLcDWblB1jcCyTE2tE+fWgtcQ6oMRvDQ d0ww== 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=WoN9b5fh20ESPQ7+DOAGdQCWDLjSgxnA1EgnSGB/k3Q=; fh=TYrED6TOMxGX0VC4GtjviASLbYyJe19+7/tKWjN44KQ=; b=v58Ynhh07hZaMiCtra+2ZWNnYeSD+Ol+pyR7/4/EpMp1/ggC1q0r+yEqOeHD1Pi8B2 W6XmXMf1gEeXDJ96T8qfi6uJO2UOchlo2bQJN4SYtaEmcxLhBhCva1l1iu0w6a9uhOfz B00TypXkkczqN24rsdj4CZa/n1qSMJl91gJN7qXTrhmIfa2/MD3mNuVZY1uSix1rjOvy LJccMCBE6dMXiD7X6SuZRzJ9SXyX0l/dKCawC+RUXHcZw8zncE6y9f/bcRGDD0LoVNWk ZRh/nOpwTfJlMeGpfOe7En2MrJiTmtOgTs3k/hw4CuRqhiIEOQjgESvYzWaGnmq2KKTY UnGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yhgo2Oxd; 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 h12-20020a05620a13ec00b0076dbec5d9a0si1997939qkl.710.2023.10.31.21.14.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 31 Oct 2023 21:14:45 -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=pass header.i=@linaro.org header.s=google header.b=yhgo2Oxd; 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 1qy2aD-0005zW-C8; Wed, 01 Nov 2023 00:11:57 -0400 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 1qy2a9-0005yC-Uw for qemu-devel@nongnu.org; Wed, 01 Nov 2023 00:11:54 -0400 Received: from mail-oi1-x229.google.com ([2607:f8b0:4864:20::229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qy2a8-0007aQ-7R for qemu-devel@nongnu.org; Wed, 01 Nov 2023 00:11:53 -0400 Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-3add37de892so3263362b6e.1 for ; Tue, 31 Oct 2023 21:11:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698811911; x=1699416711; darn=nongnu.org; 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=WoN9b5fh20ESPQ7+DOAGdQCWDLjSgxnA1EgnSGB/k3Q=; b=yhgo2OxdUXjzPf5e2PfRhbkBnxMSB/rz10xVTrzQPsGY83txcNC04qxBjg1SFYX4W4 EOy24qjiNLxa5ddKbX7//StYqcY7HEfZo2AxcmkXDUJikf4r0QTTDxCp8dxtrj0fu9sS vZHXlKI2er08hmjBhZNOX1xRMCDv7A+yRgxqpF5khh6k6rT/WoZE9dc9f5ulyXgUSq5K 0qzjUHcNGIeXzAH11H46/isbFhy5wGzmxxVqpbWCQ7DJLddPSfq8gLlFk8QRvUOclpcc lT+XBLqrr8tAjXqkwB++nVlISJgdKfkUjxJ9t/OwDOM8JcUzcBKoVHaGoZwJM8b/yH3w x3Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698811911; x=1699416711; 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=WoN9b5fh20ESPQ7+DOAGdQCWDLjSgxnA1EgnSGB/k3Q=; b=lXPcI7hDRUANElgRFJl3Kow83EDXsYmVtmA6QRDg1lbMOynYbHXn1lsdtovnCQ6wGZ DKaZKSClm3tDdcSpwE9isQ+GqRquLvod9MsXzf42GM7oBn4Wzf6j+wv9N3r/qEfEWs/3 82YCPkvlLIa8Iw3PczG2YKMEaAR3JlQN33rLMJ+J4OKbGx7be5rdszbQDO9m6hBYbV8K MDPykwV4IAJHEbwU+jkRZ8VYf109jU3pOlm9ChPFrH4BAfbC36Bftob/y/4UiNRt8ybi m6IeDviHsbER4KfhHR/H+OvMzHdXC1Rw2OUP3GJtlCUE61j2uzGsCFLQPLXsKCq3xI94 84YQ== X-Gm-Message-State: AOJu0YzM2L0PjQj5MqA6WRIDdTQ396eDTyrOd71dR/lj0AvetGDDLndg +u5YhFd3TxP3G1bJonqG7ei1A5SOawp5LVJjFhg= X-Received: by 2002:a05:6808:209f:b0:3ad:fe8d:dfae with SMTP id s31-20020a056808209f00b003adfe8ddfaemr14971479oiw.57.1698811910839; Tue, 31 Oct 2023 21:11:50 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id k8-20020aa79728000000b006875df4773fsm359576pfg.163.2023.10.31.21.11.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 21:11:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mark.cave-ayland@ilande.co.uk Subject: [PATCH v2 20/21] target/sparc: Implement UDIV inline Date: Tue, 31 Oct 2023 21:11:31 -0700 Message-Id: <20231101041132.174501-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231101041132.174501-1-richard.henderson@linaro.org> References: <20231101041132.174501-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::229; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x229.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, T_SCC_BODY_TEXT_LINE=-0.01 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 --- target/sparc/insns.decode | 3 +- target/sparc/translate.c | 67 +++++++++++++++++++++++++++++++-------- 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/target/sparc/insns.decode b/target/sparc/insns.decode index 52f54b87cc..2d26404cb2 100644 --- a/target/sparc/insns.decode +++ b/target/sparc/insns.decode @@ -184,7 +184,8 @@ MULScc 10 ..... 100100 ..... . ............. @r_r_ri_cc1 UDIVX 10 ..... 001101 ..... . ............. @r_r_ri SDIVX 10 ..... 101101 ..... . ............. @r_r_ri -UDIV 10 ..... 0.1110 ..... . ............. @r_r_ri_cc +UDIV 10 ..... 001110 ..... . ............. @r_r_ri +UDIVcc 10 ..... 011110 ..... . ............. @r_r_ri_cc1 SDIV 10 ..... 0.1111 ..... . ............. @r_r_ri_cc TADDcc 10 ..... 100000 ..... . ............. @r_r_ri_cc1 diff --git a/target/sparc/translate.c b/target/sparc/translate.c index 95cc4c71f4..4b7d943bae 100644 --- a/target/sparc/translate.c +++ b/target/sparc/translate.c @@ -577,18 +577,6 @@ static void gen_op_smul(TCGv dst, TCGv src1, TCGv src2) gen_op_multiply(dst, src1, src2, 1); } -static void gen_op_udiv(TCGv dst, TCGv src1, TCGv src2) -{ -#ifdef TARGET_SPARC64 - gen_helper_udiv(dst, tcg_env, src1, src2); - tcg_gen_ext32u_tl(dst, dst); -#else - TCGv_i64 t64 = tcg_temp_new_i64(); - gen_helper_udiv(t64, tcg_env, src1, src2); - tcg_gen_trunc_i64_tl(dst, t64); -#endif -} - static void gen_op_sdiv(TCGv dst, TCGv src1, TCGv src2) { #ifdef TARGET_SPARC64 @@ -3568,7 +3556,7 @@ TRANS(UMUL, MUL, do_logic, a, gen_op_umul, NULL) TRANS(SMUL, MUL, do_logic, a, gen_op_smul, NULL) TRANS(MULScc, ALL, do_arith, a, NULL, NULL, gen_op_mulscc) -TRANS(UDIV, DIV, do_arith, a, gen_op_udiv, NULL, gen_op_udivcc) +TRANS(UDIVcc, DIV, do_arith, a, NULL, NULL, gen_op_udivcc) TRANS(SDIV, DIV, do_arith, a, gen_op_sdiv, NULL, gen_op_sdivcc) /* TODO: Should have feature bit -- comes in with UltraSparc T2. */ @@ -3591,6 +3579,59 @@ static bool trans_OR(DisasContext *dc, arg_r_r_ri_cc *a) return do_logic(dc, a, tcg_gen_or_tl, tcg_gen_ori_tl); } +static bool trans_UDIV(DisasContext *dc, arg_r_r_ri *a) +{ + TCGv_i64 t1, t2; + TCGv dst; + + if (!avail_DIV(dc)) { + return false; + } + /* For simplicity, we under-decoded the rs2 form. */ + if (!a->imm && a->rs2_or_imm & ~0x1f) { + return false; + } + + if (unlikely(a->rs2_or_imm == 0)) { + gen_exception(dc, TT_DIV_ZERO); + return true; + } + + if (a->imm) { + t2 = tcg_constant_i64((uint32_t)a->rs2_or_imm); + } else { + TCGLabel *lab; + TCGv_i32 n2; + + finishing_insn(dc); + flush_cond(dc); + + n2 = tcg_temp_new_i32(); + tcg_gen_trunc_tl_i32(n2, cpu_regs[a->rs2_or_imm]); + + lab = delay_exception(dc, TT_DIV_ZERO); + tcg_gen_brcondi_i32(TCG_COND_EQ, n2, 0, lab); + + t2 = tcg_temp_new_i64(); +#ifdef TARGET_SPARC64 + tcg_gen_ext32u_i64(t2, cpu_regs[a->rs2_or_imm]); +#else + tcg_gen_extu_i32_i64(t2, cpu_regs[a->rs2_or_imm]); +#endif + } + + t1 = tcg_temp_new_i64(); + tcg_gen_concat_tl_i64(t1, gen_load_gpr(dc, a->rs1), cpu_y); + + tcg_gen_divu_i64(t1, t1, t2); + tcg_gen_umin_i64(t1, t1, tcg_constant_i64(UINT32_MAX)); + + dst = gen_dest_gpr(dc, a->rd); + tcg_gen_trunc_i64_tl(dst, t1); + gen_store_gpr(dc, a->rd, dst); + return advance_pc(dc); +} + static bool trans_UDIVX(DisasContext *dc, arg_r_r_ri *a) { TCGv dst, src1, src2;