From patchwork Thu Feb 8 17:31:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 127713 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1739738ljc; Thu, 8 Feb 2018 10:15:19 -0800 (PST) X-Google-Smtp-Source: AH8x226fSMbwuOqO0CclEWv66tSJvK7tL1txwc7sg6xNAzbNd+bLmllBFGPginak/lEZx0N2Djmf X-Received: by 10.129.109.133 with SMTP id i127mr74521ywc.444.1518113719727; Thu, 08 Feb 2018 10:15:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518113719; cv=none; d=google.com; s=arc-20160816; b=aR388GNSq9araxwReBHZjxIWiFJfYgJgA8umPfH2d5u/MoO+5VwT7mClXjzYzXkiHn pZLgb0LbwIh5Sz/C/JZsSSiEONfFjnt3g+P8S7D8KZSHfeYZqgf+1bFOZbI1+IRPhZJ9 z9vE0FR5YPG/Qjq9ABB4qWt2seQiBa2dYlYCBkDFnb4mTHzrTn4GrV540vJzhmZ/kzrg iRdlfttv075aRX1wcy0qJVWZOoyGZXrq41LHpEFTZPXnNzit0kk7Pn5rZCzNtdtfE5KX dEwdEoIhcGxK7u9ZSSU5r8qwWAJ3EI7RCPemevaPZmPf1hY8Fk6WT32oz9pctPuxqoU9 4ygA== 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 :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=99cgG/GpcQFnGgmSDCkovT54aRp3JoFpCezaCSLAdy4=; b=vqVYs+Pbfgw9c+4AJxsUcbKsj6kpvwfS/6mr7v3LLa3MLfPUMze6jGYLTLlfyNvJ53 WmgAcEAjLU3YYchV/tR8GsUswEAJtx5yskp4EmHTCd0fBLH+phd7+fqkPf4dnMKiRUg2 Iq8hpsatq6GRRKtcFFD4U0jQkaCtNBhIskUnZM86h+8T02gVEWxrRhPJmPaVIJEVw8Ed ELTIkiw4MTgnVnQ7Aw6t13tm8xLyaASeb5tNP/tFBSCmRweh1HYLZWx2XlYVNSBAZVxH ZhxfPFcX5xSB8Ne7bsajR7sYpQI/RE27pWqr+rHEDEdXNMefy6j2DR0PnxsBVD+2dcn3 AB3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=TkOGfeb9; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id n17si93459ywh.42.2018.02.08.10.15.19 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 08 Feb 2018 10:15:19 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=TkOGfeb9; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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]:59154 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejqj8-00083j-R7 for patch@linaro.org; Thu, 08 Feb 2018 13:15:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57310) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejqBU-0002xE-0Z for qemu-devel@nongnu.org; Thu, 08 Feb 2018 12:40:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ejqBS-0000Ra-8I for qemu-devel@nongnu.org; Thu, 08 Feb 2018 12:40:32 -0500 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:45338) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ejqBS-0000Qs-03 for qemu-devel@nongnu.org; Thu, 08 Feb 2018 12:40:30 -0500 Received: by mail-wr0-x243.google.com with SMTP id h9so5590576wre.12 for ; Thu, 08 Feb 2018 09:40:29 -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 :mime-version:content-transfer-encoding; bh=99cgG/GpcQFnGgmSDCkovT54aRp3JoFpCezaCSLAdy4=; b=TkOGfeb9XBzSoNzdn+Af4KkyrD0a7REQtYNHJymal2Qo3Py0jJaYBJaIIiRvMM0FKC 312vZXrJs+n7C44WioCp4FMy2J3ryuaUjKBfpUBKQmm/x5YhJv+eD0BjgB5JVNTY6ysy zX7c823PBd2b9K3pmOuNR+ChZvhTrVhNOtRIc= 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=99cgG/GpcQFnGgmSDCkovT54aRp3JoFpCezaCSLAdy4=; b=ka1DUGIt0/JvSd8N1arMGpl1ejoaJ0l9mvO7Wjg/2FrO0OtZneu8BVgZVF7bOmjQ50 3ECRp7govq9M/ypFmE57E4n7/SVp/SCLY/qGG5CrhsPly1vjjiQhej8SJXMJIMy9wSLj s5otGISG5Nzzauf9hvBuUDBe/yH8/SGceeEcdYMDNNtNurka69xAMkrqzwfjPsppwiTi OSyLYouRnuA9o+wt3t5vGdjoAGionGVSo4TYYzecnqHoVbakL7eJme5tYWkcN6xcOsGA EOl8LS8aVVBI7wEnhIZ/F9hbFLhW6cC+eZbFDcoHIBph6AuaoFEChoJyJ26imcVfmjcF FS1A== X-Gm-Message-State: APf1xPCfOD8x06G8U9/qSxUcac4uqBKP6Y2HVTLs9YFkH21HPKk4lZBo NaBQN8swDJjC2J0ak4DRVORvvw== X-Received: by 10.223.135.115 with SMTP id 48mr1647864wrz.212.1518111628782; Thu, 08 Feb 2018 09:40:28 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id l92sm558454wrc.31.2018.02.08.09.40.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Feb 2018 09:40:25 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 17F7E3E0D2C; Thu, 8 Feb 2018 17:31:59 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-arm@nongnu.org Date: Thu, 8 Feb 2018 17:31:43 +0000 Message-Id: <20180208173157.24705-19-alex.bennee@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180208173157.24705-1-alex.bennee@linaro.org> References: <20180208173157.24705-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::243 Subject: [Qemu-devel] [PATCH v2 18/32] arm/translate-a64: add FP16 FPRINTx to simd_two_reg_misc_fp16 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 , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This adds the full range of half-precision floating point to integral instructions. Signed-off-by: Alex Bennée --- target/arm/helper-a64.c | 22 ++++++++ target/arm/helper-a64.h | 2 + target/arm/translate-a64.c | 136 +++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 148 insertions(+), 12 deletions(-) -- 2.15.1 diff --git a/target/arm/helper-a64.c b/target/arm/helper-a64.c index 8f0f59ea31..919b073635 100644 --- a/target/arm/helper-a64.c +++ b/target/arm/helper-a64.c @@ -750,3 +750,25 @@ uint32_t HELPER(advsimd_acgt_f16)(float16 a, float16 b, void *fpstp) int compare = float16_compare(f0, f1, fpst); return ADVSIMD_CMPRES(compare == float_relation_greater); } + +/* round to integral */ +float16 HELPER(advsimd_rinth_exact)(float16 x, void *fp_status) +{ + return float16_round_to_int(x, fp_status); +} + +float16 HELPER(advsimd_rinth)(float16 x, void *fp_status) +{ + int old_flags = get_float_exception_flags(fp_status), new_flags; + float16 ret; + + ret = float16_round_to_int(x, fp_status); + + /* Suppress any inexact exceptions the conversion produced */ + if (!(old_flags & float_flag_inexact)) { + new_flags = get_float_exception_flags(fp_status); + set_float_exception_flags(new_flags & ~float_flag_inexact, fp_status); + } + + return ret; +} diff --git a/target/arm/helper-a64.h b/target/arm/helper-a64.h index d2dd46d07b..b583bc0dd8 100644 --- a/target/arm/helper-a64.h +++ b/target/arm/helper-a64.h @@ -76,3 +76,5 @@ DEF_HELPER_3(advsimd_cge_f16, i32, f16, f16, ptr) DEF_HELPER_3(advsimd_cgt_f16, i32, f16, f16, ptr) DEF_HELPER_3(advsimd_acge_f16, i32, f16, f16, ptr) DEF_HELPER_3(advsimd_acgt_f16, i32, f16, f16, ptr) +DEF_HELPER_2(advsimd_rinth_exact, f16, f16, ptr) +DEF_HELPER_2(advsimd_rinth, f16, f16, ptr) diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index f939ca4d40..a0506f094f 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -10727,40 +10727,152 @@ static void disas_simd_two_reg_misc(DisasContext *s, uint32_t insn) /* AdvSIMD [scalar] two register miscellaneous (FP16) * * 31 30 29 28 27 24 23 22 21 17 16 12 11 10 9 5 4 0 - * +---+---+---+---+--------+---+-------------+--------+-----+------+------+ + * +---+---+---+---+---------+---+-------------+--------+-----+------+------+ * | 0 | Q | U | S | 1 1 1 0 | a | 1 1 1 1 0 0 | opcode | 1 0 | Rn | Rd | - * +---+---+---+---+--------+---+-------------+--------+-----+------+------+ + * +---+---+---+---+---------+---+-------------+--------+-----+------+------+ * mask: 1000 1111 0111 1110 0000 1100 0000 0000 0x8f7e 0c00 * val: 0000 1110 0111 1000 0000 1000 0000 0000 0x0e78 0800 * - * ???While the group is listed with bit 28 always set to 1 this is not - * always the case.???? - * - * This actually covers two groups, + * This actually covers two groups where scalar access is governed by + * bit 28. A bunch of the instructions (float to integral) only exist + * in the vector form and are un-allocated for the scalar decode. Also + * in the scalar decode Q is always 1. */ static void disas_simd_two_reg_misc_fp16(DisasContext *s, uint32_t insn) { - int fpop, opcode, a; + int fpop, opcode, a, u; + int rn, rd; + bool is_q; + bool is_scalar; + bool only_in_vector = false; + + int pass; + TCGv_i32 tcg_rmode = NULL; + TCGv_ptr tcg_fpstatus = NULL; + bool need_rmode = false; + int rmode; if (!arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { unallocated_encoding(s); return; } - if (!fp_access_check(s)) { - return; - } - - opcode = extract32(insn, 12, 4); + opcode = extract32(insn, 12, 5); a = extract32(insn, 23, 1); + u = extract32(insn, 29, 1); + is_scalar = extract32(insn, 28, 1); + is_q = extract32(insn, 30, 1); + fpop = deposit32(opcode, 5, 1, a); + fpop = deposit32(fpop, 6, 1, u); switch (fpop) { + case 0x18: /* FRINTN */ + need_rmode = true; + only_in_vector = true; + rmode = FPROUNDING_TIEEVEN; + break; + case 0x19: /* FRINTM */ + need_rmode = true; + only_in_vector = true; + rmode = FPROUNDING_NEGINF; + break; + case 0x38: /* FRINTP */ + need_rmode = true; + only_in_vector = true; + rmode = FPROUNDING_POSINF; + break; + case 0x39: /* FRINTZ */ + need_rmode = true; + only_in_vector = true; + rmode = FPROUNDING_ZERO; + break; + case 0x58: /* FRINTA */ + need_rmode = true; + only_in_vector = true; + rmode = FPROUNDING_TIEAWAY; + break; + case 0x59: /* FRINTX */ + case 0x79: /* FRINTI */ + only_in_vector = true; + /* current rounding mode */ + break; default: fprintf(stderr, "%s: insn %#04x fpop %#2x\n", __func__, insn, fpop); g_assert_not_reached(); } + + /* Check additional constraints for the scalar encoding */ + if (is_scalar) { + if (!is_q) { + unallocated_encoding(s); + return; + } + /* FRINTxx is only in the vector form */ + if (only_in_vector && is_scalar) { + unallocated_encoding(s); + return; + } + } + + if (!fp_access_check(s)) { + return; + } + + if (need_fpst || need_rmode) { + tcg_fpstatus = get_fpstatus_ptr(true); + } + + if (need_rmode) { + tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rmode)); + gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus); + } + + if (is_scalar) { + /* no operations yet */ + } else { + for (pass = 0; pass < (is_q ? 8 : 4); pass++) { + TCGv_i32 tcg_op = tcg_temp_new_i32(); + TCGv_i32 tcg_res = tcg_temp_new_i32(); + + read_vec_element_i32(s, tcg_op, rn, pass, MO_16); + + switch (fpop) { + case 0x18: /* FRINTN */ + case 0x19: /* FRINTM */ + case 0x38: /* FRINTP */ + case 0x39: /* FRINTZ */ + case 0x58: /* FRINTA */ + case 0x79: /* FRINTI */ + gen_helper_advsimd_rinth(tcg_res, tcg_op, tcg_fpstatus); + break; + case 0x59: /* FRINTX */ + gen_helper_advsimd_rinth_exact(tcg_res, tcg_op, tcg_fpstatus); + break; + default: + g_assert_not_reached(); + } + + write_vec_element_i32(s, tcg_res, rd, pass, MO_16); + + tcg_temp_free_i32(tcg_res); + tcg_temp_free_i32(tcg_op); + } + + if (!is_q) { + clear_vec_high(s, rd); + } + } + + if (tcg_rmode) { + gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus); + tcg_temp_free_i32(tcg_rmode); + } + + if (tcg_fpstatus) { + tcg_temp_free_ptr(tcg_fpstatus); + } } /* AdvSIMD scalar x indexed element