From patchwork Sat Feb 23 01:22:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 159084 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp2391100jaa; Fri, 22 Feb 2019 17:22:36 -0800 (PST) X-Google-Smtp-Source: AHgI3Ibw4hpc4HpeK3BEfz5ec4h0wtmeAGgiGMZ/opGZjjGaO1iihGs1fF5vt2aN0W0Vju+WZcQl X-Received: by 2002:a81:b189:: with SMTP id p131mr5824942ywh.84.1550884955994; Fri, 22 Feb 2019 17:22:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550884955; cv=none; d=google.com; s=arc-20160816; b=z7ZQd4UXKL0ShOR7zP6ANWymohX4KOYbyQT2IDk2ees9wyln9oikupke3hDctcbI6J z40HbWSjo4CtpG6zoy/QDgrz9MTLB4mnnz1mFJBlv2LA5WMMuU7xJyMi7L/c8D6hnl0c 9f6ykNf7YKSM3mucMypQD2lW/J0aBc3KKuUwy+8n07Z/qnZ1Z/I0in3tXuDdLPhMrx5O Z0gcBgBqrs9GzNODGqQmVnbyIft9Wt6pklM4898P9hIqYrG+9LNYbE8uvvcGuew/ltuP inNK2IY5jhLi0R/Vqc4mQf3fhMRdF4kxD/UsZ3x4JoyvVaizY7321wOKdmlT3OcY5pVA v8iQ== 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:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=mC+SpBVBrDJzRk6F8MWOq394R2QevDYVB9531egPSiM=; b=S6aeobJni24uMf5u9Oqx1Lt1i5GLNSIhJAUHUMuElbf5Powt4pl+U9or2eoFKWLOGh cQ20GMUbLxPeqJ0jdELOuxl9SJ3dyuRAFJXcYTYRMXTRxiDLIYAINqNaHpYVBx+JJ9yR +XenwWGnxAI3o5KToM1vKbptA5TdP4ZAymfuQs1Snehp1uq7OT3kMB7MX9+KCew/YC4F MZ8A9rcOaQgXbr0RpeJw3/TVfS/ubAotjB/mJxAdOb+SNHt5Ll6HisdIkSWwL+xv06nA pRZgNl/m3z2jdX1HkhrfL1FXzUvV4sxFsOGA+yJem4hTPv39AGAGJx1yhNgTjGnPX+qT b0qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=zNAuy8AT; 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 n16si2005156ywh.128.2019.02.22.17.22.35 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 22 Feb 2019 17:22:35 -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=fail header.i=@linaro.org header.s=google header.b=zNAuy8AT; 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 ([127.0.0.1]:59402 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxM1T-0008JB-FH for patch@linaro.org; Fri, 22 Feb 2019 20:22:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57061) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxM17-0008IZ-0f for qemu-devel@nongnu.org; Fri, 22 Feb 2019 20:22:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxM15-0000Td-Tw for qemu-devel@nongnu.org; Fri, 22 Feb 2019 20:22:13 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]:34047) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gxM15-0000OU-Lf for qemu-devel@nongnu.org; Fri, 22 Feb 2019 20:22:11 -0500 Received: by mail-pl1-x630.google.com with SMTP id d15so1859014plr.1 for ; Fri, 22 Feb 2019 17:22:11 -0800 (PST) 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; bh=mC+SpBVBrDJzRk6F8MWOq394R2QevDYVB9531egPSiM=; b=zNAuy8ATtn7pMyAcNpdY3Ylfl3BR6zRPqRQ0eD801A6SfLrR9Kv1rKtrt99cQj48VS r7TONhfCX1XBBpFsjKeaFqUm87LVLY4KhvHjj93QGNMlMYi80W/w/p0iFQNwd2on06xQ Yd6dg3+PoVli5W2X8HJW3ZIl2u1tQLdERXfLXUHF5kIANX3Q6aqSx2MvzrAwfvm4MUX4 vbBtlsZXEzZXkancR2I0PSrGzpn5QC4O0iMyGEk7YDedwdCKaY8W9Rb1ZMA/4vwsl/EV VFSDPB42Xb1HHKPMRAFgAgLsqL6VFTcuy0QcP3hp3ONZ90IqROGTZ4aQsx6t5pg7KXmY 7A/A== 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; bh=mC+SpBVBrDJzRk6F8MWOq394R2QevDYVB9531egPSiM=; b=XkQOqkSUZDL8I9jFi7kBkEd1SDlkbly5wUK0uPGzbE31Uh5qNTwvLmWAsfVAcLOl1m RopBJgjj7kJPzzwLfZAf2hVFie1/GWr50jM8fF6hgSYBgZpmygZfoMlK+q8sjRWjoehR aT8dfZ2vcGgt1QyhqCFXjUbITBqBeDfjVCX7wbFpuuHrzgyEY9bi6M3+rgh3yey/Z7FB bD0gDaJmMrVQZxhAF/Xy6zwpyWjbFTfAMGBbtYVbtCSHClcfU/QOrwb8+YrxGsaY2vk9 i0dYXy37576T8jMUIPb7qZJB0rTi10IQq+TNAHgrPk6Yd9ewO3A8FHdhaCe5EE8jJfxI do/Q== X-Gm-Message-State: AHQUAuaInkRgjn2Oot6LN5cuHIEo1uMZSCX4Py8ovW83D5bqIwABKHCN MY9sIAhR1ElIbyAE2QWiE7zJGPJYb2g= X-Received: by 2002:a17:902:e90b:: with SMTP id cs11mr6902533plb.197.1550884930034; Fri, 22 Feb 2019 17:22:10 -0800 (PST) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id m67sm5607497pfj.70.2019.02.22.17.22.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Feb 2019 17:22:09 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 22 Feb 2019 17:22:05 -0800 Message-Id: <20190223012206.30498-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190223012206.30498-1-richard.henderson@linaro.org> References: <20190223012206.30498-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::630 Subject: [Qemu-devel] [PATCH 1/2] target/arm: Restructure handle_fp_1src_{single, double} X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This will allow sharing code that adjusts rmode beyond the existing users. Signed-off-by: Richard Henderson --- target/arm/translate-a64.c | 90 +++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 41 deletions(-) -- 2.17.1 diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index d3c8eaf089..fcbf6b16cf 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -5505,55 +5505,59 @@ static void handle_fp_1src_half(DisasContext *s, int opcode, int rd, int rn) /* Floating-point data-processing (1 source) - single precision */ static void handle_fp_1src_single(DisasContext *s, int opcode, int rd, int rn) { + void (*gen_fpst)(TCGv_i32, TCGv_i32, TCGv_ptr); + TCGv_i32 tcg_op, tcg_res; TCGv_ptr fpst; - TCGv_i32 tcg_op; - TCGv_i32 tcg_res; + int rmode = -1; - fpst = get_fpstatus_ptr(false); tcg_op = read_fp_sreg(s, rn); tcg_res = tcg_temp_new_i32(); switch (opcode) { case 0x0: /* FMOV */ tcg_gen_mov_i32(tcg_res, tcg_op); - break; + goto done; case 0x1: /* FABS */ gen_helper_vfp_abss(tcg_res, tcg_op); - break; + goto done; case 0x2: /* FNEG */ gen_helper_vfp_negs(tcg_res, tcg_op); - break; + goto done; case 0x3: /* FSQRT */ gen_helper_vfp_sqrts(tcg_res, tcg_op, cpu_env); - break; + goto done; case 0x8: /* FRINTN */ case 0x9: /* FRINTP */ case 0xa: /* FRINTM */ case 0xb: /* FRINTZ */ case 0xc: /* FRINTA */ - { - TCGv_i32 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(opcode & 7)); - - gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst); - gen_helper_rints(tcg_res, tcg_op, fpst); - - gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst); - tcg_temp_free_i32(tcg_rmode); + rmode = arm_rmode_to_sf(opcode & 7); + gen_fpst = gen_helper_rints; break; - } case 0xe: /* FRINTX */ - gen_helper_rints_exact(tcg_res, tcg_op, fpst); + gen_fpst = gen_helper_rints_exact; break; case 0xf: /* FRINTI */ - gen_helper_rints(tcg_res, tcg_op, fpst); + gen_fpst = gen_helper_rints; break; default: - abort(); + g_assert_not_reached(); } - write_fp_sreg(s, rd, tcg_res); - + fpst = get_fpstatus_ptr(false); + if (rmode >= 0) { + TCGv_i32 tcg_rmode = tcg_const_i32(rmode); + gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst); + gen_fpst(tcg_res, tcg_op, fpst); + gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst); + tcg_temp_free_i32(tcg_rmode); + } else { + gen_fpst(tcg_res, tcg_op, fpst); + } tcg_temp_free_ptr(fpst); + + done: + write_fp_sreg(s, rd, tcg_res); tcg_temp_free_i32(tcg_op); tcg_temp_free_i32(tcg_res); } @@ -5561,9 +5565,10 @@ static void handle_fp_1src_single(DisasContext *s, int opcode, int rd, int rn) /* Floating-point data-processing (1 source) - double precision */ static void handle_fp_1src_double(DisasContext *s, int opcode, int rd, int rn) { + void (*gen_fpst)(TCGv_i64, TCGv_i64, TCGv_ptr); + TCGv_i64 tcg_op, tcg_res; TCGv_ptr fpst; - TCGv_i64 tcg_op; - TCGv_i64 tcg_res; + int rmode = -1; switch (opcode) { case 0x0: /* FMOV */ @@ -5571,48 +5576,51 @@ static void handle_fp_1src_double(DisasContext *s, int opcode, int rd, int rn) return; } - fpst = get_fpstatus_ptr(false); tcg_op = read_fp_dreg(s, rn); tcg_res = tcg_temp_new_i64(); switch (opcode) { case 0x1: /* FABS */ gen_helper_vfp_absd(tcg_res, tcg_op); - break; + goto done; case 0x2: /* FNEG */ gen_helper_vfp_negd(tcg_res, tcg_op); - break; + goto done; case 0x3: /* FSQRT */ gen_helper_vfp_sqrtd(tcg_res, tcg_op, cpu_env); - break; + goto done; case 0x8: /* FRINTN */ case 0x9: /* FRINTP */ case 0xa: /* FRINTM */ case 0xb: /* FRINTZ */ case 0xc: /* FRINTA */ - { - TCGv_i32 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(opcode & 7)); - - gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst); - gen_helper_rintd(tcg_res, tcg_op, fpst); - - gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst); - tcg_temp_free_i32(tcg_rmode); + rmode = arm_rmode_to_sf(opcode & 7); + gen_fpst = gen_helper_rintd; break; - } case 0xe: /* FRINTX */ - gen_helper_rintd_exact(tcg_res, tcg_op, fpst); + gen_fpst = gen_helper_rintd_exact; break; case 0xf: /* FRINTI */ - gen_helper_rintd(tcg_res, tcg_op, fpst); + gen_fpst = gen_helper_rintd; break; default: - abort(); + g_assert_not_reached(); } - write_fp_dreg(s, rd, tcg_res); - + fpst = get_fpstatus_ptr(false); + if (rmode >= 0) { + TCGv_i32 tcg_rmode = tcg_const_i32(rmode); + gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst); + gen_fpst(tcg_res, tcg_op, fpst); + gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst); + tcg_temp_free_i32(tcg_rmode); + } else { + gen_fpst(tcg_res, tcg_op, fpst); + } tcg_temp_free_ptr(fpst); + + done: + write_fp_dreg(s, rd, tcg_res); tcg_temp_free_i64(tcg_op); tcg_temp_free_i64(tcg_res); } From patchwork Sat Feb 23 01:22:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 159086 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp2392505jaa; Fri, 22 Feb 2019 17:24:37 -0800 (PST) X-Google-Smtp-Source: AHgI3IYBSnq9QWvN6CLWp5P3CoWeFmGPEotDemcBWnO3eaUycMC41gSy1Sw5YAxcpHxCKCOOEinK X-Received: by 2002:a81:6f0b:: with SMTP id k11mr5677895ywc.245.1550885077873; Fri, 22 Feb 2019 17:24:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550885077; cv=none; d=google.com; s=arc-20160816; b=Wa/L8S525mq8pDqJSSMP1lepySxcpRjj3fY3fnIIAxyyNQXXHqcPaG2pxOmhzeQ/HQ cVUVMoI5GpsvDGpeOgLIVdfcqgfup6gp9rnbxq/Eg6EMVqKVmWl4ec9kd2yNwQt9ZfLe rT6uV0eQ0YvCMtRvOIFMBErr6uUf8GdJZeqkjs78fkpO0Q5Xh642maC6DGCZYV38fKWJ avg/Dty+fl3C0wSq+EwW5HYWTVuZIzY7y0+18eT4e1qtHdgMk5jl5X6kLH7HxNijZd9W dcFMykpmg6Gn5OrThYODFPv1LZSBOLlEGRIQwKwHj5rQV8vov4xJz6r9u52kK+ab5F0Q 5Phg== 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:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=xH3OCaAqVpUx9IjEogLWsN/U2GSd29ikHEOx2a5u9ms=; b=ndExoTCMD1tLN/qGGmKnSyqSVhOucY6kr8MzsxJIKrRS/artaQXFckrUijrbrmdCaJ sVdKUf1oG/GRwaNBncdmLOoLZxfo63vi2mdf/Q6aBdro4vZuCQDbzSpC/8RAftiV4vPe n8TR2hFk7r8+M5jN/jrvwMgYi+8ShAGcv4aLD1kl+iXPhNJqx6e6zb6c7uRNxSXqJMsJ YDCrhq7UHLzmWtxONzm1/0EaZAhL/mpqr1IBHcbxjo1A6XOnF+AqZ8L1LghmA45Kzi0e p+k/xUHhn5Ifvc/JqgMuyvCg4HAZgLkkOxAxDVO1yti3Lh/l10cQDgxwFCnzMY2pixIS IqiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="Dk/AFze9"; 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 l137si1755686ywb.328.2019.02.22.17.24.37 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 22 Feb 2019 17:24:37 -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=fail header.i=@linaro.org header.s=google header.b="Dk/AFze9"; 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 ([127.0.0.1]:59414 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxM3R-0000jx-B0 for patch@linaro.org; Fri, 22 Feb 2019 20:24:37 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57079) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxM18-0008J2-DT for qemu-devel@nongnu.org; Fri, 22 Feb 2019 20:22:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxM16-0000Xl-Uf for qemu-devel@nongnu.org; Fri, 22 Feb 2019 20:22:14 -0500 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:41652) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gxM16-0000UU-L6 for qemu-devel@nongnu.org; Fri, 22 Feb 2019 20:22:12 -0500 Received: by mail-pl1-x641.google.com with SMTP id y5so1841082plk.8 for ; Fri, 22 Feb 2019 17:22:12 -0800 (PST) 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; bh=xH3OCaAqVpUx9IjEogLWsN/U2GSd29ikHEOx2a5u9ms=; b=Dk/AFze9KceW3t3BKJd/1lME6lRPZgD4GTk0vYX2LSxSdaeOeF1ZPfKMA/5yHaaIK/ qMq53pFZQxsauFtWvwhsqOVdGh8qUQFK+RVpqqWh5Lbzfdq4cZIo/EDbDWKNvQg0lvZf EG+L9+rywctz6qnscKk6I/B3IqiUoQJWEic4eS8QTlfUfIGuT/I9QGxEBhGriy54jLAe E0Wbt+VguAAfGLdGPPpAOD0O4NVqhYoOuZJ5pPybM/wJsIU3TAi/5UK09QJlVPYxSJLi nQfrtkLRtOk0/k3vPiha20i12B1zBs18GGs3Uqt88VajE/QvUWz1i2K19ijx7WYZekvX QtwA== 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; bh=xH3OCaAqVpUx9IjEogLWsN/U2GSd29ikHEOx2a5u9ms=; b=ICwMyEp+S+SLTLO8obpNO6O++xvjAz5AYzT3PH+I20ehYbqrqiyZ2eWamFCRz466gQ R4hMrt9x0Jng3Rj21OLZymgavmyn3kUWBs7YuwHS6UAwxq8pCx9c1+GTOOyto+oBMxCh LW6ZbXWrx86CJbis1XEbQ/ZXtXLxTbwr23ctMbHJHfS7RQIWuB+AJffPyaxtVDpmGwes Yi2Atw8XBwSDPOdi8wtYTN55ZofvKWBb+7+LE6CYhsitx5DF8ok/gDC2i+1Yq5oLAZJq fBUalQ1UTwQ5JzqWiiYmKOF9qQkyi28FehDZk10nZtSxqsO0P4tj/dUIQD4xuWKHP5uR 4wUQ== X-Gm-Message-State: AHQUAubHwhTYSGGN/+CdTOLW1i/ExXhygkmXGFewhYix17n/RF3JLtAP mjzlk/qKxDEeF13y5g5mYEFkNrAPzIs= X-Received: by 2002:a17:902:b709:: with SMTP id d9mr7127776pls.83.1550884931223; Fri, 22 Feb 2019 17:22:11 -0800 (PST) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id m67sm5607497pfj.70.2019.02.22.17.22.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Feb 2019 17:22:10 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 22 Feb 2019 17:22:06 -0800 Message-Id: <20190223012206.30498-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190223012206.30498-1-richard.henderson@linaro.org> References: <20190223012206.30498-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::641 Subject: [Qemu-devel] [PATCH 2/2] target/arm: Implement ARMv8.5-FRINT X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson --- target/arm/cpu.h | 5 ++ target/arm/helper.h | 5 ++ target/arm/cpu64.c | 1 + target/arm/translate-a64.c | 71 ++++++++++++++++++++++++++-- target/arm/vfp_helper.c | 96 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 173 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 9cf439fb8d..f60a2361fe 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3391,6 +3391,11 @@ static inline bool isar_feature_aa64_pauth(const ARMISARegisters *id) FIELD_DP64(0, ID_AA64ISAR1, GPI, 0xf))) != 0; } +static inline bool isar_feature_aa64_frint(const ARMISARegisters *id) +{ + return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, FRINTTS) != 0; +} + static inline bool isar_feature_aa64_fp16(const ARMISARegisters *id) { /* We always set the AdvSIMD and FP fields identically wrt FP16. */ diff --git a/target/arm/helper.h b/target/arm/helper.h index d363904278..c978a1d812 100644 --- a/target/arm/helper.h +++ b/target/arm/helper.h @@ -686,6 +686,11 @@ DEF_HELPER_FLAGS_5(gvec_fmlal_idx_a32, TCG_CALL_NO_RWG, DEF_HELPER_FLAGS_5(gvec_fmlal_idx_a64, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_2(frint32_s, TCG_CALL_NO_RWG, f32, f32, ptr) +DEF_HELPER_FLAGS_2(frint64_s, TCG_CALL_NO_RWG, f32, f32, ptr) +DEF_HELPER_FLAGS_2(frint32_d, TCG_CALL_NO_RWG, f64, f64, ptr) +DEF_HELPER_FLAGS_2(frint64_d, TCG_CALL_NO_RWG, f64, f64, ptr) + #ifdef TARGET_AARCH64 #include "helper-a64.h" #include "helper-sve.h" diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 1b0c427277..645cc20eb6 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -318,6 +318,7 @@ static void aarch64_max_initfn(Object *obj) t = FIELD_DP64(t, ID_AA64ISAR1, API, 0); t = FIELD_DP64(t, ID_AA64ISAR1, GPA, 1); t = FIELD_DP64(t, ID_AA64ISAR1, GPI, 0); + t = FIELD_DP64(t, ID_AA64ISAR1, FRINTTS, 1); cpu->isar.id_aa64isar1 = t; t = cpu->isar.id_aa64pfr0; diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index fcbf6b16cf..139e500df8 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -5540,6 +5540,20 @@ static void handle_fp_1src_single(DisasContext *s, int opcode, int rd, int rn) case 0xf: /* FRINTI */ gen_fpst = gen_helper_rints; break; + case 0x10: /* FRINT32Z */ + rmode = float_round_to_zero; + gen_fpst = gen_helper_frint32_s; + break; + case 0x11: /* FRINT32X */ + gen_fpst = gen_helper_frint32_s; + break; + case 0x12: /* FRINT64Z */ + rmode = float_round_to_zero; + gen_fpst = gen_helper_frint64_s; + break; + case 0x13: /* FRINT64X */ + gen_fpst = gen_helper_frint64_s; + break; default: g_assert_not_reached(); } @@ -5603,6 +5617,20 @@ static void handle_fp_1src_double(DisasContext *s, int opcode, int rd, int rn) case 0xf: /* FRINTI */ gen_fpst = gen_helper_rintd; break; + case 0x10: /* FRINT32Z */ + rmode = float_round_to_zero; + gen_fpst = gen_helper_frint32_d; + break; + case 0x11: /* FRINT32X */ + gen_fpst = gen_helper_frint32_d; + break; + case 0x12: /* FRINT64Z */ + rmode = float_round_to_zero; + gen_fpst = gen_helper_frint64_d; + break; + case 0x13: /* FRINT64X */ + gen_fpst = gen_helper_frint64_d; + break; default: g_assert_not_reached(); } @@ -5739,6 +5767,13 @@ static void disas_fp_1src(DisasContext *s, uint32_t insn) handle_fp_fcvt(s, opcode, rd, rn, dtype, type); break; } + + case 0x10 ... 0x13: /* FRINT{32,64}{X,Z} */ + if (type > 1 || !dc_isar_feature(aa64_frint, s)) { + unallocated_encoding(s); + return; + } + /* fall through */ case 0x0 ... 0x3: case 0x8 ... 0xc: case 0xe ... 0xf: @@ -5748,14 +5783,12 @@ static void disas_fp_1src(DisasContext *s, uint32_t insn) if (!fp_access_check(s)) { return; } - handle_fp_1src_single(s, opcode, rd, rn); break; case 1: if (!fp_access_check(s)) { return; } - handle_fp_1src_double(s, opcode, rd, rn); break; case 3: @@ -5767,13 +5800,13 @@ static void disas_fp_1src(DisasContext *s, uint32_t insn) if (!fp_access_check(s)) { return; } - handle_fp_1src_half(s, opcode, rd, rn); break; default: unallocated_encoding(s); } break; + default: unallocated_encoding(s); break; @@ -9301,6 +9334,14 @@ static void handle_2misc_64(DisasContext *s, int opcode, bool u, case 0x59: /* FRINTX */ gen_helper_rintd_exact(tcg_rd, tcg_rn, tcg_fpstatus); break; + case 0x1e: /* FRINT32Z */ + case 0x5e: /* FRINT32X */ + gen_helper_frint32_d(tcg_rd, tcg_rn, tcg_fpstatus); + break; + case 0x1f: /* FRINT64Z */ + case 0x5f: /* FRINT64X */ + gen_helper_frint64_d(tcg_rd, tcg_rn, tcg_fpstatus); + break; default: g_assert_not_reached(); } @@ -11951,8 +11992,7 @@ static void disas_simd_two_reg_misc(DisasContext *s, uint32_t insn) } break; case 0xc ... 0xf: - case 0x16 ... 0x1d: - case 0x1f: + case 0x16 ... 0x1f: { /* Floating point: U, size[1] and opcode indicate operation; * size[0] indicates single or double precision. @@ -12095,6 +12135,19 @@ static void disas_simd_two_reg_misc(DisasContext *s, uint32_t insn) } need_fpstatus = true; break; + case 0x1e: /* FRINT32Z */ + case 0x1f: /* FRINT64Z */ + need_rmode = true; + rmode = FPROUNDING_ZERO; + /* fall through */ + case 0x5e: /* FRINT32X */ + case 0x5f: /* FRINT64X */ + need_fpstatus = true; + if ((size == 3 && !is_q) || !dc_isar_feature(aa64_frint, s)) { + unallocated_encoding(s); + return; + } + break; default: unallocated_encoding(s); return; @@ -12260,6 +12313,14 @@ static void disas_simd_two_reg_misc(DisasContext *s, uint32_t insn) case 0x7c: /* URSQRTE */ gen_helper_rsqrte_u32(tcg_res, tcg_op, tcg_fpstatus); break; + case 0x1e: /* FRINT32Z */ + case 0x5e: /* FRINT32X */ + gen_helper_frint32_s(tcg_res, tcg_op, tcg_fpstatus); + break; + case 0x1f: /* FRINT64Z */ + case 0x5f: /* FRINT64X */ + gen_helper_frint64_s(tcg_res, tcg_op, tcg_fpstatus); + break; default: g_assert_not_reached(); } diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c index f19c0606c2..c77000606e 100644 --- a/target/arm/vfp_helper.c +++ b/target/arm/vfp_helper.c @@ -1174,3 +1174,99 @@ uint32_t HELPER(vjcvt)(float64 value, CPUARMState *env) return result; } + +/* Round a float32 to an integer that fits in int32_t or int64_t. */ +static float32 frint_f32(float32 f, float_status *fpst, int intsize) +{ + int old_flags = get_float_exception_flags(fpst); + uint32_t exp = extract32(f, 23, 8); + + if (unlikely(exp == 0xff)) { + /* NaN or Inf. */ + goto overflow; + } + + /* Round and re-extract the exponent. */ + f = float32_round_to_int(f, fpst); + exp = extract32(f, 23, 8); + + /* Validate the range of the result. */ + if (exp < 126 + intsize) { + /* abs(F) <= INT{N}_MAX */ + return f; + } + if (exp == 126 + intsize) { + uint32_t sign = extract32(f, 31, 1); + uint32_t frac = extract32(f, 0, 23); + if (sign && frac == 0) { + /* F == INT{N}_MIN */ + return f; + } + } + + overflow: + /* + * Raise Invalid and return INT{N}_MIN as a float. Revert any + * inexact exception float32_round_to_int may have raised. + */ + set_float_exception_flags(old_flags | float_flag_invalid, fpst); + return (0x100u + 126u + intsize) << 23; +} + +float32 HELPER(frint32_s)(float32 f, void *fpst) +{ + return frint_f32(f, fpst, 32); +} + +float32 HELPER(frint64_s)(float32 f, void *fpst) +{ + return frint_f32(f, fpst, 64); +} + +/* Round a float64 to an integer that fits in int32_t or int64_t. */ +static float64 frint_f64(float64 f, float_status *fpst, int intsize) +{ + int old_flags = get_float_exception_flags(fpst); + uint32_t exp = extract64(f, 52, 11); + + if (unlikely(exp == 0x7ff)) { + /* NaN or Inf. */ + goto overflow; + } + + /* Round and re-extract the exponent. */ + f = float64_round_to_int(f, fpst); + exp = extract64(f, 52, 11); + + /* Validate the range of the result. */ + if (exp < 1022 + intsize) { + /* abs(F) <= INT{N}_MAX */ + return f; + } + if (exp == 1022 + intsize) { + uint64_t sign = extract64(f, 63, 1); + uint64_t frac = extract64(f, 0, 52); + if (sign && frac == 0) { + /* F == INT{N}_MIN */ + return f; + } + } + + overflow: + /* + * Raise Invalid and return INT{N}_MIN as a float. Revert any + * inexact exception float32_round_to_int may have raised. + */ + set_float_exception_flags(old_flags | float_flag_invalid, fpst); + return (uint64_t)(0x800 + 1022 + intsize) << 52; +} + +float64 HELPER(frint32_d)(float64 f, void *fpst) +{ + return frint_f64(f, fpst, 32); +} + +float64 HELPER(frint64_d)(float64 f, void *fpst) +{ + return frint_f64(f, fpst, 64); +}