From patchwork Sun Nov 5 20:12: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: 741060 Delivered-To: patch@linaro.org Received: by 2002:adf:fd90:0:b0:32d:baff:b0ca with SMTP id d16csp793474wrr; Sun, 5 Nov 2023 12:15:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IGShcnIPoCQMigNcgOMhNWPWLbvXdLV7HUetNCss9q2oRSEbxA5hxuFGkJnuNNGaamZ31q0 X-Received: by 2002:a05:6214:400e:b0:65b:319b:b430 with SMTP id kd14-20020a056214400e00b0065b319bb430mr29435807qvb.58.1699215308498; Sun, 05 Nov 2023 12:15:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699215308; cv=none; d=google.com; s=arc-20160816; b=kKKBZbT7LFVAMS/k5sPwwhyU8LckZRufCjsmaFX5yyLa5Oqpkmdb/vM+et2QgLX8dC i2IaZomaZ3zDutJIkfDUrRuft7gncogy7dVt3e2SiOcpRXbqD/pSHQZCb90f1k1wQuf1 1drGvEzvdF2O9zRjGEQj7OQGsaWjsqRRrM4S/QKp0jwISTq/TgLJnlY2r5cbluX+7x/B LISqUv68cJSUnFKy7YUjwjUmJx1Rp0s5awUstTf+i+bLB3ijCNvFQc5qLroVxsF5K0gV //m/o0uDefJYsaW549RDCqTvlbNQc64NfrccnX4PtPLaD6ZaFequWs50aJqwDaCclmjq ZtBg== 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=A78suQY9V9iQl5jBJ+5kjMF55wPobXhyeLKa16NEwCk=; fh=rYI8DiHAAFX3O5g969KmOAQ7d45Sb8OxQX1+DywGDk4=; b=HY1krwn0eBhWS54BvESthGH0yTTSV0kBG4ffYd1zZ8vcRh5oGVtLiD0AGpMd48Y8Cy EGKhcRiqv40PGWFF0KG5kQCZ0drjIR1oEa+SZZaFWtiLTv2Dl2/KLiRQfXt8OMFu4Z47 IQI+K6qmT9/3eacZINXDg/e4XA8n9eYXmbN1aukbb2rraeVDm0Q2ICIlWsAyhZegRCAC rMUxHg5E+KS6T5tjAPkHZwFDB9Vni5mFzh37AEGLCEfeuv+sLR0LB3Pv0gxxnWYa812U yaZm1p+BOaI/PDaP4i0FbfeYomlq0LEYryf9ICRD77AoXOqEY+F9eQItdLsaymQEt+S1 VZ4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gdhf2TTK; 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 c4-20020ad44304000000b0066d0418fc25si4653235qvs.267.2023.11.05.12.15.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 05 Nov 2023 12:15:08 -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=gdhf2TTK; 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 1qzjUD-0003Sd-Vg; Sun, 05 Nov 2023 15:12: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 1qzjUB-0003RI-RT for qemu-devel@nongnu.org; Sun, 05 Nov 2023 15:12:43 -0500 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qzjUA-0002BF-6b for qemu-devel@nongnu.org; Sun, 05 Nov 2023 15:12:43 -0500 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-5b92b852390so2993371a12.2 for ; Sun, 05 Nov 2023 12:12:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699215160; x=1699819960; 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=A78suQY9V9iQl5jBJ+5kjMF55wPobXhyeLKa16NEwCk=; b=gdhf2TTKcxEUD1++rP5SwjRo468jGxgzzRie/SXFFvjPXeuyZ6ZNEAy2dJyETw6Lij rJTPgZpMaHYcuNUmFlSMeN6dCGH/iUmuNXYMzgQ66dSvx8nT6TtJHWp4mbPGaM8Bw5gZ Qvir7em33NKTw7TcXM2eaO3y301cw0Q3TPEBfoWlJuUqLgy+Ewa/JMfZaEgD6ArjU2qs iSN4j5ziVYyev3lXSPBVuqiUOdAvc+o1SscMU/R6Xsy0v12oHeVNFuN4O/PQe6u0usC+ JaqA78PNKcq11hcAGV4kFmxkDu9qXZySW5GNExQGpOAMFGr5+aJObnqlfEuJ/c1c5WWv mjDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699215160; x=1699819960; 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=A78suQY9V9iQl5jBJ+5kjMF55wPobXhyeLKa16NEwCk=; b=MIjpIErBf0Sfio3Dlased8E2omijB61FE1/7hbo5rtRbgUZjswImerX/Z89NzTN3gb DJKUV7feEDpBjwec+m2k4RYzbNnZvxWkaXRcLqQVPR/3cH4wwGw4rvLfI+Hv6dnaGkcC 6MvJeRmtxea7zI5mt4oz6eohEKX8mf3O9DlqmHxa2D+XAxcZzJ0x/ONmUeVXPfWejB6k VDSmE0D4iQEk998YJWzF3DUi/P85cx7/MSpNb4JlkEoX9MKo9BwvYxjZ2kKy43tu+gfz eP+KlmEGJLv+M76NNe8eSHMQF5UTYJqWcyeTiVC1lfLWe46JLrxI3KCSlyFPK1q7wQ10 BQNQ== X-Gm-Message-State: AOJu0YyY+TpG14qhajL3egDdz2IJS1eBGW0VBmI/C0KO+kxDgBG+Nndj J9maAFQ+DaMuRNIdlboI3Ye4w0jv7djMT75mqA0= X-Received: by 2002:a05:6a21:a597:b0:161:76a4:4f74 with SMTP id gd23-20020a056a21a59700b0016176a44f74mr38581984pzc.1.1699215160687; Sun, 05 Nov 2023 12:12:40 -0800 (PST) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id u23-20020a056a00099700b006884549adc8sm4359777pfg.29.2023.11.05.12.12.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 12:12:40 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Mark Cave-Ayland Subject: [PULL 20/21] target/sparc: Implement UDIV inline Date: Sun, 5 Nov 2023 12:12:21 -0800 Message-Id: <20231105201222.202395-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231105201222.202395-1-richard.henderson@linaro.org> References: <20231105201222.202395-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::532; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x532.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 Tested-by: Mark Cave-Ayland Acked-by: Mark Cave-Ayland 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;