From nobody Mon Nov 23 04:34:21 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1792865316; cv=none; d=zohomail.com; s=zohoarc; b=EzhixUQR/FoxqbJIDpji/OxJRpU6yaSEdDC2FF5a/QEHnKj1CswM2Gn/0j/5/jedEg1+XRtEibYMLwMy/BEovB81w//WlqVIFN9QBkJxZED8n/uwR25vz7FZt9IEEOiMDM209B73obiwaprR5HyCFMdS8Pn4qavBrW3umrks+5k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792865316; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0JYKXljzvVxNfPy0F5+sSiAzdmJGE7tD1ZaAdvZfDnQ=; b=E9QJETfjmsFT5pNl1zzzJ9o0WIvHKvfooOEJ4G9F7241b5QVr2CxQ5Oi5BfAN45VgHt3x08wgm463web7IYVZA8AL8v9xuFGEDwkwxgHLhWhC7kakZPD53ZizDa3xzTpH60s/FQ1AELQv+lHqy28/0wEseKDZxfrensJ2KLlhFU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792865316382264.15680720472835; Sat, 24 Oct 2026 11:08:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xKgAT-0006Dz-9p; Sat, 24 Oct 2026 14:08:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xKgAN-00063N-74 for qemu-devel@nongnu.org; Sat, 24 Oct 2026 14:08:28 -0400 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xKgAJ-0002K6-Hv for qemu-devel@nongnu.org; Sat, 24 Oct 2026 14:08:26 -0400 Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 69OExwR2996544 for ; Sat, 24 Oct 2026 18:08:22 GMT Received: from mail-dy1-f200.google.com (mail-dy1-f200.google.com [74.125.82.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hgny9scct-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Sat, 24 Oct 2026 18:08:21 +0000 (GMT) Received: by mail-dy1-f200.google.com with SMTP id 5a478bee46e88-3580c07911eso5705430eec.0 for ; Sat, 24 Oct 2026 11:08:21 -0700 (PDT) Received: from hu-bcain-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-369f27d5bf8sm3966963eec.4.2026.10.24.11.08.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Oct 2026 11:08:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 0JYKXljzvVxNfPy0F5+sSiAzdmJGE7tD1ZaAdvZfDnQ=; b=n6yoSS9aqXrgEMF2 L8cCpcVetyA0Pg3qexynrBARQ2czwhha5qVRCL8rtv9XUxC9Ob1Ru6HuDXCBm4P0 LI5JTyvpaZLYge7MUmhgs8fp3nJ9DvPeavhTR0/LpCUzas0DhP93vXzsNh6wHk/w 4no70ike1PvOcBaGW5gmLunCiLXRN6zN44altwNsbShf+1gMVo2iZMqkFw1ZfMY6 oagRLFzfFnOFnRz7GlwWUe+1d47IcDcEdu6B1HAHyJ6QHbdGMtTZQvuRTfGqcFmM t0+bUFg5eVubKQ54CRg/EjZ6DC9HieoP3hRsE8sKrWmhaqN/oKNp8l1BrOYK4VVZ A7KoZQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1792865301; x=1793470101; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=0JYKXljzvVxNfPy0F5+sSiAzdmJGE7tD1ZaAdvZfDnQ=; b=c/+awydvAzlqFP96l/V56WbzJaTRkk5Ifs+Cj77fADvByVchRVAZNQ0E0p/Wxh/wLY SJLeyf9iu7Aaj/6vGiGA4YCQeBYCJC4bPeYKBWZ5SbpW3x5aVzTiEXF/2TSREyy4x+I7 VOFOLSBE3rC+MEeRTTGrxxRHrY1KAJ08gSqqaiiGdVd9oAbjowDPT9Sw2z5+CZuB3AhG TZ/LwFrto3SiUBoqP7fYtmSkJEdRRswqHyl/W344pjTxDN2BCZPcwwHV6/kQ/4+Y9PCa SU0SZe8C2fAOps2RWzZ3l4a1xYuzOXUhORjLmRPr6+S8XCKZ/2yrRJtGrGAJc2Op9rCr u8ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792865301; x=1793470101; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=0JYKXljzvVxNfPy0F5+sSiAzdmJGE7tD1ZaAdvZfDnQ=; b=1xjQsXf6kRu8qXgQ417ysGWTtmGLISPxM/3OkfoOZiuOmzlVyR43YQg3UFGyikdqMl nNIGgQMIV+2b7WzNQl9Z8kfSSGiuKkbNm2AgPdRfCXN4+uux2qoeO/MLCzlW7kvLCLRD phcxR/uGZ5NPxuopFs+TNQbsRzMTHS6iWnpRLP2iyZITzjFFxJthljSoBa7/yDbq1T7X WeXIl/4pxwflrxF9YVyKb+5T1TmvAbRsiz4LGoWZYXZ7Ce4Y03pBmtVwYB/wWtoc3rPF ajjxL10NTIdiWiWy1PvC7Te+MUDTDd3njfOszcV1ZEZkS+bMjbBKqSRmtUeppmp00eNS qMTw== X-Gm-Message-State: AFq9FYLZZL2bFnUF1RMxOtQoUhCwMysdvueta7dHM01jeFPke4epjGB8 Eutx+dN7FtLMIqGyG7FMBk7esZQf5h+suRDoJZ68vxGVJ7F4cmTi639zfFj6+7/mVwur9w5JQhi P6npUZZcHeUD/cT2KvcryR/70HqnUr0EUSHYA1ERgwS8mj2LsPMcHah5f6wbeQRL2ww== X-Gm-Gg: AYBFou0krr6+9ElI5ZUT2oOh2jVaZR+qh02loyrlnHFbFT+xIXRV+Uol2QtLiC7dulo SB0m1Z7vFPuLpbT5lYH1BpoJKsGY3DdZ/w616XqyWdsdnUSZRz8bOx30AiM7MiQUHrJIO1qxfBa 7yCxchskSHPAD+9h/D2eefF7bi0ERwt5ZT+GXbuq1i7BBd25j2Ff0N4YDnwBXen2wQtdOPNYaCJ QzNdxt1M9A0gd43Mwh01WHTYDl9j0BxydOZNPZiv1ecjOnB2/0cUekRgN/cClUltPAwvm4WQY6u UhEYN9CX3wt8GGpIIzkp59bjSBupZ7CwdnuqugKIr4vVWXUyRIo3i7grXOjSzSptlg0XQfaavdk MlfAWdMIkEOb6NKGPWYhrUAALBq1EvxeNoeBQk+PDEi+V4+dR X-Received: by 2002:a05:7300:3a9d:b0:361:6dc4:d0b2 with SMTP id 5a478bee46e88-369e836c118mr3445395eec.2.1792865300814; Sat, 24 Oct 2026 11:08:20 -0700 (PDT) X-Received: by 2002:a05:7300:3a9d:b0:361:6dc4:d0b2 with SMTP id 5a478bee46e88-369e836c118mr3445355eec.2.1792865299895; Sat, 24 Oct 2026 11:08:19 -0700 (PDT) From: Brian Cain To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Brian Cain , Marco Liebel Subject: [PATCH v2 1/3] target/hexagon: add v79 HVX vcvt2 instructions Date: Sat, 24 Oct 2026 11:08:15 -0700 Message-Id: <20261024180817.2037169-2-brian.cain@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261024180817.2037169-1-brian.cain@oss.qualcomm.com> References: <20261024180817.2037169-1-brian.cain@oss.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: mH8LR5T_Br0f1jwvtPuy1eVqF_bCDDfb X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMDI0MDA3MiBTYWx0ZWRfX+6h/waetTuzf q1vFWeDvxjT+Hhl9sCeGDdV9EWGSXzKGV/QqWo8tRyboauzuAM/VYN88VwcD/N1t+5VpCf6N8G9 LOeK1Uw/0o3CzT3j7Q6xqeN4KmqhQ/5BJTD5eIVIeXWweXxMtFCVJj7ZoMt+Mu7d/c5xI90h2IQ 4Wo9xukw5uDRyQgeNrRob2/R7TlBh3uVpI5CaQmwgnTlybr5nqFkUMePeimlzSavlvs8eD4+l27 zW2xAzD2gh97U41ylabfJMWIFu6HD6W0rgp6ROjYUOCIfmsAt0YILmg0MuCW9hwyH+6WZNloa+4 lUxiTJxQJHNcUMSkqL71PHM2W5c9BhTkIruwtSHvnHWJ1LV5uEpmlO2ULvruOBgvuJ9Mw3ZFs5U RcTjmUVltg71fyK/fQRKuCCmjg32PHNx4Ac+DyDu5/z36HLCnmldSrolKLC9Y+CyORBZQDR9q2o /h9MSrFmr18EgJz1zBQ== X-Authority-Analysis: v=2.4 cv=PqcG/AM3 c=1 sm=1 tr=0 ts=6adcf415 cx=c_pps a=PfFC4Oe2JQzmKTvty2cRDw==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=IkcTkHD0fZMA:10 a=660iZSQnnn4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=YMgV9FUhrdKAYTUUvYB2:22 a=EUspDBNiAAAA:8 a=yoXkoL7M3VEoSO3RQYoA:9 a=QEXdDO2ut3YA:10 a=6Ab_bkdmUrQuMsNx7PHu:22 X-Proofpoint-ORIG-GUID: mH8LR5T_Br0f1jwvtPuy1eVqF_bCDDfb X-Proofpoint-Spam-Info: AW1haW4tMjYxMDI0MDA3MiBTYWx0ZWRfX2zeeeXfxGVv/ 4C4CcNF9mDfsvNsXrF59me966sD2jAJUSJwd6Or1awuccnxqXunJIv7xD4XlubM5zeo4cvKw5f5 zaxi707QzP7iU6+giSsHHcW4HcteODQ= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-10-24_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 spamscore=0 priorityscore=1501 bulkscore=0 impostorscore=0 phishscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610240072 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=brian.cain@oss.qualcomm.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1792865317209158500 Add V6_vcvt2_{hf_ub,hf_b,ub_hf,b_hf}, which differ from vcvt only in element interleaving. Reviewed-by: Pierrick Bouvier Signed-off-by: Brian Cain Reviewed-by: Marco Liebel --- tests/tcg/hexagon/check_rev_gating.c | 6 + tests/tcg/hexagon/fp_hvx_v79.c | 110 +++++++++++++++++++ target/hexagon/tag_rev_info.c.inc | 4 + target/hexagon/imported/mmvec/encode_ext.def | 4 + target/hexagon/imported/mmvec/ext.idef | 33 ++++++ tests/tcg/hexagon/meson.build | 2 + 6 files changed, 159 insertions(+) create mode 100644 tests/tcg/hexagon/fp_hvx_v79.c diff --git a/tests/tcg/hexagon/check_rev_gating.c b/tests/tcg/hexagon/check= _rev_gating.c index ad22a93bdaf..f2fea9b884f 100644 --- a/tests/tcg/hexagon/check_rev_gating.c +++ b/tests/tcg/hexagon/check_rev_gating.c @@ -124,6 +124,10 @@ TRY_FUNC(v79_dcfetchbo_nt, =20 TRY_FUNC(v79hvx_vmerge_qf, ".word 0x1f01e0e2 /* v2 =3D vmerge(v0.x, v1.w) */\n") +TRY_FUNC(v79hvx_vcvt2_hf_ub, + ".word 0x1ed5e0e2 /* v3:2.hf =3D vcvt2(v0.ub) */\n") +TRY_FUNC(v79hvx_vcvt2_b_hf, + ".word 0x1ac1e0c2 /* v2.b =3D vcvt2(v0.hf, v1.hf) */\n") =20 TRY_FUNC(v81hvx_veqhf, ".word 0x1f82c11c /* q0 =3D vcmp.eq(v1.hf, v2.hf) */\n") @@ -167,6 +171,8 @@ int main(void) assert(try_v79_dcfetchbo_nt() =3D=3D SIGILL); =20 assert(try_v79hvx_vmerge_qf() =3D=3D SIGILL); + assert(try_v79hvx_vcvt2_hf_ub() =3D=3D SIGILL); + assert(try_v79hvx_vcvt2_b_hf() =3D=3D SIGILL); =20 assert(try_v81hvx_veqhf() =3D=3D SIGILL); =20 diff --git a/tests/tcg/hexagon/fp_hvx_v79.c b/tests/tcg/hexagon/fp_hvx_v79.c new file mode 100644 index 00000000000..2f6bbd7cf40 --- /dev/null +++ b/tests/tcg/hexagon/fp_hvx_v79.c @@ -0,0 +1,110 @@ +/* + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +/* + * Tests for the HVX IEEE floating point instructions introduced in v79. + */ + +#include +#include +#include +#include +#include +#include +#include + +int err; +#include "hvx_misc.h" +#include "hex_test.h" + +/* + * The vcvt2 instructions differ from vcvt in how elements are interleaved + * between the vectors of a pair or the sources: + * + * Vdd.v[0].hf[2*i] =3D OP(Vu.FROM[4*i]); + * Vdd.v[0].hf[2*i+1] =3D OP(Vu.FROM[4*i+2]); + * Vdd.v[1].hf[2*i] =3D OP(Vu.FROM[4*i+1]); + * Vdd.v[1].hf[2*i+1] =3D OP(Vu.FROM[4*i+3]); + * + * Vd.TO[4*i] =3D OP(Vu.hf[2*i]); + * Vd.TO[4*i+1] =3D OP(Vv.hf[2*i]); + * Vd.TO[4*i+2] =3D OP(Vu.hf[2*i+1]); + * Vd.TO[4*i+3] =3D OP(Vv.hf[2*i+1]); + */ +#define DEF_TEST_VCVT2_WIDEN(FROM, MUL, ADD) \ + static void test_vcvt2_hf_##FROM(void) \ + { \ + HVX_VectorPair *hvx_output =3D (HVX_VectorPair *)&output[0]; \ + HVX_Vector buffer; \ + memset(expect, 0, sizeof(expect)); \ + for (int i =3D 0; i < MAX_VEC_SIZE_BYTES; i++) { \ + ((MMVector *)&buffer)->FROM[i] =3D i * MUL + ADD; \ + expect[i % 2].hf[2 * (i / 4) + ((i % 4) / 2)] =3D \ + raw_hf((_Float16)(((MMVector *)&buffer)->FROM[i])); \ + } \ + *hvx_output =3D Q6_Whf_vcvt2_V##FROM(buffer); \ + check_output_hf(__LINE__, 2); \ + } + +DEF_TEST_VCVT2_WIDEN(ub, 3, 1) +DEF_TEST_VCVT2_WIDEN(b, 5, 7) + +static const struct { + uint16_t hf; + uint8_t ub; + int8_t b; +} cvt2_narrow_cases[] =3D { + { HF_QNaN, UINT8_MAX, INT8_MAX }, + { HF_SNaN, UINT8_MAX, INT8_MAX }, + { HF_QNaN_neg, UINT8_MAX, INT8_MAX }, + { HF_INF, UINT8_MAX, INT8_MAX }, + { HF_INF_neg, 0, INT8_MIN }, + { HF_zero, 0, 0 }, + { HF_zero_neg, 0, 0 }, + { HF_neg_two, 0, -2 }, + { HF_one, 1, 1 }, + { 0x3e00 /* 1.5 */, 2, 2 }, + { 0x4100 /* 2.5 */, 2, 2 }, + { 0x4300 /* 3.5 */, 4, 4 }, + { 0x5640 /* 100 */, 100, 100 }, + { 0x5a40 /* 200 */, 200, INT8_MAX }, + { 0x5c00 /* 256 */, UINT8_MAX, INT8_MAX }, + { 0xd640 /* -100 */, 0, -100 }, + { 0xda40 /* -200 */, 0, INT8_MIN }, +}; +#define NUM_CVT2_NARROW_CASES ARRAY_SIZE(cvt2_narrow_cases) + +#define DEF_TEST_VCVT2_NARROW(TO) \ + static void test_vcvt2_##TO##_hf(void) \ + { \ + HVX_Vector *hvx_output =3D (HVX_Vector *)&output[0]; \ + HVX_Vector buffers[2]; \ + memset(expect, 0, sizeof(expect)); \ + for (int j =3D 0; j < MAX_VEC_SIZE_BYTES / 2; j++) { \ + for (int s =3D 0; s < 2; s++) { \ + int c =3D (2 * j + s) % NUM_CVT2_NARROW_CASES; \ + ((MMVector *)&buffers[s])->hf[j] =3D cvt2_narrow_cases[c].= hf; \ + expect[0].TO[4 * (j / 2) + 2 * (j % 2) + s] =3D \ + cvt2_narrow_cases[c].TO; \ + } \ + } \ + *hvx_output =3D Q6_V##TO##_vcvt2_VhfVhf(buffers[0], buffers[1]); \ + check_output_##TO(__LINE__, 1); \ + } + +DEF_TEST_VCVT2_NARROW(ub) +DEF_TEST_VCVT2_NARROW(b) + +int main(void) +{ + test_vcvt2_hf_ub(); + test_vcvt2_hf_b(); + test_vcvt2_ub_hf(); + test_vcvt2_b_hf(); + + puts(err ? "FAIL" : "PASS"); + return err ? 1 : 0; +} diff --git a/target/hexagon/tag_rev_info.c.inc b/target/hexagon/tag_rev_inf= o.c.inc index 41ce3cb572f..4ab135d33f3 100644 --- a/target/hexagon/tag_rev_info.c.inc +++ b/target/hexagon/tag_rev_info.c.inc @@ -680,6 +680,10 @@ static const struct tag_rev_info tag_rev_info[XX_LAST_= OPCODE] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VER_NONE }, [V6_vconv_qf32_sf] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX= _VER_NONE }, + [V6_vcvt2_b_hf] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VE= R_NONE }, + [V6_vcvt2_hf_b] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VE= R_NONE }, + [V6_vcvt2_hf_ub] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_V= ER_NONE }, + [V6_vcvt2_ub_hf] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_V= ER_NONE }, [V6_vilog2_hf] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VER= _NONE }, [V6_vilog2_qf16] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_V= ER_NONE }, [V6_vilog2_qf32] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_V= ER_NONE }, diff --git a/target/hexagon/imported/mmvec/encode_ext.def b/target/hexagon/= imported/mmvec/encode_ext.def index 34e63b89743..9605e870a1e 100644 --- a/target/hexagon/imported/mmvec/encode_ext.def +++ b/target/hexagon/imported/mmvec/encode_ext.def @@ -846,12 +846,16 @@ DEF_ENC(V6_vcvt_sf_hf,"00011110--0-0100PP1uuuuu100ddd= dd") DEF_ENC(V6_vcvt_hf_sf,"00011111011vvvvvPP1uuuuu001ddddd") DEF_ENC(V6_vcvt_hf_ub,"00011110--0-0100PP1uuuuu001ddddd") DEF_ENC(V6_vcvt_hf_b,"00011110--0-0100PP1uuuuu010ddddd") +DEF_ENC(V6_vcvt2_hf_ub,"0001111011010101PP1uuuuu111ddddd") +DEF_ENC(V6_vcvt2_hf_b,"0001111011010101PP1uuuuu110ddddd") DEF_ENC(V6_vcvt_hf_uh,"00011110--0-0100PP1uuuuu101ddddd") DEF_ENC(V6_vcvt_hf_h,"00011110--0-0100PP1uuuuu111ddddd") DEF_ENC(V6_vcvt_uh_hf,"00011110--0--101PP1uuuuu000ddddd") DEF_ENC(V6_vcvt_h_hf,"00011110--0-0110PP1uuuuu000ddddd") DEF_ENC(V6_vcvt_ub_hf,"00011111110vvvvvPP1uuuuu101ddddd") DEF_ENC(V6_vcvt_b_hf,"00011111110vvvvvPP1uuuuu110ddddd") +DEF_ENC(V6_vcvt2_ub_hf,"00011010110vvvvvPP1uuuuu111ddddd") +DEF_ENC(V6_vcvt2_b_hf,"00011010110vvvvvPP1uuuuu110ddddd") =20 /* IEEE FP vconv instructions */ DEF_ENC(V6_vconv_sf_w,"00011110--0--101PP1uuuuu011ddddd") diff --git a/target/hexagon/imported/mmvec/ext.idef b/target/hexagon/import= ed/mmvec/ext.idef index 3592930777e..b9a4858d0c1 100644 --- a/target/hexagon/imported/mmvec/ext.idef +++ b/target/hexagon/imported/mmvec/ext.idef @@ -3103,6 +3103,25 @@ ITERATOR_INSN_IEEE_FP_DOUBLE_16(32, vcvt_hf_b, "Vd= d32.hf=3Dvcvt(Vu32.b)", VddV.v[1].hf[2*i] =3D int64_to_float16_scalbn(VuV.b[4*i+2], float_ro= und_nearest_even, 0); VddV.v[1].hf[2*i+1] =3D int64_to_float16_scalbn(VuV.b[4*i+3], float_ro= und_nearest_even, 0)) =20 +/* + * The vcvt2 variants differ from vcvt only in which source elements land = in + * which half of the result pair: the even source bytes go to the first + * vector and the odd ones to the second. + */ +ITERATOR_INSN_IEEE_FP_DOUBLE_16(32, vcvt2_hf_ub, "Vdd32.hf=3Dvcvt2(Vu32.u= b)", + "Vector IEEE cvt2 from int: ub widen to hf", + VddV.v[0].hf[2*i] =3D uint64_to_float16_scalbn(VuV.ub[4*i], 0, &env-= >hvx_fp_status); + VddV.v[0].hf[2*i+1] =3D uint64_to_float16_scalbn(VuV.ub[4*i+2], 0, &en= v->hvx_fp_status); + VddV.v[1].hf[2*i] =3D uint64_to_float16_scalbn(VuV.ub[4*i+1], 0, &en= v->hvx_fp_status); + VddV.v[1].hf[2*i+1] =3D uint64_to_float16_scalbn(VuV.ub[4*i+3], 0, &en= v->hvx_fp_status)) + +ITERATOR_INSN_IEEE_FP_DOUBLE_16(32, vcvt2_hf_b, "Vdd32.hf=3Dvcvt2(Vu32.b= )", + "Vector IEEE cvt2 from int: b widen to hf", + VddV.v[0].hf[2*i] =3D int64_to_float16_scalbn(VuV.b[4*i], 0, &env->h= vx_fp_status); + VddV.v[0].hf[2*i+1] =3D int64_to_float16_scalbn(VuV.b[4*i+2], 0, &env-= >hvx_fp_status); + VddV.v[1].hf[2*i] =3D int64_to_float16_scalbn(VuV.b[4*i+1], 0, &env-= >hvx_fp_status); + VddV.v[1].hf[2*i+1] =3D int64_to_float16_scalbn(VuV.b[4*i+3], 0, &env-= >hvx_fp_status)) + ITERATOR_INSN_IEEE_FP_DOUBLE_32(32, vcvt_sf_hf, "Vdd32.sf=3Dvcvt(Vu32.hf)", "Vector IEEE cvt: hf widen to sf", VddV.v[0].sf[i] =3D f16_to_f32(VuV.hf[2*i]); @@ -3139,6 +3158,20 @@ ITERATOR_INSN_IEEE_FP_16_32(32, vcvt_b_hf, "Vd32.b= =3Dvcvt(Vu32.hf,Vv32.hf)", VdV.b[4*i+2] =3D float16_to_int8_scalbn(VvV.hf[2*i], float_round_neare= st_even, 0, &env->hvx_fp_status); VdV.b[4*i+3] =3D float16_to_int8_scalbn(VvV.hf[2*i+1], float_round_nea= rest_even, 0, &env->hvx_fp_status)) =20 +ITERATOR_INSN_IEEE_FP_16_32(32, vcvt2_ub_hf, "Vd32.ub=3Dvcvt2(Vu32.hf,Vv32= .hf)", + "Vector cvt2 to int: hf narrow to ub", + VdV.ub[4*i] =3D float16_to_uint8_scalbn(VuV.hf[2*i], float_round_nea= rest_even, 0, &env->hvx_fp_status); + VdV.ub[4*i+1] =3D float16_to_uint8_scalbn(VvV.hf[2*i], float_round_nea= rest_even, 0, &env->hvx_fp_status); + VdV.ub[4*i+2] =3D float16_to_uint8_scalbn(VuV.hf[2*i+1], float_round_n= earest_even, 0, &env->hvx_fp_status); + VdV.ub[4*i+3] =3D float16_to_uint8_scalbn(VvV.hf[2*i+1], float_round_n= earest_even, 0, &env->hvx_fp_status)) + +ITERATOR_INSN_IEEE_FP_16_32(32, vcvt2_b_hf, "Vd32.b=3Dvcvt2(Vu32.hf,Vv32.= hf)", + "Vector cvt2 to int: hf narrow to b", + VdV.b[4*i] =3D float16_to_int8_scalbn(VuV.hf[2*i], float_round_neare= st_even, 0, &env->hvx_fp_status); + VdV.b[4*i+1] =3D float16_to_int8_scalbn(VvV.hf[2*i], float_round_neare= st_even, 0, &env->hvx_fp_status); + VdV.b[4*i+2] =3D float16_to_int8_scalbn(VuV.hf[2*i+1], float_round_nea= rest_even, 0, &env->hvx_fp_status); + VdV.b[4*i+3] =3D float16_to_int8_scalbn(VvV.hf[2*i+1], float_round_nea= rest_even, 0, &env->hvx_fp_status)) + ITERATOR_INSN_SHIFT_SLOT_FLT(32, vconv_w_sf,"Vd32.w=3DVu32.sf", "Vector conversion of sf32 format to int w", VdV.w[i] =3D conv_w_sf(VuV.sf[i], &env->hvx_fp_status)) diff --git a/tests/tcg/hexagon/meson.build b/tests/tcg/hexagon/meson.build index a6ace4c77c2..d3faccf9bcd 100644 --- a/tests/tcg/hexagon/meson.build +++ b/tests/tcg/hexagon/meson.build @@ -42,6 +42,8 @@ tests +=3D { 'qemu_args': ['-cpu', 'v73,ieee-fp=3Dfalse']}, 'fp_hvx_cvt.c': {'cflags': [cflags, '-mv73', '-mhvx', '-mhvx-ieee-fp']}, 'fp_hvx_cmp.c': {'cflags': [cflags, '-mv73', '-mhvx', '-mhvx-ieee-fp']}, + 'fp_hvx_v79.c': {'cflags': [cflags, '-mv79', '-mhvx', '-mhvx-ieee-fp'], + 'qemu_args': ['-cpu', 'v79']}, 'v81_hvx.c': {'cflags': [cflags, '-mv81', '-mhvx', '-mhvx-ieee-fp'], 'qemu_args': ['-cpu', 'v81']}, 'qfloat_v81.c': {'cflags': [cflags, '-mv81', '-mhvx', '-mhvx-ieee-fp'], --=20 2.34.1 From nobody Mon Nov 23 04:34:21 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1792865346; cv=none; d=zohomail.com; s=zohoarc; b=l5cvUkQ1jPEs6lbsdG+PnGqVPDo9SU270/4pso63AUELgwq5ks01FwTbhjiKlLNV0qHrQLTixXjGSCu6aGUBVXmhezw9NSZFgzjj4nSuz0K8jY41W97lGq/kj0bQhxoue4dL5xYrTD+rE7iqSpgZ3oWqGvT0sd1hGig18vcdJSA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792865346; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YHQz6Qd7YDC4lFIWFDDi6K1pN25S/+NQ90ih0Jifd0I=; b=Y3J0lZlR0eFzUPCGRDaZyRHIMYP+60YSZeR2WtLJjYYoWkg/aI0f9QdTueXrBqIZ5s/2kF08Mu71M+KXoqS1caPOssd7qzUF8/FgQgftNBjYpM2gSIUxkDLHLOd0dOs0WcfM0fbwr9oUV8o7zYYx/78AJc9FCPS2v7NtNHdd35o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792865346501994.2921743524; Sat, 24 Oct 2026 11:09:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xKgAX-0006J9-CY; Sat, 24 Oct 2026 14:08:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xKgAR-00069e-N4 for qemu-devel@nongnu.org; Sat, 24 Oct 2026 14:08:32 -0400 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xKgAL-0002KF-5t for qemu-devel@nongnu.org; Sat, 24 Oct 2026 14:08:30 -0400 Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 69OF01vp2952627 for ; Sat, 24 Oct 2026 18:08:23 GMT Received: from mail-dy1-f199.google.com (mail-dy1-f199.google.com [74.125.82.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hgkms9n6b-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Sat, 24 Oct 2026 18:08:23 +0000 (GMT) Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-33c35f5ca6cso3589115eec.1 for ; Sat, 24 Oct 2026 11:08:23 -0700 (PDT) Received: from hu-bcain-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-369f27d5bf8sm3966963eec.4.2026.10.24.11.08.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Oct 2026 11:08:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= YHQz6Qd7YDC4lFIWFDDi6K1pN25S/+NQ90ih0Jifd0I=; b=QvT1I+uKbcHk2u1q lGJ0xTu83zNaBVEfC1MyNk94z3R0fZg1Ys69MNFygzx0nWVwULeFyyUNbc2tEvvk pFTn1SbUhupnQ2OykW1nlkZzEj247d0ZGPYkCXxANGIIqGESVLkGALiNkuN0HiTD QKx1mwYsW1P4lGPfz1C4JWlPT7VADM4SpmZdN9Yb8yWM7DvYk+14cf+HOymzcSwB 2VuG73l/L9YbIEQ4HSKif/qWN2s/Ejec7C9CUUvcjtKZNwNXhnIEItsfFi/bR54P I+kuYT3x9W2nfWxLD00PM9uw7IxiFmQ96A5sqtO6DHX6NQ2YyYXjz5iSRXMytU1N 3sX/yg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1792865303; x=1793470103; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=YHQz6Qd7YDC4lFIWFDDi6K1pN25S/+NQ90ih0Jifd0I=; b=UpR437dk/7gXQBA8vFqTsoh2uFdKrZaMM8aW/5M1rBrqPSx43W07+BDMx+jPOOf/rY A73y0oGn7n+Iktlu5Pyl18rYElgHsd8lB1GS6WL1Cck+nz7j9+dl6gT9aVwSCXdR+iMm vj14wDs5KvHiKRxX3/TGN2hBfMsuJlAI3soknFkXnUCf5xd131N2jegzf+BwVXeOftiM g8sM38HCT8jlyZGtEhrYKuEWOrRKa3//8pCTKdioEUvisqPLsj7WFbyXypapT+AylHYA yetF9/8PknikrWtxPAn7w1fKoqNE+8ASJI0eHIRDrA3O4haY1jmu8nzzV3GGT7PA1gDZ ZAFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792865303; x=1793470103; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=YHQz6Qd7YDC4lFIWFDDi6K1pN25S/+NQ90ih0Jifd0I=; b=Wps/nekfoJsbexAzAxBccQOrjvDdTwDCuAdaAtmgDIX9QpLYylQYd+LYYxIHvLEJMi xlnLpWazHRwzX270s4C3zYaDzDh86Sdo8bHN01Puvu7dcSU6E8Z6P+3zRVlaDLiPveDv 1R9TMhRgstn+cwmA+bvLx6U/mXvqOxJpmSyvTT7ho6Fcm5pCckk3vrBxXZxAZgt4WSPh 9TkCzYJEwjOdd6rP5viYRygT3lGi0T5xBtC7guhFoBhnEloToS0bTTAVfsUetMqR6ZIU AZ9dlF7RamGVzcfID3gE3h/EP+NM+WpxlFobos1tegrcCc5uhZzS3iusRiU2LZ5k1HO8 poFA== X-Gm-Message-State: AFq9FYJeotRJoE49Mq09sISs6cSKgHaGTcjvhauXLBpxwmYo9cONdIZM 7KL/05QvyuaDaG2X+c97NRSVwJSgKExCPGYPn1XBQ/do/MDo4wM32t4hO1uQA5EruceZrKttx5o iFDJ2dIUXGWLX8ufXmOOvLdjBXceDXYzL+PX0tKmEFe3ZjkoOJA5fHnjFNZA8fZhC2g== X-Gm-Gg: AYBFou0e/jlxljPV1Pyv6/WxlYo2/WyhiU3377oiLWxaVsbCsZ6K99RqBAzfh1Ql3M0 /rLrDfudMIQcZubMO9kR03G2SCOZnWOhIUMgjaS9E1acFAWEjlzmMYkeQ6PmPJ7WwQkzHPfjHeh 2I8PTTv/VYI2urToDUtHs7GqXvtrfUk87ss24n4DxYDJmJpi+MOg1J7S262A5PF6n4pFD3HyPTn BN+kfTIIlaCCNOx/CuPYfbBjAjJgR0xDH0FRsRSvhrxyEzOPmazIDibUFePT5+NAhkX3mvw+fUS Nz7yt1/wzT7ivKAXGSWht/P5O3CRetRYhFjIHqHrA4KQAcP5w1t0FeI7Hrb3J2CZohvADXPo4fG 4SgDkYquUaulMPywvxGkp2g8vprio7RuIFGbVYutvqQ9tZry1 X-Received: by 2002:a05:693c:2804:b0:368:40c6:3a01 with SMTP id 5a478bee46e88-369e8362dcbmr3890279eec.2.1792865302386; Sat, 24 Oct 2026 11:08:22 -0700 (PDT) X-Received: by 2002:a05:693c:2804:b0:368:40c6:3a01 with SMTP id 5a478bee46e88-369e8362dcbmr3890234eec.2.1792865301309; Sat, 24 Oct 2026 11:08:21 -0700 (PDT) From: Brian Cain To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Brian Cain , Marco Liebel Subject: [PATCH v2 2/3] target/hexagon: add v79 HVX FP8 instructions Date: Sat, 24 Oct 2026 11:08:16 -0700 Message-Id: <20261024180817.2037169-3-brian.cain@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261024180817.2037169-1-brian.cain@oss.qualcomm.com> References: <20261024180817.2037169-1-brian.cain@oss.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: qRH7dX9MxQjg-luoAQaEsp8B4CAng9qy X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMDI0MDA3MiBTYWx0ZWRfXzWFSMK4xv/l6 blNr5EtTldzaj1iCLKp4FAUrbRZLH7aCdH+J+F4s8jjYT7Q3hThktHEx9bxbLliSSgpJQvthhIB IJjYcX8CtObaQK0H2AbtwcdduuvdJQ2ovkVafplZ7VNvA5dnt9U6wlDDz1R6opzbi6ZlbC6Q96o pQkSdDvQBstrKGzeSdiYpJr/1Z7sNhAUIamLi+9byFofWdoqMcMMgDGvPCq4uAS41USDEGswAhq CY74DhXyNk1O6Hb4WC/qE3gNxTP9f1TvGG7/7oPhLTuvTU42QcwCksaM9CYiYrXRtrlZYUSExM/ 2D4Efhzy66LacBbi/L1kruNyr+fOGz0o5UnqPhk5aCfp/8ZHdDeUpKTSzmtSGNX89s44IgiBJ0g UNAEdCmVItkja8SOuutxLAjPkyhEv56cTGdp5/TfeQz0fTc9Gj81KSrJt+5DVdg2W/F578ilBBb tfwCFwTTY4Y2n5BRndg== X-Proofpoint-Spam-Info: AW1haW4tMjYxMDI0MDA3MiBTYWx0ZWRfX9IXzPQRBu2kB V/co486iSrMe7i3OOQIzghQ8+pv8TS8bAjwLCDudaRiH4GoehJUADl1DfLbmB4ZscSR3KIqYSK2 j/NMuM/LETX1xdZ6bYOHnh3HT6HS0gM= X-Authority-Analysis: v=2.4 cv=UqX2pOwB c=1 sm=1 tr=0 ts=6adcf417 cx=c_pps a=cFYjgdjTJScbgFmBucgdfQ==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=IkcTkHD0fZMA:10 a=660iZSQnnn4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=Um2Pa8k9VHT-vaBCBUpS:22 a=EUspDBNiAAAA:8 a=_5u4GtUHH7punIX7pfYA:9 a=QEXdDO2ut3YA:10 a=scEy_gLbYbu1JhEsrz4S:22 X-Proofpoint-GUID: qRH7dX9MxQjg-luoAQaEsp8B4CAng9qy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-10-24_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 bulkscore=0 phishscore=0 adultscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610240072 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=brian.cain@oss.qualcomm.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1792865347817158500 Add the E4M3FNUZ FP8 add, sub, mpy, convert, neg, abs, min and max instructions, and the USR.FPSAT bit that controls saturation. Signed-off-by: Brian Cain --- target/hexagon/mmvec/hvx_ieee_fp.h | 27 ++ target/hexagon/mmvec/mmvec.h | 1 + target/hexagon/attribs_def.h.inc | 1 + target/hexagon/reg_fields_def.h.inc | 1 + target/hexagon/genptr.c | 7 +- target/hexagon/mmvec/hvx_ieee_fp.c | 128 +++++++ tests/tcg/hexagon/check_rev_gating.c | 18 + tests/tcg/hexagon/fp_hvx_v79.c | 368 +++++++++++++++++++ target/hexagon/tag_rev_info.c.inc | 12 + target/hexagon/imported/mmvec/encode_ext.def | 12 + target/hexagon/imported/mmvec/ext.idef | 78 ++++ 11 files changed, 652 insertions(+), 1 deletion(-) diff --git a/target/hexagon/mmvec/hvx_ieee_fp.h b/target/hexagon/mmvec/hvx_= ieee_fp.h index 6efc39eb203..229ee0ee516 100644 --- a/target/hexagon/mmvec/hvx_ieee_fp.h +++ b/target/hexagon/mmvec/hvx_ieee_fp.h @@ -35,6 +35,33 @@ uint16_t cmpgt_hf(float16 a1, float16 a2, float_status *= fp_status); uint32_t cmpeq_sf(float32 a1, float32 a2, float_status *fp_status); uint16_t cmpeq_hf(float16 a1, float16 a2, float_status *fp_status); =20 +/* + * FP8 instructions. The FP8 format is E4M3FNUZ: one sign bit, four expon= ent + * bits (bias 8) and three fraction bits, with no infinities and no negati= ve + * zero. The encoding that would be negative zero, 0x80, is the only NaN. + * softfloat has no such format, so values are widened to float16 (which h= olds + * every FP8 value exactly) to operate on them. + */ +#define F8_NAN 0x80 +#define F8_MAX_NORM 0x7f + +float16 f8_to_f16(uint8_t a, float_status *fp_status); +/* + * Narrow with round-to-nearest-even. Infinity and results too large for = FP8 + * become the largest normal number if sat is set and NaN otherwise. + */ +uint8_t f16_to_f8(float16 a, bool sat, float_status *fp_status); + +float16 fp_add_hf_f8(uint8_t a1, uint8_t a2, float_status *fp_status); +float16 fp_sub_hf_f8(uint8_t a1, uint8_t a2, float_status *fp_status); +float16 fp_mult_hf_f8(uint8_t a1, uint8_t a2, float_status *fp_status); +float16 fp_mult_hf_f8_acc(uint8_t a1, uint8_t a2, float16 acc, + float_status *fp_status); +uint8_t fp_neg_f8(uint8_t a); +uint8_t fp_abs_f8(uint8_t a); +uint8_t fp_min_f8(uint8_t a1, uint8_t a2, float_status *fp_status); +uint8_t fp_max_f8(uint8_t a1, uint8_t a2, float_status *fp_status); + /* IEEE BFloat instructions */ =20 #define fp_mult_sf_bf(A, B) \ diff --git a/target/hexagon/mmvec/mmvec.h b/target/hexagon/mmvec/mmvec.h index de36e12e30a..7b8cce3a37b 100644 --- a/target/hexagon/mmvec/mmvec.h +++ b/target/hexagon/mmvec/mmvec.h @@ -55,6 +55,7 @@ typedef struct { int8_t b[MAX_VEC_SIZE_BYTES / 1]; float32 sf[MAX_VEC_SIZE_BYTES / 4]; float16 hf[MAX_VEC_SIZE_BYTES / 2]; + uint8_t f8[MAX_VEC_SIZE_BYTES / 1]; bfloat16 bf[MAX_VEC_SIZE_BYTES / 2]; /* qfloat "visible" mantissa/exponent, sans the extended bits belo= w */ int32_t qf32[MAX_VEC_SIZE_BYTES / 4]; diff --git a/target/hexagon/attribs_def.h.inc b/target/hexagon/attribs_def.= h.inc index 5a98ea33139..9ec57945fab 100644 --- a/target/hexagon/attribs_def.h.inc +++ b/target/hexagon/attribs_def.h.inc @@ -203,6 +203,7 @@ DEF_ATTRIB(RESTRICT_LATEPRED, "Predicate can not be use= d as a .new.", "", "") /* HVX IEEE FP extension attributes */ DEF_ATTRIB(HVX_IEEE_FP, "HVX IEEE FP extension instruction", "", "") DEF_ATTRIB(HVX_IEEE_FP_ACC, "HVX IEEE FP accumulate instruction", "", "") +DEF_ATTRIB(HVX_IEEE_FP_OUT_8, "HVX IEEE FP 8-bit output", "", "") DEF_ATTRIB(HVX_IEEE_FP_OUT_16, "HVX IEEE FP 16-bit output", "", "") DEF_ATTRIB(HVX_IEEE_FP_OUT_32, "HVX IEEE FP 32-bit output", "", "") DEF_ATTRIB(CVI_VX_NO_TMP_LD, "HVX multiply without tmp load", "", "") diff --git a/target/hexagon/reg_fields_def.h.inc b/target/hexagon/reg_field= s_def.h.inc index 553f6ffffbc..0951a3f2694 100644 --- a/target/hexagon/reg_fields_def.h.inc +++ b/target/hexagon/reg_fields_def.h.inc @@ -35,6 +35,7 @@ DEF_REG_FIELD(USR_LPCFG, 8, 2) DEF_REG_FIELD(USR_FPDAZ, 17, 1) =20 DEF_REG_FIELD(USR_FPRND, 22, 2) +DEF_REG_FIELD(USR_FPSAT, 24, 1) =20 DEF_REG_FIELD(USR_FPINVE, 25, 1) DEF_REG_FIELD(USR_FPDBZE, 26, 1) diff --git a/target/hexagon/genptr.c b/target/hexagon/genptr.c index 1a68d8c1b8d..fe70ea6aa06 100644 --- a/target/hexagon/genptr.c +++ b/target/hexagon/genptr.c @@ -552,7 +552,12 @@ static inline void gen_write_ctrl_reg(DisasContext *ct= x, int reg_num, if (reg_num =3D=3D HEX_REG_P3_0_ALIASED) { gen_write_p3_0(ctx, val); } else { - const target_ulong reg_mask =3D reg_immut_masks[reg_num]; + target_ulong reg_mask =3D reg_immut_masks[reg_num]; + if (reg_num =3D=3D HEX_REG_USR && + ctx->hex_def->hex_version >=3D HEX_VER_V79) { + /* USR.FPSAT is reserved before v79 */ + reg_mask &=3D ~fGET_REG_FIELD_MASK(USR_FPSAT); + } gen_masked_reg_write(val, hex_gpr[reg_num], reg_mask); tcg_gen_mov_tl(get_result_gpr(ctx, reg_num), val); if (reg_num =3D=3D HEX_REG_QEMU_PKT_CNT) { diff --git a/target/hexagon/mmvec/hvx_ieee_fp.c b/target/hexagon/mmvec/hvx_= ieee_fp.c index e0971147a3d..038725dce57 100644 --- a/target/hexagon/mmvec/hvx_ieee_fp.c +++ b/target/hexagon/mmvec/hvx_ieee_fp.c @@ -6,6 +6,8 @@ =20 #include "qemu/osdep.h" #include "hvx_ieee_fp.h" +#include "fpu/softfloat-parts.h" +#include "fpu/softfloat-macros.h" =20 float32 fp_mult_sf_hf(float16 a1, float16 a2, float_status *fp_status) { @@ -159,3 +161,129 @@ uint16_t cmpeq_hf(float16 a1, float16 a2, float_statu= s *fp_status) { return float16_eq_quiet(a1, a2, fp_status); } + +/* IEEE FP8 instructions */ + +float16 f8_to_f16(uint8_t a, float_status *fp_status) +{ + int exp =3D extract32(a, 3, 4); + int frac =3D extract32(a, 0, 3); + float16 ret; + + if (a =3D=3D F8_NAN) { + return float16_default_nan(fp_status); + } + if (a =3D=3D 0) { + return float16_zero; + } + + /* + * The value is sig * 2^(exp - 11), where sig is the fraction with the + * implicit bit; the smallest exponent is shared with the subnormals. + */ + ret =3D uint64_to_float16_scalbn(exp ? frac | 8 : frac, (exp ? exp : 1= ) - 11, + fp_status); + return a & 0x80 ? float16_chs(ret) : ret; +} + +uint8_t f16_to_f8(float16 a, bool sat, float_status *fp_status) +{ + FloatParts64 p =3D float16_unpack_canonical(a, fp_status); + uint8_t sign =3D p.sign ? 0x80 : 0; + uint64_t frac; + int shift, code; + + switch (p.cls) { + case float_class_qnan: + case float_class_snan: + return F8_NAN; + case float_class_inf: + return sat ? sign | F8_MAX_NORM : F8_NAN; + case float_class_zero: + return 0; + default: + break; + } + + /* + * p.frac has its implicit bit at bit 63. FP8 keeps that bit and three + * fraction bits, fewer for subnormal results, which start at 2^-7. + * Shift down to the rounding position, keeping three bits to round on. + */ + shift =3D 60 + (p.exp < -7 ? -7 - p.exp : 0); + shift64RightJamming(p.frac, shift - 3, &frac); + code =3D frac >> 3; + if ((frac & 7) > 4 || ((frac & 7) =3D=3D 4 && (code & 1))) { + code++; + } + + if (p.exp >=3D -7) { + /* Rounding up to 2^(exp+1) carries into the exponent field */ + code +=3D (p.exp + 8) * 8 - 8; + } + if (p.exp > 7 || code > F8_MAX_NORM) { + return sat ? sign | F8_MAX_NORM : F8_NAN; + } + /* There's no negative zero */ + return code ? sign | code : 0; +} + +float16 fp_add_hf_f8(uint8_t a1, uint8_t a2, float_status *fp_status) +{ + return float16_add(f8_to_f16(a1, fp_status), f8_to_f16(a2, fp_status), + fp_status); +} + +float16 fp_sub_hf_f8(uint8_t a1, uint8_t a2, float_status *fp_status) +{ + return float16_sub(f8_to_f16(a1, fp_status), f8_to_f16(a2, fp_status), + fp_status); +} + +float16 fp_mult_hf_f8(uint8_t a1, uint8_t a2, float_status *fp_status) +{ + return float16_mul(f8_to_f16(a1, fp_status), f8_to_f16(a2, fp_status), + fp_status); +} + +float16 fp_mult_hf_f8_acc(uint8_t a1, uint8_t a2, float16 acc, + float_status *fp_status) +{ + return float16_muladd(f8_to_f16(a1, fp_status), f8_to_f16(a2, fp_statu= s), + acc, 0, fp_status); +} + +uint8_t fp_neg_f8(uint8_t a) +{ + /* Zero has no negative counterpart, and NaN stays NaN */ + return a =3D=3D 0 || a =3D=3D F8_NAN ? a : a ^ 0x80; +} + +uint8_t fp_abs_f8(uint8_t a) +{ + return a =3D=3D F8_NAN ? a : a & 0x7f; +} + +/* + * These return NaN if either input is, unlike the IEEE min/max which retu= rn + * the number. + */ +uint8_t fp_min_f8(uint8_t a1, uint8_t a2, float_status *fp_status) +{ + if (a1 =3D=3D F8_NAN || a2 =3D=3D F8_NAN) { + return F8_NAN; + } + return f16_to_f8(float16_min(f8_to_f16(a1, fp_status), + f8_to_f16(a2, fp_status), fp_status), + true, fp_status); +} + +uint8_t fp_max_f8(uint8_t a1, uint8_t a2, float_status *fp_status) +{ + if (a1 =3D=3D F8_NAN || a2 =3D=3D F8_NAN) { + return F8_NAN; + } + return f16_to_f8(float16_max(f8_to_f16(a1, fp_status), + f8_to_f16(a2, fp_status), fp_status), + true, fp_status); +} diff --git a/tests/tcg/hexagon/check_rev_gating.c b/tests/tcg/hexagon/check= _rev_gating.c index f2fea9b884f..a0b9474492e 100644 --- a/tests/tcg/hexagon/check_rev_gating.c +++ b/tests/tcg/hexagon/check_rev_gating.c @@ -128,6 +128,18 @@ TRY_FUNC(v79hvx_vcvt2_hf_ub, ".word 0x1ed5e0e2 /* v3:2.hf =3D vcvt2(v0.ub) */\n") TRY_FUNC(v79hvx_vcvt2_b_hf, ".word 0x1ac1e0c2 /* v2.b =3D vcvt2(v0.hf, v1.hf) */\n") +TRY_FUNC(v79hvx_vcvt_f8_hf, + ".word 0x1fe1e040 /* v0.f8 =3D vcvt(v0.hf, v1.hf) */\n") +TRY_FUNC(v79hvx_vcvt_hf_f8, + ".word 0x1e05e0a2 /* v3:2.hf =3D vcvt(v0.f8) */\n") +TRY_FUNC(v79hvx_vmpy_hf_f8, + ".word 0x1f80c0c0 /* v1:0.hf =3D vmpy(v0.f8, v0.f8) */\n") +TRY_FUNC(v79hvx_vmpy_hf_f8_acc, + ".word 0x1f80c0e0 /* v1:0.hf +=3D vmpy(v0.f8, v0.f8) */\n") +TRY_FUNC(v79hvx_vfneg_f8, + ".word 0x1c66e0e2 /* v2.f8 =3D vfneg(v0.f8) */\n") +TRY_FUNC(v79hvx_vfmin_f8, + ".word 0x1c61e082 /* v2.f8 =3D vfmin(v0.f8, v1.f8) */\n") =20 TRY_FUNC(v81hvx_veqhf, ".word 0x1f82c11c /* q0 =3D vcmp.eq(v1.hf, v2.hf) */\n") @@ -173,6 +185,12 @@ int main(void) assert(try_v79hvx_vmerge_qf() =3D=3D SIGILL); assert(try_v79hvx_vcvt2_hf_ub() =3D=3D SIGILL); assert(try_v79hvx_vcvt2_b_hf() =3D=3D SIGILL); + assert(try_v79hvx_vcvt_f8_hf() =3D=3D SIGILL); + assert(try_v79hvx_vcvt_hf_f8() =3D=3D SIGILL); + assert(try_v79hvx_vmpy_hf_f8() =3D=3D SIGILL); + assert(try_v79hvx_vmpy_hf_f8_acc() =3D=3D SIGILL); + assert(try_v79hvx_vfneg_f8() =3D=3D SIGILL); + assert(try_v79hvx_vfmin_f8() =3D=3D SIGILL); =20 assert(try_v81hvx_veqhf() =3D=3D SIGILL); =20 diff --git a/tests/tcg/hexagon/fp_hvx_v79.c b/tests/tcg/hexagon/fp_hvx_v79.c index 2f6bbd7cf40..084cced93c1 100644 --- a/tests/tcg/hexagon/fp_hvx_v79.c +++ b/tests/tcg/hexagon/fp_hvx_v79.c @@ -98,6 +98,362 @@ static const struct { DEF_TEST_VCVT2_NARROW(ub) DEF_TEST_VCVT2_NARROW(b) =20 +/* + * FP8 instructions + * + * Each test first checks a table of corner cases against explicit expected + * results. It then runs the instruction over a broad sweep of inputs that + * covers every value, or every pair of values, and compares a hash of all= of + * the results with a reference one. + */ +#define F8_NAN 0x80 +#define HF_NAN 0x7fff + +/* + * The widening FP8 instructions put the even-numbered bytes of each word = in + * the first vector of the result pair and the odd-numbered ones in the + * second, like vcvt2 does. + */ +#define WIDEN_VEC(I) ((I) % 2) +#define WIDEN_IDX(I) (2 * ((I) / 4) + (((I) % 4) / 2)) + +#define HASH_INIT 0xcbf29ce484222325ULL + +static void hash_bytes(uint64_t *hash, const void *buf, size_t len) +{ + const uint8_t *p =3D buf; + + for (size_t i =3D 0; i < len; i++) { + *hash =3D (*hash ^ p[i]) * 0x100000001b3ULL; + } +} + +static void check_hash(int line, uint64_t hash, uint64_t golden) +{ + if (hash !=3D golden) { + printf("ERROR at line %d: hash 0x%016" PRIx64 " !=3D 0x%016" PRIx6= 4 "\n", + line, hash, golden); + err++; + } +} + +/* Operands and the expected results of the operations on them */ +static const struct { + uint8_t a, b; + uint16_t add, sub, mpy; + uint8_t min, max; +} f8_cases[] =3D { + /* NaN, with either operand */ + { 0x80, 0x40, HF_NAN, HF_NAN, HF_NAN, F8_NAN, F8_NAN }, + { 0x40, 0x80, HF_NAN, HF_NAN, HF_NAN, F8_NAN, F8_NAN }, + { 0x80, 0x80, HF_NAN, HF_NAN, HF_NAN, F8_NAN, F8_NAN }, + /* Zero, which has no negative */ + { 0x00, 0x00, 0x0000, 0x0000, 0x0000, 0x00, 0x00 }, + { 0x00, 0x40, 0x3c00, 0xbc00, 0x0000, 0x00, 0x40 }, + /* One and minus one: exact cancellation gives positive zero */ + { 0x40, 0x40, 0x4000, 0x0000, 0x3c00, 0x40, 0x40 }, + { 0x40, 0xc0, 0x0000, 0x4000, 0xbc00, 0xc0, 0x40 }, + /* The largest magnitude, 240 */ + { 0x7f, 0x7f, 0x5f80, 0x0000, 0x7b08, 0x7f, 0x7f }, + { 0x7f, 0xff, 0x0000, 0x5f80, 0xfb08, 0xff, 0x7f }, + { 0xff, 0xff, 0xdf80, 0x0000, 0x7b08, 0xff, 0xff }, + /* The smallest subnormal and the largest, next to the smallest normal= */ + { 0x01, 0x01, 0x1800, 0x0000, 0x0010, 0x01, 0x01 }, + { 0x01, 0x40, 0x3c01, 0xbbfe, 0x1400, 0x01, 0x40 }, + { 0x07, 0x08, 0x2380, 0x9400, 0x0380, 0x07, 0x08 }, + { 0x44, 0x01, 0x3e01, 0x3dff, 0x1600, 0x01, 0x44 }, +}; +#define NUM_F8_CASES ARRAY_SIZE(f8_cases) + +#define DEF_TEST_F8_BINARY_HF(NAME, INTRIN, FIELD, GOLDEN) \ + static void test_##NAME(void) \ + { \ + HVX_VectorPair *hvx_output =3D (HVX_VectorPair *)&output[0]; \ + uint64_t hash =3D HASH_INIT; \ + HVX_Vector a, b; \ + for (int i =3D 0; i < MAX_VEC_SIZE_BYTES; i++) { \ + int c =3D i % NUM_F8_CASES; \ + ((MMVector *)&a)->ub[i] =3D f8_cases[c].a; \ + ((MMVector *)&b)->ub[i] =3D f8_cases[c].b; \ + expect[WIDEN_VEC(i)].hf[WIDEN_IDX(i)] =3D f8_cases[c].FIELD; \ + } \ + *hvx_output =3D INTRIN(a, b); \ + check_output_hf(__LINE__, 2); \ + /* Every pair of FP8 values, 128 at a time */ \ + for (int blk =3D 0; blk < 512; blk++) { \ + for (int i =3D 0; i < MAX_VEC_SIZE_BYTES; i++) { \ + int pair =3D blk * MAX_VEC_SIZE_BYTES + i; \ + ((MMVector *)&a)->ub[i] =3D pair & 0xff; \ + ((MMVector *)&b)->ub[i] =3D pair >> 8; \ + } \ + *hvx_output =3D INTRIN(a, b); \ + hash_bytes(&hash, hvx_output, sizeof(*hvx_output)); \ + } \ + check_hash(__LINE__, hash, GOLDEN); \ + } + +#define DEF_TEST_F8_BINARY_UB(NAME, INTRIN, FIELD, GOLDEN) \ + static void test_##NAME(void) \ + { \ + HVX_Vector *hvx_output =3D (HVX_Vector *)&output[0]; \ + uint64_t hash =3D HASH_INIT; \ + HVX_Vector a, b; \ + for (int i =3D 0; i < MAX_VEC_SIZE_BYTES; i++) { \ + int c =3D i % NUM_F8_CASES; \ + ((MMVector *)&a)->ub[i] =3D f8_cases[c].a; \ + ((MMVector *)&b)->ub[i] =3D f8_cases[c].b; \ + expect[0].ub[i] =3D f8_cases[c].FIELD; \ + } \ + *hvx_output =3D INTRIN(a, b); \ + check_output_ub(__LINE__, 1); \ + for (int blk =3D 0; blk < 512; blk++) { \ + for (int i =3D 0; i < MAX_VEC_SIZE_BYTES; i++) { \ + int pair =3D blk * MAX_VEC_SIZE_BYTES + i; \ + ((MMVector *)&a)->ub[i] =3D pair & 0xff; \ + ((MMVector *)&b)->ub[i] =3D pair >> 8; \ + } \ + *hvx_output =3D INTRIN(a, b); \ + hash_bytes(&hash, hvx_output, sizeof(*hvx_output)); \ + } \ + check_hash(__LINE__, hash, GOLDEN); \ + } + +DEF_TEST_F8_BINARY_HF(vadd_hf_f8, Q6_Whf_vadd_VV, add, 0x2e57ea6fa0a5770bU= LL) +DEF_TEST_F8_BINARY_HF(vsub_hf_f8, Q6_Whf_vsub_VV, sub, 0xe5fcfee5b66a9333U= LL) +DEF_TEST_F8_BINARY_HF(vmpy_hf_f8, Q6_Whf_vmpy_VV, mpy, 0x9edf5d41219d76dfU= LL) +DEF_TEST_F8_BINARY_UB(vfmin_f8, Q6_V_vfmin_VV, min, 0x9d394d7796c56725ULL) +DEF_TEST_F8_BINARY_UB(vfmax_f8, Q6_V_vfmax_VV, max, 0xd4e8b1560e8feea5ULL) + +/* The accumulator is added to the product of the operands */ +static const struct { + uint8_t a, b; + uint16_t acc, result; +} f8_acc_cases[] =3D { + { 0x40, 0x40, 0x0000, 0x3c00 }, + { 0x40, 0x40, 0x3c00, 0x4000 }, + { 0x40, 0x40, 0xbc00, 0x0000 }, + { 0x40, 0xc0, 0x3c00, 0x0000 }, + { 0x7f, 0x7f, 0x7bff, 0x7c00 }, + { 0x7f, 0xff, 0xfbff, 0xfc00 }, + { 0x01, 0x01, 0x0001, 0x0011 }, + /* A NaN operand or accumulator, and an infinite accumulator */ + { 0x80, 0x40, 0x3c00, HF_NAN }, + { 0x40, 0x40, 0x7e00, HF_NAN }, + { 0x40, 0x40, 0x7c00, 0x7c00 }, +}; +#define NUM_F8_ACC_CASES ARRAY_SIZE(f8_acc_cases) + +static const uint16_t acc_values[] =3D { + 0x0000, 0x8000, 0x3c00, 0xbc00, 0x6800, 0x0001, 0x7bff, 0xfbff, 0x7c00, + 0xfc00, 0x7e00, 0x7d00, 0x1234, 0xa5c3, +}; + +static void test_vmpy_hf_f8_acc(void) +{ + HVX_VectorPair *hvx_output =3D (HVX_VectorPair *)&output[0]; + uint64_t hash =3D HASH_INIT; + HVX_VectorPair acc; + HVX_Vector a, b; + + for (int i =3D 0; i < MAX_VEC_SIZE_BYTES; i++) { + int c =3D i % NUM_F8_ACC_CASES; + + ((MMVector *)&a)->ub[i] =3D f8_acc_cases[c].a; + ((MMVector *)&b)->ub[i] =3D f8_acc_cases[c].b; + ((MMVector *)&acc)->hf[WIDEN_VEC(i) * 64 + WIDEN_IDX(i)] =3D + f8_acc_cases[c].acc; + expect[WIDEN_VEC(i)].hf[WIDEN_IDX(i)] =3D f8_acc_cases[c].result; + } + *hvx_output =3D Q6_Whf_vmpyacc_WhfVV(acc, a, b); + check_output_hf(__LINE__, 2); + + /* + * Every pair of FP8 values with each of the accumulator values, and w= ith + * one that is close to cancelling the product. + */ + for (int n =3D 0; n <=3D ARRAY_SIZE(acc_values); n++) { + for (int blk =3D 0; blk < 512; blk++) { + for (int i =3D 0; i < MAX_VEC_SIZE_BYTES; i++) { + int pair =3D blk * MAX_VEC_SIZE_BYTES + i; + + ((MMVector *)&a)->ub[i] =3D pair & 0xff; + ((MMVector *)&b)->ub[i] =3D pair >> 8; + } + if (n =3D=3D ARRAY_SIZE(acc_values)) { + acc =3D Q6_Whf_vmpy_VV(a, b); + for (int k =3D 0; k < MAX_VEC_SIZE_BYTES; k++) { + ((MMVector *)&acc)->hf[k] ^=3D 0x8000 ^ (k & 3); + } + } else { + for (int k =3D 0; k < MAX_VEC_SIZE_BYTES; k++) { + ((MMVector *)&acc)->hf[k] =3D acc_values[n]; + } + } + *hvx_output =3D Q6_Whf_vmpyacc_WhfVV(acc, a, b); + hash_bytes(&hash, hvx_output, sizeof(*hvx_output)); + } + } + check_hash(__LINE__, hash, 0x85def62d6d02aea8ULL); +} + +static const struct { + uint8_t f8; + uint16_t hf; +} cvt_hf_f8_cases[] =3D { + { 0x00, 0x0000 }, + { 0x01, 0x1400 }, + { 0x07, 0x1f00 }, + { 0x08, 0x2000 }, + { 0x40, 0x3c00 }, + { 0x7f, 0x5b80 }, + { 0x80, HF_NAN }, + { 0xff, 0xdb80 }, +}; +#define NUM_CVT_HF_F8_CASES ARRAY_SIZE(cvt_hf_f8_cases) + +static void test_vcvt_hf_f8(void) +{ + HVX_VectorPair *hvx_output =3D (HVX_VectorPair *)&output[0]; + uint64_t hash =3D HASH_INIT; + HVX_Vector a; + + for (int i =3D 0; i < MAX_VEC_SIZE_BYTES; i++) { + int c =3D i % NUM_CVT_HF_F8_CASES; + + ((MMVector *)&a)->ub[i] =3D cvt_hf_f8_cases[c].f8; + expect[WIDEN_VEC(i)].hf[WIDEN_IDX(i)] =3D cvt_hf_f8_cases[c].hf; + } + *hvx_output =3D Q6_Whf_vcvt_V(a); + check_output_hf(__LINE__, 2); + + /* Every FP8 value */ + for (int blk =3D 0; blk < 2; blk++) { + for (int i =3D 0; i < MAX_VEC_SIZE_BYTES; i++) { + ((MMVector *)&a)->ub[i] =3D blk * MAX_VEC_SIZE_BYTES + i; + } + *hvx_output =3D Q6_Whf_vcvt_V(a); + hash_bytes(&hash, hvx_output, sizeof(*hvx_output)); + } + check_hash(__LINE__, hash, 0xf09689ef20d70fafULL); +} + +#define DEF_TEST_F8_UNARY(NAME, INTRIN, REF) \ + static void test_##NAME(void) \ + { \ + HVX_Vector *hvx_output =3D (HVX_Vector *)&output[0]; \ + HVX_Vector a; \ + for (int blk =3D 0; blk < 2; blk++) { \ + for (int i =3D 0; i < MAX_VEC_SIZE_BYTES; i++) { \ + int f8 =3D blk * MAX_VEC_SIZE_BYTES + i; \ + ((MMVector *)&a)->ub[i] =3D f8; \ + expect[0].ub[i] =3D REF(f8); \ + } \ + *hvx_output =3D INTRIN(a); \ + check_output_ub(__LINE__, 1); \ + } \ + } + +static uint8_t ref_neg(uint8_t f8) +{ + return f8 =3D=3D 0 || f8 =3D=3D F8_NAN ? f8 : f8 ^ 0x80; +} + +static uint8_t ref_abs(uint8_t f8) +{ + return f8 =3D=3D F8_NAN ? f8 : f8 & 0x7f; +} + +DEF_TEST_F8_UNARY(vfneg_f8, Q6_V_vfneg_V, ref_neg) +DEF_TEST_F8_UNARY(vabs_f8, Q6_V_vabs_V, ref_abs) + +/* + * USR.FPSAT picks what the narrowing conversion does on overflow, so it's= set + * before the source operands are loaded to keep the compiler from schedul= ing + * the conversion ahead of it. + */ +static void set_fpsat(bool sat) +{ + uint32_t usr; + + asm volatile("%[usr] =3D usr" : [usr] "=3Dr"(usr)); + usr =3D sat ? usr | (1 << 24) : usr & ~(1 << 24); + asm volatile("usr =3D %[usr]" : : [usr] "r"(usr)); +} + +/* The results without and with saturation */ +static const struct { + uint16_t hf; + uint8_t f8, f8_sat; +} cvt_f8_hf_cases[] =3D { + /* NaN, infinity, and zero, which has no negative */ + { 0x7e00, F8_NAN, F8_NAN }, + { 0x7d00, F8_NAN, F8_NAN }, + { 0xfe00, F8_NAN, F8_NAN }, + { 0x7c00, F8_NAN, 0x7f }, + { 0xfc00, F8_NAN, 0xff }, + { 0x0000, 0x00, 0x00 }, + { 0x8000, 0x00, 0x00 }, + { 0x3c00, 0x40, 0x40 }, + { 0xbc00, 0xc0, 0xc0 }, + /* The largest magnitude, 240, and values rounding to it or overflowin= g */ + { 0x5b80, 0x7f, 0x7f }, + { 0xdb80, 0xff, 0xff }, + { 0x5ba0, 0x7f, 0x7f }, + { 0x5b40, 0x7e, 0x7e }, + { 0x5bc0, F8_NAN, 0x7f }, + { 0x5c00, F8_NAN, 0x7f }, + /* Subnormals: exact, ties to even, and rounding to zero */ + { 0x1400, 0x01, 0x01 }, + { 0x1000, 0x00, 0x00 }, + { 0x1600, 0x02, 0x02 }, + { 0x1800, 0x02, 0x02 }, + { 0x1200, 0x01, 0x01 }, + { 0x0001, 0x00, 0x00 }, + { 0x8001, 0x00, 0x00 }, +}; +#define NUM_CVT_F8_HF_CASES ARRAY_SIZE(cvt_f8_hf_cases) + +static void test_vcvt_f8_hf(bool sat) +{ + HVX_Vector *hvx_output =3D (HVX_Vector *)&output[0]; + HVX_Vector buffers[2]; + /* volatile keeps the loads of the sources after set_fpsat() */ + volatile HVX_Vector *vbuffers =3D buffers; + uint64_t hash =3D HASH_INIT; + + for (int j =3D 0; j < MAX_VEC_SIZE_BYTES / 2; j++) { + for (int s =3D 0; s < 2; s++) { + int c =3D (2 * j + s) % NUM_CVT_F8_HF_CASES; + + ((MMVector *)&buffers[s])->hf[j] =3D cvt_f8_hf_cases[c].hf; + expect[0].ub[4 * (j / 2) + 2 * (j % 2) + s] =3D + sat ? cvt_f8_hf_cases[c].f8_sat : cvt_f8_hf_cases[c].f8; + } + } + set_fpsat(sat); + *hvx_output =3D Q6_V_vcvt_VhfVhf(vbuffers[0], vbuffers[1]); + set_fpsat(false); + check_output_ub(__LINE__, 1); + + /* Every half precision value, 64 at a time, in alternating sources */ + for (int blk =3D 0; blk < 1024; blk++) { + for (int j =3D 0; j < MAX_VEC_SIZE_BYTES / 2; j++) { + for (int s =3D 0; s < 2; s++) { + /* A different value in each source, covering all of them = */ + uint16_t h =3D (blk * 64 + j) * (s ? 40503 : 1) + (s ? 123= 45 : 0); + + ((MMVector *)&buffers[s])->hf[j] =3D h; + } + } + set_fpsat(sat); + *hvx_output =3D Q6_V_vcvt_VhfVhf(vbuffers[0], vbuffers[1]); + set_fpsat(false); + hash_bytes(&hash, hvx_output, sizeof(*hvx_output)); + } + check_hash(__LINE__, hash, + sat ? 0x711e375027f85c31ULL : 0xc90f8f22ad443a9dULL); +} + int main(void) { test_vcvt2_hf_ub(); @@ -105,6 +461,18 @@ int main(void) test_vcvt2_ub_hf(); test_vcvt2_b_hf(); =20 + test_vcvt_hf_f8(); + test_vcvt_f8_hf(false); + test_vcvt_f8_hf(true); + test_vadd_hf_f8(); + test_vsub_hf_f8(); + test_vmpy_hf_f8(); + test_vmpy_hf_f8_acc(); + test_vfneg_f8(); + test_vabs_f8(); + test_vfmin_f8(); + test_vfmax_f8(); + puts(err ? "FAIL" : "PASS"); return err ? 1 : 0; } diff --git a/target/hexagon/tag_rev_info.c.inc b/target/hexagon/tag_rev_inf= o.c.inc index 4ab135d33f3..1c4917e6fa7 100644 --- a/target/hexagon/tag_rev_info.c.inc +++ b/target/hexagon/tag_rev_info.c.inc @@ -663,6 +663,7 @@ static const struct tag_rev_info tag_rev_info[XX_LAST_O= PCODE] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VER_NONE }, [V6_set_qfext] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VER= _NONE }, + [V6_vabs_f8] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VER_N= ONE }, [V6_vabs_qf16_hf] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_= VER_NONE }, [V6_vabs_qf16_qf16] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VER_NONE @@ -671,6 +672,7 @@ static const struct tag_rev_info tag_rev_info[XX_LAST_O= PCODE] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VER_NONE }, [V6_vabs_qf32_sf] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_= VER_NONE }, + [V6_vadd_hf_f8] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VE= R_NONE }, [V6_vconv_bf_qf32] =3D { .introduced =3D HEX_VER_V81, .removed =3D HEX= _VER_NONE }, [V6_vconv_qf16_hf] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX= _VER_NONE }, [V6_vconv_qf16_qf16] =3D { @@ -684,11 +686,20 @@ static const struct tag_rev_info tag_rev_info[XX_LAST= _OPCODE] =3D { [V6_vcvt2_hf_b] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VE= R_NONE }, [V6_vcvt2_hf_ub] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_V= ER_NONE }, [V6_vcvt2_ub_hf] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_V= ER_NONE }, + [V6_vcvt_f8_hf] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VE= R_NONE }, + [V6_vcvt_hf_f8] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VE= R_NONE }, + [V6_vfmax_f8] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VER_= NONE }, + [V6_vfmin_f8] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VER_= NONE }, + [V6_vfneg_f8] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VER_= NONE }, [V6_vilog2_hf] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VER= _NONE }, [V6_vilog2_qf16] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_V= ER_NONE }, [V6_vilog2_qf32] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_V= ER_NONE }, [V6_vilog2_sf] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VER= _NONE }, [V6_vmerge_qf] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VER= _NONE }, + [V6_vmpy_hf_f8] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VE= R_NONE }, + [V6_vmpy_hf_f8_acc] =3D { + .introduced =3D HEX_VER_V79, .removed =3D HEX_VER_NONE + }, [V6_vmpy_rt_hf] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VE= R_NONE }, [V6_vmpy_rt_qf16] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_= VER_NONE }, [V6_vmpy_rt_sf] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VE= R_NONE }, @@ -700,6 +711,7 @@ static const struct tag_rev_info tag_rev_info[XX_LAST_O= PCODE] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VER_NONE }, [V6_vneg_qf32_sf] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_= VER_NONE }, + [V6_vsub_hf_f8] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VE= R_NONE }, [V6_vsub_hf_mix] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_V= ER_NONE }, [V6_vsub_sf_mix] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_V= ER_NONE }, }; diff --git a/target/hexagon/imported/mmvec/encode_ext.def b/target/hexagon/= imported/mmvec/encode_ext.def index 9605e870a1e..5941e09df93 100644 --- a/target/hexagon/imported/mmvec/encode_ext.def +++ b/target/hexagon/imported/mmvec/encode_ext.def @@ -882,6 +882,18 @@ DEF_ENC(V6_veqhf_or,"00011100100vvvvvPP1uuuuu010111xx") DEF_ENC(V6_veqsf_xor,"00011100100vvvvvPP1uuuuu100011xx") DEF_ENC(V6_veqhf_xor,"00011100100vvvvvPP1uuuuu100111xx") =20 +/* FP8 instructions */ +DEF_ENC(V6_vadd_hf_f8,"00011111100vvvvvPP0uuuuu100ddddd") +DEF_ENC(V6_vsub_hf_f8,"00011111100vvvvvPP0uuuuu101ddddd") +DEF_ENC(V6_vmpy_hf_f8,"00011111100vvvvvPP0uuuuu110ddddd") +DEF_ENC(V6_vmpy_hf_f8_acc,"00011111100vvvvvPP0uuuuu111xxxxx") +DEF_ENC(V6_vfmin_f8,"00011100011vvvvvPP1uuuuu100ddddd") +DEF_ENC(V6_vfmax_f8,"00011100011vvvvvPP1uuuuu101ddddd") +DEF_ENC(V6_vabs_f8,"00011100011--110PP1uuuuu110ddddd") +DEF_ENC(V6_vfneg_f8,"00011100011--110PP1uuuuu111ddddd") +DEF_ENC(V6_vcvt_f8_hf,"00011111111vvvvvPP1uuuuu010ddddd") +DEF_ENC(V6_vcvt_hf_f8,"00011110--0--101PP1uuuuu101ddddd") + /* BFLOAT instructions */ DEF_ENC(V6_vmpy_sf_bf,"00011101010vvvvvPP1uuuuu100ddddd") DEF_ENC(V6_vmpy_sf_bf_acc,"00011101000vvvvvPP1uuuuu000xxxxx") diff --git a/target/hexagon/imported/mmvec/ext.idef b/target/hexagon/import= ed/mmvec/ext.idef index b9a4858d0c1..1b8afee8b6f 100644 --- a/target/hexagon/imported/mmvec/ext.idef +++ b/target/hexagon/imported/mmvec/ext.idef @@ -2920,6 +2920,12 @@ EXTINSN(V6_##TAG, SYNTAX, \ ATTRIBS(A_EXTENSION,A_HVX_IEEE_FP,A_CVI,A_CVI_VX,A_HVX_IEEE_FP_OUT_32), \ DESCR, DO_FOR_EACH_CODE(WIDTH, CODE)) =20 +/* Single pipe, 8-bit output */ +#define ITERATOR_INSN_IEEE_FP_8(WIDTH,TAG,SYNTAX,DESCR,CODE) \ +EXTINSN(V6_##TAG, SYNTAX, \ + ATTRIBS(A_EXTENSION,A_HVX_IEEE_FP,A_CVI,A_CVI_VX,A_HVX_IEEE_FP_OUT_8),= \ + DESCR, DO_FOR_EACH_CODE(WIDTH, CODE)) + /* Single pipe, 16-bit output */ #define ITERATOR_INSN_IEEE_FP_16(WIDTH,TAG,SYNTAX,DESCR,CODE) \ EXTINSN(V6_##TAG, SYNTAX, \ @@ -3373,6 +3379,78 @@ ITERATOR_INSN_IEEE_FP_16_32_LATE(16, vmin_bf, "Vd32.= bf=3Dvmin(Vu32.bf,Vv32.bf)", fBFLOAT()) =20 =20 +/*************************************************************************= ***** + FP8 instructions + *************************************************************************= *****/ + +/* + * The widening FP8 instructions split the source elements between the two + * result vectors by position: the even-numbered bytes of each word go to = the + * first vector and the odd-numbered ones to the second. The narrowing + * conversion, vcvt_f8_hf, takes its elements alternately from its two sou= rces. + */ +ITERATOR_INSN_IEEE_FP_DOUBLE_16(32, vadd_hf_f8, "Vdd32.hf=3Dvadd(Vu32.f8,V= v32.f8)", + "Vector FP8 add: f8 widen to hf", + VddV.v[0].hf[2*i] =3D fp_add_hf_f8(VuV.f8[4*i], VvV.f8[4*i], &env->h= vx_fp_status); + VddV.v[0].hf[2*i+1] =3D fp_add_hf_f8(VuV.f8[4*i+2], VvV.f8[4*i+2], &en= v->hvx_fp_status); + VddV.v[1].hf[2*i] =3D fp_add_hf_f8(VuV.f8[4*i+1], VvV.f8[4*i+1], &en= v->hvx_fp_status); + VddV.v[1].hf[2*i+1] =3D fp_add_hf_f8(VuV.f8[4*i+3], VvV.f8[4*i+3], &en= v->hvx_fp_status)) + +ITERATOR_INSN_IEEE_FP_DOUBLE_16(32, vsub_hf_f8, "Vdd32.hf=3Dvsub(Vu32.f8,V= v32.f8)", + "Vector FP8 sub: f8 widen to hf", + VddV.v[0].hf[2*i] =3D fp_sub_hf_f8(VuV.f8[4*i], VvV.f8[4*i], &env->h= vx_fp_status); + VddV.v[0].hf[2*i+1] =3D fp_sub_hf_f8(VuV.f8[4*i+2], VvV.f8[4*i+2], &en= v->hvx_fp_status); + VddV.v[1].hf[2*i] =3D fp_sub_hf_f8(VuV.f8[4*i+1], VvV.f8[4*i+1], &en= v->hvx_fp_status); + VddV.v[1].hf[2*i+1] =3D fp_sub_hf_f8(VuV.f8[4*i+3], VvV.f8[4*i+3], &en= v->hvx_fp_status)) + +ITERATOR_INSN_IEEE_FP_DOUBLE_16(32, vmpy_hf_f8, "Vdd32.hf=3Dvmpy(Vu32.f8,V= v32.f8)", + "Vector FP8 mul: f8 widen to hf", + VddV.v[0].hf[2*i] =3D fp_mult_hf_f8(VuV.f8[4*i], VvV.f8[4*i], &env->= hvx_fp_status); + VddV.v[0].hf[2*i+1] =3D fp_mult_hf_f8(VuV.f8[4*i+2], VvV.f8[4*i+2], &e= nv->hvx_fp_status); + VddV.v[1].hf[2*i] =3D fp_mult_hf_f8(VuV.f8[4*i+1], VvV.f8[4*i+1], &e= nv->hvx_fp_status); + VddV.v[1].hf[2*i+1] =3D fp_mult_hf_f8(VuV.f8[4*i+3], VvV.f8[4*i+3], &e= nv->hvx_fp_status)) + +ITERATOR_INSN_IEEE_FP_DOUBLE_16(32, vmpy_hf_f8_acc, "Vxx32.hf+=3Dvmpy(Vu32= .f8,Vv32.f8)", + "Vector FP8 fma: f8 widen to hf", + VxxV.v[0].hf[2*i] =3D fp_mult_hf_f8_acc(VuV.f8[4*i], VvV.f8[4*i], + VxxV.v[0].hf[2*i], &env->hvx_f= p_status); + VxxV.v[0].hf[2*i+1] =3D fp_mult_hf_f8_acc(VuV.f8[4*i+2], VvV.f8[4*i+2], + VxxV.v[0].hf[2*i+1], &env->hvx= _fp_status); + VxxV.v[1].hf[2*i] =3D fp_mult_hf_f8_acc(VuV.f8[4*i+1], VvV.f8[4*i+1], + VxxV.v[1].hf[2*i], &env->hvx_f= p_status); + VxxV.v[1].hf[2*i+1] =3D fp_mult_hf_f8_acc(VuV.f8[4*i+3], VvV.f8[4*i+3], + VxxV.v[1].hf[2*i+1], &env->hvx= _fp_status)) + +ITERATOR_INSN_IEEE_FP_DOUBLE_16(32, vcvt_hf_f8, "Vdd32.hf=3Dvcvt(Vu32.f8)", + "Vector cvt to fp16: f8 widen to hf", + VddV.v[0].hf[2*i] =3D f8_to_f16(VuV.f8[4*i], &env->hvx_fp_status); + VddV.v[0].hf[2*i+1] =3D f8_to_f16(VuV.f8[4*i+2], &env->hvx_fp_status); + VddV.v[1].hf[2*i] =3D f8_to_f16(VuV.f8[4*i+1], &env->hvx_fp_status); + VddV.v[1].hf[2*i+1] =3D f8_to_f16(VuV.f8[4*i+3], &env->hvx_fp_status)) + +/* + * With USR.FPSAT set, overflow saturates to the largest FP8 normal number + * instead of producing NaN. + */ +ITERATOR_INSN_IEEE_FP_8(32, vcvt_f8_hf, "Vd32.f8=3Dvcvt(Vu32.hf,Vv32.hf)", + "Vector cvt to fp8: hf narrow to f8", + VdV.f8[4*i] =3D f16_to_f8(VuV.hf[2*i], GET_USR_FIELD(USR_FPSAT), &en= v->hvx_fp_status); + VdV.f8[4*i+1] =3D f16_to_f8(VvV.hf[2*i], GET_USR_FIELD(USR_FPSAT), &en= v->hvx_fp_status); + VdV.f8[4*i+2] =3D f16_to_f8(VuV.hf[2*i+1], GET_USR_FIELD(USR_FPSAT), &= env->hvx_fp_status); + VdV.f8[4*i+3] =3D f16_to_f8(VvV.hf[2*i+1], GET_USR_FIELD(USR_FPSAT), &= env->hvx_fp_status)) + +ITERATOR_INSN_IEEE_FP_8(8, vfneg_f8, "Vd32.f8=3Dvfneg(Vu32.f8)", + "Vector FP8 neg: f8", VdV.f8[i] =3D fp_neg_f8(VuV.f8[i])) +ITERATOR_INSN_IEEE_FP_8(8, vabs_f8, "Vd32.f8=3Dvabs(Vu32.f8)", + "Vector FP8 abs: f8", VdV.f8[i] =3D fp_abs_f8(VuV.f8[i])) +ITERATOR_INSN_IEEE_FP_8(8, vfmin_f8, "Vd32.f8=3Dvfmin(Vu32.f8,Vv32.f8)", + "Vector FP8 min: f8", + VdV.f8[i] =3D fp_min_f8(VuV.f8[i], VvV.f8[i], &env->hvx_fp_status)) +ITERATOR_INSN_IEEE_FP_8(8, vfmax_f8, "Vd32.f8=3Dvfmax(Vu32.f8,Vv32.f8)", + "Vector FP8 max: f8", + VdV.f8[i] =3D fp_max_f8(VuV.f8[i], VvV.f8[i], &env->hvx_fp_status)) + + /*************************************************************************= ***** QFloat extended-precision instructions *************************************************************************= *****/ --=20 2.34.1 From nobody Mon Nov 23 04:34:21 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1792865347; cv=none; d=zohomail.com; s=zohoarc; b=E+Or5tYdAV01TT7ea6c6pFFRuIC44jIBVU+tRy+Q1h6hDSsvDZy4ZECHdV7WPbiYnaYjMfkzn8c/opbE84rY6Kkrb/RO74feRSfLpm/M/UawnNpTdwfQ+ynAbNZrTZZePQT4whlfwk32ggeSsV7L1c2O+w4fBpfzfzer0JrCdH0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792865347; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=EAnhEL0TAGnib616GGc4X5rZDkOGJ1lv7ov9ctuhUG8=; b=Y9f7GkuOG3tczCvD9yO6CZHmspu7gzPuUetVwvTX3ToPwz01xU4A6UQOXCiUE3Wx3pCqEAWcVdRuHcyfkqKAelkcAOj+kV4WbcaCQQ9SBt8/sUW+dgVRDJ5Ly8LZVfb0ZjHtUigsOWVhm01iz4Nlbq4H/hRa0pnDQJenDbRKLEk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792865347900869.8056506023207; Sat, 24 Oct 2026 11:09:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xKgAW-0006IE-4r; Sat, 24 Oct 2026 14:08:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xKgAR-00069p-DG for qemu-devel@nongnu.org; Sat, 24 Oct 2026 14:08:31 -0400 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xKgAM-0002KK-BF for qemu-devel@nongnu.org; Sat, 24 Oct 2026 14:08:29 -0400 Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 69OExr6e1353439 for ; Sat, 24 Oct 2026 18:08:24 GMT Received: from mail-dy1-f200.google.com (mail-dy1-f200.google.com [74.125.82.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hgnehhdy9-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Sat, 24 Oct 2026 18:08:24 +0000 (GMT) Received: by mail-dy1-f200.google.com with SMTP id 5a478bee46e88-36998507c13so545914eec.0 for ; Sat, 24 Oct 2026 11:08:24 -0700 (PDT) Received: from hu-bcain-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-369f27d5bf8sm3966963eec.4.2026.10.24.11.08.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Oct 2026 11:08:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= EAnhEL0TAGnib616GGc4X5rZDkOGJ1lv7ov9ctuhUG8=; b=QlzrlPeK7u230xPF TDV210yV4nHY1nCyqS9FQ6NvXoGfU3qPKKZGBlMWw0nQD7keNDc11BXXs6uupunt /P12fXEjKBQ/9KLPpVLGMA18DVR2L3X2l/4a/7RnJfk83YkuMJaevwbRPHTUDwiA 8OpUqaxBNLPqKxKNtuTaSiA8h2AwMo4347L/ZR7BtYl3gRIsu5e+CKBZDJJjqfPr pTYBITbsD+uncihEvoA3XP0XoEv90udYMGWYrJlS1swBGiCXkKyxQEHo5/TJBEkF aNG93nmzoUl4prmsI5dHvEor7NsIz3SoIW48/8KtrNJd2UUrCKMWZit8r49wimdX 0KPLng== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1792865303; x=1793470103; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=EAnhEL0TAGnib616GGc4X5rZDkOGJ1lv7ov9ctuhUG8=; b=WudNDHhZBdavunJC6HGiWNvSmRrm0E/+i+xeXdxsVACsqalKYzvU6DzWqVrVOD3Q/6 H0uuRNLX/YuCuvEt7XozPxRc4CO8DoV8hDTELcMfYz29kcNqXPMOVEICbtWi5QLzwzDC D0j9WQpm7d0fk17oq5iUY2U6ZYjrYepGrrAHWWDj6KiDCM5o05AiDRMuyPzctWkO8U3r qYVe4myjlX9ylmrgL+ZFIAh9ZeSnDhVLEnul6Bm+yAsgWX0p83I37001svl2FiTJ9Xx6 bIPFlWewtmJowQRCBoBGXbtDhbMT7VO4C3o9Sd5Gnte+P6zrE0rfDFbfLqxIJTYAd/VR ZctA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792865303; x=1793470103; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=EAnhEL0TAGnib616GGc4X5rZDkOGJ1lv7ov9ctuhUG8=; b=GQgvg8OcYAXzl6N3Yuu87SF+udpeN+GueiygHFGcb5BVVAhyRU770TUDrcCrqGUqSZ RarPC9y+FDMDIFyRQeKyKhG3LbSDYhgJ8+2CBNdUyBKpAhSzX3vNWK4QZqVbuElAKvkB f5Baoff936NYBSYCsa7LZMW+n0bPxFwB4E5R23AD0hNO27RihlBAyOXMpr/zN7QziU9q 2//rzP11XBk9V2X1nCxHCAEaDI7bpZywVoirAod7ElxoNdklQ8ms5NyAevJdXnxs31oj Gtfd5bALRG4P++MNt5QJPHScHtYklQjL/jkggTnE2iUyNKVDEJnxM7djwb2DXhLutPWd 36iw== X-Gm-Message-State: AFq9FYINjsWutMVoM3YjYoiODTK5BIpQKgpQ0cVMB4qy9mwade0QWMuO LuMdZc9A+Jlfo2RPSFA6HYa4TxTkXKDdjyVZeJ9o3SWrRig1ISlLYeWR9A2dovxMzyRJJyqlGKp rVn0cj1OULDsXOLqd+z2V6NRPwC6u62rJBHvxVD3dYqS1uwv6+2Gf/eNfCEK9Hzq6tw== X-Gm-Gg: AYBFou3dTvBD6nYe1HTb6S5oLKQ3cQL8dTGQYTwKqPMQKdatoR9iwswsC5H/UQ6cTyZ 4SCk/IqyDDoPV4Hv2LNWnsI7MEgJTzNO2DF0nzDU0cME9UUYkKCTjOpMqg8iruj3KNnrg1PUlOd fZ2eYsPn90QZ6Z6beTlsdFy+Iqq8rauOjr6vJBsBgHSrn/j4lZascxPfx8ZwImx77spUNTyJpJm LcMjR4Rqy6m0hhTPYOTGMCwqy+xk7I0Z7u0iqtP75cuYuRftFud3BI20dwfjnZKB/RR2IYxy3fl PlsaGfUlDwDZuj2MyK8w+I+JQkgXcY34KXK50cW3YCTDGPAyKu8aw7sM6v2DsU/swywe0bBt8XT 3ValFVPJ5yqFdsJDJDfEI9u6I2scibb4H0m1gnJsJn7s7/cMt X-Received: by 2002:a05:7300:50f0:b0:369:ef63:ea90 with SMTP id 5a478bee46e88-369ef63f3abmr1923083eec.28.1792865303241; Sat, 24 Oct 2026 11:08:23 -0700 (PDT) X-Received: by 2002:a05:7300:50f0:b0:369:ef63:ea90 with SMTP id 5a478bee46e88-369ef63f3abmr1923051eec.28.1792865302553; Sat, 24 Oct 2026 11:08:22 -0700 (PDT) From: Brian Cain To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Brian Cain , Marco Liebel Subject: [PATCH v2 3/3] target/hexagon: add v81 HVX FP8 and qf16 conversions Date: Sat, 24 Oct 2026 11:08:17 -0700 Message-Id: <20261024180817.2037169-4-brian.cain@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261024180817.2037169-1-brian.cain@oss.qualcomm.com> References: <20261024180817.2037169-1-brian.cain@oss.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Info: AW1haW4tMjYxMDI0MDA3MiBTYWx0ZWRfXwc5nobN9SDN3 v8c2I0KPAtJoisRGMyQp/hj2JDMsCabgZZqV6wqyQkikPoJ4m1fO90KuppKYZAehg42MiE3VAcp Ms4niXBY6/JNbXSJ+BG/jSPKMYdImPQ= X-Proofpoint-ORIG-GUID: DRO9vQ47Ubmv2lxLiDP7vHHYYmi_iHk0 X-Authority-Analysis: v=2.4 cv=d5tgWhjE c=1 sm=1 tr=0 ts=6adcf418 cx=c_pps a=PfFC4Oe2JQzmKTvty2cRDw==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=IkcTkHD0fZMA:10 a=660iZSQnnn4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=_K5XuSEh1TEqbUxoQ0s3:22 a=EUspDBNiAAAA:8 a=j8yUcP_KkYIJtjHBztQA:9 a=QEXdDO2ut3YA:10 a=6Ab_bkdmUrQuMsNx7PHu:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMDI0MDA3MiBTYWx0ZWRfXxqbmQ/h8C/CB XdZrQOOAVtCh3Z8SCQRvJrQ5aL8UOsrZxMN/M0cHusUF311uou+16GmOQmbM/ZtmUtFajTShUyj V2GiNjNoIAHLXqZ9sTFY9WIEBR5zLZ4pPAc85Ip5Nr30EXokbnHIgL2B83ZlmrPQkAn6BFwd9gH hjSzaptAmVn2umnszmvgBYuYh7bjBbq1lsyKOGXCs270FwWQT8efHbnTVtAVX4wW3MBz2Ksiu97 NwvBQL6s48e5pa0p3FvhahcwWXnIgcAbl045SkN0BzAangA9FnxL3/JjZ1E+HP4lRiDr6ERqp9B MelRHCEo1Gj+bcnSEv087m9Prq0qvp22Htfn4dn6AzxTmt6QQt4Dgh2cHZtx2QXJCCOW6/kdRMJ u+bMwaAC4PmKYK+vqXPgLUDtxVDpWDbDl+GQyiHviMR0ZVbN5fjcA6Pzh+PXHilnzZ6FRvaOoPg 8M4BxVA9YKATdiAY8+w== X-Proofpoint-GUID: DRO9vQ47Ubmv2lxLiDP7vHHYYmi_iHk0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-10-24_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 phishscore=0 clxscore=1015 adultscore=0 malwarescore=0 suspectscore=0 lowpriorityscore=0 spamscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610240072 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=brian.cain@oss.qualcomm.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1792865349823158500 Add V6_vconv_qf16_f8 and V6_vconv_f8_qf16, which use FP8 with exponent bias 7. Signed-off-by: Brian Cain --- target/hexagon/mmvec/hvx_ieee_fp.h | 8 ++ target/hexagon/mmvec/macros.h | 20 +++ target/hexagon/mmvec/hvx_ieee_fp.c | 28 +++++ tests/tcg/hexagon/check_rev_gating.c | 6 + tests/tcg/hexagon/qfloat_v81.c | 121 +++++++++++++++++++ target/hexagon/tag_rev_info.c.inc | 2 + target/hexagon/imported/mmvec/encode_ext.def | 2 + target/hexagon/imported/mmvec/ext.idef | 6 + 8 files changed, 193 insertions(+) diff --git a/target/hexagon/mmvec/hvx_ieee_fp.h b/target/hexagon/mmvec/hvx_= ieee_fp.h index 229ee0ee516..996feae67b3 100644 --- a/target/hexagon/mmvec/hvx_ieee_fp.h +++ b/target/hexagon/mmvec/hvx_ieee_fp.h @@ -52,6 +52,14 @@ float16 f8_to_f16(uint8_t a, float_status *fp_status); */ uint8_t f16_to_f8(float16 a, bool sat, float_status *fp_status); =20 +/* + * The v81 conversions between FP8 and qf16 read the same encoding with + * exponent bias 7 instead of 8, so every value is twice as large. + * NaN is still 0x80 and narrowing never saturates. + */ +float16 f8_bias7_to_f16(uint8_t a, float_status *fp_status); +uint8_t f16_to_f8_bias7(float16 a, float_status *fp_status); + float16 fp_add_hf_f8(uint8_t a1, uint8_t a2, float_status *fp_status); float16 fp_sub_hf_f8(uint8_t a1, uint8_t a2, float_status *fp_status); float16 fp_mult_hf_f8(uint8_t a1, uint8_t a2, float_status *fp_status); diff --git a/target/hexagon/mmvec/macros.h b/target/hexagon/mmvec/macros.h index 0e643b29109..8ac685bdc57 100644 --- a/target/hexagon/mmvec/macros.h +++ b/target/hexagon/mmvec/macros.h @@ -417,6 +417,26 @@ =20 #define fQF_VILOG2(TYPE, A, AEXT) qf_vilog2(TYPE, A, AEXT) =20 +/* + * Convert an FP8 element to the qf16 element (V).qf16[i]. FP8 is exactly + * representable in hf, so go through that. The one FP8 NaN becomes the + * negative qf16 NaN. + */ +#define fCONVERT_F8_TO_QF16(V, A) \ + do { \ + if ((A) =3D=3D F8_NAN) { \ + (V).qf16[i] =3D extqf16_neg_nan >> 4; \ + set_extended_bits(&(V), i, 16, \ + extqf16_neg_nan & EXT16_BITMASK); \ + } else { \ + unfloat u =3D fPARSEHF(f8_bias7_to_f16(A, &env->hvx_fp_status)= ); \ + INIT_UNFLOAT(v) \ + v.exp =3D E_MIN_EXTQF16; \ + v.sign =3D 1; \ + fQFADD(16, V, u, v); \ + } \ + } while (0) + #define fCONVERT_QF32_TO_SF(A, AEXT) \ (qfloat_is_extended(env) ? \ conv_sf_extqf32(A, AEXT, CVI_QFRND_MODE) : legacy_conv_sf_qf32(A)) diff --git a/target/hexagon/mmvec/hvx_ieee_fp.c b/target/hexagon/mmvec/hvx_= ieee_fp.c index 038725dce57..a04d3af7b20 100644 --- a/target/hexagon/mmvec/hvx_ieee_fp.c +++ b/target/hexagon/mmvec/hvx_ieee_fp.c @@ -228,6 +228,34 @@ uint8_t f16_to_f8(float16 a, bool sat, float_status *f= p_status) return code ? sign | code : 0; } =20 +float16 f8_bias7_to_f16(uint8_t a, float_status *fp_status) +{ + float_status exact =3D { 0 }; + + /* + * Multiply by 2.0 (0x4000), which is exact. Leave NaN alone so that + * it keeps the default NaN of fp_status, not that of the scratch stat= us. + */ + return a =3D=3D F8_NAN ? f8_to_f16(a, fp_status) : + float16_mul(f8_to_f16(a, fp_status), make_float16(0x4000), &exa= ct); +} + +uint8_t f16_to_f8_bias7(float16 a, float_status *fp_status) +{ + float_status halve =3D { 0 }; + + if (float16_is_any_nan(a)) { + return F8_NAN; + } + /* + * Multiply by 0.5 (0x3800). Halving only loses a bit for tiny values + * (below 2^-13), far under half the smallest FP8 value (2^-10), where + * the result rounds to zero either way. + */ + return f16_to_f8(float16_mul(a, make_float16(0x3800), &halve), false, + fp_status); +} + float16 fp_add_hf_f8(uint8_t a1, uint8_t a2, float_status *fp_status) { return float16_add(f8_to_f16(a1, fp_status), f8_to_f16(a2, fp_status), diff --git a/tests/tcg/hexagon/check_rev_gating.c b/tests/tcg/hexagon/check= _rev_gating.c index a0b9474492e..63c4a125a5d 100644 --- a/tests/tcg/hexagon/check_rev_gating.c +++ b/tests/tcg/hexagon/check_rev_gating.c @@ -143,6 +143,10 @@ TRY_FUNC(v79hvx_vfmin_f8, =20 TRY_FUNC(v81hvx_veqhf, ".word 0x1f82c11c /* q0 =3D vcmp.eq(v1.hf, v2.hf) */\n") +TRY_FUNC(v81hvx_vconv_qf16_f8, + ".word 0x1e0ce2a0 /* v1:0.qf16 =3D v2.f8 */\n") +TRY_FUNC(v81hvx_vconv_f8_qf16, + ".word 0x1e0ce4e3 /* v3.f8 =3D v4.qf16 */\n") =20 int main(void) { @@ -193,6 +197,8 @@ int main(void) assert(try_v79hvx_vfmin_f8() =3D=3D SIGILL); =20 assert(try_v81hvx_veqhf() =3D=3D SIGILL); + assert(try_v81hvx_vconv_qf16_f8() =3D=3D SIGILL); + assert(try_v81hvx_vconv_f8_qf16() =3D=3D SIGILL); =20 assert(signals_handled =3D=3D expected_signals); =20 diff --git a/tests/tcg/hexagon/qfloat_v81.c b/tests/tcg/hexagon/qfloat_v81.c index 4fdd4809071..c0598c057ff 100644 --- a/tests/tcg/hexagon/qfloat_v81.c +++ b/tests/tcg/hexagon/qfloat_v81.c @@ -108,11 +108,132 @@ static void test_qf32_bf_conversion(void) check_output_h(__LINE__, 1); } =20 +/* + * The conversions between FP8 and qf16 read the FP8 encoding with exponent + * bias 7, unlike the v79 vcvt instructions which use bias 8. Zero is 0 a= nd + * 0x80 is the only NaN. + */ +#define F8_NAN 0x80 +#define QF16_NAN 0x801f + +/* The qf16 encoding of an FP8 value: 11-bit significand, 5-bit exponent */ +static void f8_to_qf16_parts(uint8_t f8, int *sig11, int *exp) +{ + int e =3D (f8 >> 3) & 0xf; + int sig =3D e ? 8 | (f8 & 7) : f8 & 7; + int p =3D 31 - __builtin_clz(sig); + + /* The value is sig * 2^(e - 7 - 3), with the smallest e shared */ + *exp =3D p + (e ? e : 1) - 10; + *sig11 =3D sig << (9 - p); +} + +static uint16_t ref_f8_to_qf16(uint8_t f8) +{ + int sig11, exp; + + if (f8 =3D=3D 0) { + return 0; + } + if (f8 =3D=3D F8_NAN) { + return QF16_NAN; + } + f8_to_qf16_parts(f8, &sig11, &exp); + /* Negative numbers hold the complement of the significand */ + if (f8 & 0x80) { + sig11 =3D ~sig11 & 0x7ff; + } + return sig11 << 5 | (exp + 15); +} + +#define WIDEN_VEC(I) ((I) % 2) +#define WIDEN_IDX(I) (2 * ((I) / 4) + (((I) % 4) / 2)) + +static void test_vconv_qf16_f8(void) +{ + for (int blk =3D 0; blk < 2; blk++) { + MMVector input; + + for (int i =3D 0; i < MAX_VEC_SIZE_BYTES; i++) { + input.ub[i] =3D blk * MAX_VEC_SIZE_BYTES + i; + expect[WIDEN_VEC(i)].uh[WIDEN_IDX(i)] =3D ref_f8_to_qf16(input= .ub[i]); + } + asm volatile( + "v2 =3D vmemu(%[in])\n" + "v1:0.qf16 =3D v2.f8\n" + "vmemu(%[out0]) =3D v0\n" + "vmemu(%[out1]) =3D v1\n" + : + : [in] "r"(&input), [out0] "r"(&output[0]), + [out1] "r"(&output[1]) + : "v0", "v1", "v2", "memory"); + check_output_uh(__LINE__, 2); + } +} + +/* Round a half precision value to FP8, to nearest even, with no saturatio= n */ +static uint8_t ref_hf_to_f8(uint16_t hf) +{ + _Float16 h; + double x, ax; + int sign =3D hf >> 15; + int code; + + memcpy(&h, &hf, sizeof(h)); + x =3D h; + if (x !=3D x || __builtin_isinf(x)) { + return F8_NAN; + } + ax =3D __builtin_fabs(x); + if (ax < 1.0 / 64) { + /* Subnormal, in units of 2^-9 */ + code =3D __builtin_rint(ax * 512); + } else { + int e =3D __builtin_ilogb(ax); + int m =3D __builtin_rint(__builtin_scalbn(ax, 3 - e)); + + code =3D (e + 7) * 8 + m - 8; + } + if (code > 0x7f) { + return F8_NAN; + } + /* There's no negative zero */ + return code ? sign << 7 | code : 0; +} + +/* + * Add zero to get a qf16 from every half precision value, which for a + * non-NaN input stays exactly that value. + */ +static void test_vconv_f8_qf16(void) +{ + for (int base =3D 0; base < 0x10000; base +=3D MAX_VEC_SIZE_BYTES / 2)= { + MMVector input; + + for (int i =3D 0; i < MAX_VEC_SIZE_BYTES / 2; i++) { + input.uh[i] =3D base + i; + expect[0].uh[i] =3D ref_hf_to_f8(base + i); + } + asm volatile( + "v2 =3D vmemu(%[in])\n" + "v3 =3D vxor(v3, v3)\n" + "v0.qf16 =3D vadd(v2.hf, v3.hf)\n" + "v1.f8 =3D v0.qf16\n" + "vmemu(%[out]) =3D v1\n" + : + : [in] "r"(&input), [out] "r"(&output[0]) + : "v0", "v1", "v2", "v3", "memory"); + check_output_uh(__LINE__, 1); + } +} + int main() { test_qf16(); test_qf32(); test_qf32_bf_conversion(); + test_vconv_qf16_f8(); + test_vconv_f8_qf16(); =20 puts(err ? "FAIL" : "PASS"); return err ? 1 : 0; diff --git a/target/hexagon/tag_rev_info.c.inc b/target/hexagon/tag_rev_inf= o.c.inc index 1c4917e6fa7..244997c625a 100644 --- a/target/hexagon/tag_rev_info.c.inc +++ b/target/hexagon/tag_rev_info.c.inc @@ -657,6 +657,8 @@ static const struct tag_rev_info tag_rev_info[XX_LAST_O= PCODE] =3D { [V6_vconv_h_hf_rnd] =3D { .introduced =3D HEX_VER_V81, .removed =3D HEX_VER_NONE }, + [V6_vconv_f8_qf16] =3D { .introduced =3D HEX_VER_V81, .removed =3D HEX= _VER_NONE }, + [V6_vconv_qf16_f8] =3D { .introduced =3D HEX_VER_V81, .removed =3D HEX= _VER_NONE }, =20 [V6_get_qfext] =3D { .introduced =3D HEX_VER_V79, .removed =3D HEX_VER= _NONE }, [V6_get_qfext_oracc] =3D { diff --git a/target/hexagon/imported/mmvec/encode_ext.def b/target/hexagon/= imported/mmvec/encode_ext.def index 5941e09df93..7139be12e59 100644 --- a/target/hexagon/imported/mmvec/encode_ext.def +++ b/target/hexagon/imported/mmvec/encode_ext.def @@ -928,7 +928,9 @@ DEF_ENC(V6_vconv_bf_qf32,"00011110--0-0110PP1uuuuu111dd= ddd") DEF_ENC(V6_vconv_hf_qf16,"00011110--0-0100PP1uuuuu011ddddd") DEF_ENC(V6_vconv_hf_qf32,"00011110--0-0100PP1uuuuu110ddddd") DEF_ENC(V6_vconv_qf16_hf,"00011110--0-1100PP1uuuuu100ddddd") +DEF_ENC(V6_vconv_qf16_f8,"00011110--0-1100PP1uuuuu101ddddd") DEF_ENC(V6_vconv_qf16_qf16,"00011110--0-1100PP1uuuuu110ddddd") +DEF_ENC(V6_vconv_f8_qf16,"00011110--0-1100PP1uuuuu111ddddd") DEF_ENC(V6_vconv_qf32_qf32,"00011110--0-1101PP1uuuuu111ddddd") DEF_ENC(V6_vconv_qf32_sf,"00011110--0-1101PP1uuuuu110ddddd") DEF_ENC(V6_vconv_sf_qf32,"00011110--0-0100PP1uuuuu000ddddd") diff --git a/target/hexagon/imported/mmvec/ext.idef b/target/hexagon/import= ed/mmvec/ext.idef index 1b8afee8b6f..aa74f4f423a 100644 --- a/target/hexagon/imported/mmvec/ext.idef +++ b/target/hexagon/imported/mmvec/ext.idef @@ -3519,6 +3519,12 @@ EXTINSN(V6_vconv_hf_qf32,"Vd32.hf=3DVuu32.qf32",ATTR= IBS(A_EXTENSION,A_CVI,A_CVI_VS EXTINSN(V6_vconv_qf16_hf,"Vd32.qf16=3DVu32.hf",ATTRIBS(A_EXTENSION,A_CVI,A= _CVI_VS,A_HVX_FLT),"Vector conversion of qf16 format to ieee HF", { fHIDE(int i;) fVFOREACH(16, i) { fHIDE(unfloat )u =3D fPARSEHF(VuV.hf[i]= ); INIT_UNFLOAT(v) v.exp =3D E_MIN_EXTQF16; v.sign =3D 1; fQFADD(16,VdV,u,v= ) ; } }) =20 +EXTINSN(V6_vconv_qf16_f8,"Vdd32.qf16=3DVu32.f8",ATTRIBS(A_EXTENSION,A_CVI,= A_CVI_VP_VS,A_HVX_FLT),"Vector convert to qf16: f8 widen to qf16", +{ fHIDE(int i;) fVFOREACH(16, i) { fCONVERT_F8_TO_QF16(VddV.v[0], VuV.f8[2= *i]); fCONVERT_F8_TO_QF16(VddV.v[1], VuV.f8[2*i+1]); } }) + +EXTINSN(V6_vconv_f8_qf16,"Vd32.f8=3DVu32.qf16",ATTRIBS(A_EXTENSION,A_CVI,A= _CVI_VS,A_HVX_FLT),"Vector convert qf16 to f8", +{ fHIDE(int i;) fVFOREACH(16, i) { VdV.uh[i] =3D f16_to_f8_bias7(fCONVERT_= QF16_TO_HF(VuV.qf16[i], GET_VEXT(VuV, i, 16)), &env->hvx_fp_status); } }) + EXTINSN(V6_vconv_qf16_qf16,"Vd32.qf16=3DVu32.qf16",ATTRIBS(A_EXTENSION,A_C= VI,A_CVI_VS,A_HVX_FLT),"Vector conversion of qf16 to qf16", { fHIDE(int i;) fVFOREACH(16, i) { fHIDE(unfloat )u =3D fPARSEQF_EXT(16,Vu= V,i); INIT_UNFLOAT(v) v.exp =3D E_MIN_EXTQF16; v.sign =3D 1; fQFADD(16,VdV,= u,v) ; } }) =20 --=20 2.34.1