From nobody Mon Nov 23 04:34:23 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=1792796341; cv=none; d=zohomail.com; s=zohoarc; b=kst2SrnLQ1gsVBV2jYW0cRBI3XYymXsvYPfhjdZ+yKG9ykvBVPd3p6t2UVoEsJEW54kwiqk1wEuopPUa//pQKllR1rjSvqiiUYxEwIJ+LzLHMVJoRfDRdlTSaJv4wl/nfKkT3TZEFQ3YEAwG0dOT2DIkBRG7rJkh5BesXanQyEY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792796341; 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=otIqGnoRhtwE09jN124fMDxxXB2gSblXU38jbQmf9BU=; b=ETGRrX8CMvipvu8NtUvuxw9tTgWl8h1FkZBGo38nyO/ScT2bRu739mlH5WjM/Bcr7RJZtF15gV8oMqfg+10yMcXP8Y8iJgh9YXh7vIdabbc+a/ng9wwMyXjBy7Cfc5GJMU4/F/SPSmuo/L9DeqVFCHLHHJof06+ISbwQqsbYRKI= 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 1792796341447222.7641844861031; Fri, 23 Oct 2026 15:59:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xKODV-0002XM-4e; Fri, 23 Oct 2026 18:58:29 -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 1xKODT-0002Wp-5v for qemu-devel@nongnu.org; Fri, 23 Oct 2026 18:58:27 -0400 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xKODR-0004k2-Ao for qemu-devel@nongnu.org; Fri, 23 Oct 2026 18:58:26 -0400 Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 69NLv4R53982726 for ; Fri, 23 Oct 2026 22:58:24 GMT Received: from mail-dl1-f70.google.com (mail-dl1-f70.google.com [74.125.82.70]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hgart1b4d-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 23 Oct 2026 22:58:24 +0000 (GMT) Received: by mail-dl1-f70.google.com with SMTP id a92af1059eb24-16bc6f3fdb1so1509154c88.0 for ; Fri, 23 Oct 2026 15:58: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 a92af1059eb24-198a32ff780sm1280380c88.22.2026.10.23.15.58.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Oct 2026 15:58: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= otIqGnoRhtwE09jN124fMDxxXB2gSblXU38jbQmf9BU=; b=R2UX8JbSc4PS8/Vr IFvyU1zHXk80COY4fYqNoy9OiuHRJBPZ4+X0qdmUtyNj+hi9hMCmytM8icdG0F2m euK1biQI4B2qLf3PygVnTekfmb/sesQXA5Sh7MnIzkeVsXa6T6NIIJP43BjV8n1c GU9H/qhBI53EQS0Kt/Bk9nSArgGQ65MglAI24ooQOMO0sj0NxAWahmFuAmCpLqLR aZeJRzw70fFt0OF7EWgOxswrFC1C+pH0+ECeGIbb9P7pKjMBSB7NcMR0HB3HvtBx ZsKel8re9gIsMxx//lRPwvWeO8DElE6XkdaK+MZjG0Vw255SXU2xuX8GMUUhZ7Gj KWGF/A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1792796303; x=1793401103; 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=otIqGnoRhtwE09jN124fMDxxXB2gSblXU38jbQmf9BU=; b=M/7tmboOy4M8FqikQ7xvvpxgGp34gWMo6QgNydbDf+T6u2XMxv2sipqsGHCWC/fnsG oNmU/HI3Ep1jU5m8wR7c8k9uM6j6BJiCqhn5M7ivC3bndf6oWDlu3yEqAC40moY1+Ld4 QWPxb162hrqAWdanFh8th+iK+Ps3e+SSXv567pzC2jcpjRIFfSMY5WhoS5ZBSnCej46u TCApDLk5JceVm6iVUripL0L/M80pSDzSQ13XOqrMAt/pAxoIGUJksywVBw/l3m5fdtr8 EGV1C0G4uujCzUVMr4/EkwRIZWbvl8/IGdVAnkjHaabPUUqwFLngtnrpVFqfJ8GYsocR IwJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792796303; x=1793401103; 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=otIqGnoRhtwE09jN124fMDxxXB2gSblXU38jbQmf9BU=; b=Drcl9Wq0Zuvtj6NqHRL1UPGUQlXeD/Ni0guIRdIdXJXyUVNx9nlbhCgZTfSaGscA0I RvKYkKfa3ESCjXc3u0w21uQwVNB+ElaDWJGSQG70DkAkdwzSxI4+tr9hhmykphcHql1J 0vLp6wWDT4585gRngmQ/XO3JH6agpgbyY0Ge9YVuTKrum6+1Sn/s26bhQpcNyEMHyXj7 3D3VRHoG+t531VG38Qv8pqjVS74RCXSyzGamVAOjhIr6pWP8jR92CW0BGbm/My1MsW2G CNgsPD8dVCD1ZVMBfyvMFLlbOCJ30ijC/LrToXRubp0mz+VWlldiTue1RnukFwGNJezE g3BQ== X-Gm-Message-State: AFq9FYLk8EAUtILFDg6YHb75zIS3KHGhESmh4ha6sbGo6PzkFFXM7Zb3 /iTppJtr5qVJAO2V5hUf0ee6Y7Ya5OPEpFkIEKUpQTK8jpeVtyF7Fu71JO9qCCXnQ8GJiH5HXwI i+2Y+CMWPSSLGqQYlpu/PRpQ68HOk9xkxwbqJ0AtU/DYcd2fHjei/KntMKJkYgH08og== X-Gm-Gg: AYBFou3gAIM8ei7EqQC8QWQmqY/DbcvcLTL08ZWqAJWCpZsqUC7ZwV7EM+gsmEg5hCJ 3VoZWUYFTDEGALpSGg55Op1LK2eiqx+tbn/LvWVk3Ap8TaL/UtTHrmZfUo3+bDVTj0k4q8ma4DI OnqJnWCMq2W21CV6r8rXQv99O/i2wpp4NWzhib+7Rn1O9adBZ8Etzu3e2nC2+x7yoCQTQQWUmCp NfjlgIOifEWnwSYQGv9wUUQLKJq1TzaGxvyoClqUT7yWJQ9zUL5cNblJhYCJLl+bA/Rh3EpYP4u UHHZPKQfYHBY7omwEAS3JwOrTa9DIWd//F+6Iclu57BWmsL//IBL4Bd4ChJKvlWYzDfzILicaoP SpVGapDuCnli6hAdp28TUdCYfl15JWaFvHtmJvUdQT5mdHLM= X-Received: by 2002:a05:7022:5e0b:b0:159:aa67:28c1 with SMTP id a92af1059eb24-19935be8193mr556649c88.20.1792796302880; Fri, 23 Oct 2026 15:58:22 -0700 (PDT) X-Received: by 2002:a05:7022:5e0b:b0:159:aa67:28c1 with SMTP id a92af1059eb24-19935be8193mr556614c88.20.1792796302260; Fri, 23 Oct 2026 15:58:22 -0700 (PDT) From: Brian Cain To: qemu-devel@nongnu.org Cc: Marco Liebel , Brian Cain , Pierrick Bouvier Subject: [PATCH 1/4] target/hexagon: add v79 HVX vcvt2 instructions Date: Fri, 23 Oct 2026 15:58:17 -0700 Message-Id: <20261023225820.330905-2-brian.cain@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261023225820.330905-1-brian.cain@oss.qualcomm.com> References: <20261023225820.330905-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-Details-Enc: AW1haW4tMjYxMDIzMDA5MCBTYWx0ZWRfX81EJx+5ITfIG JIGif6P5xk0iMvhyqIPjgEYTCiBgtjkLGqxqc2JiF54SAynPz1WWeoLgbuX+TCTHl5owUgWnoCL A6tdrxVkJfodB2Qwrq3cgrjmxwJ33QgqhWSzCndcWj6pM0DUlZe/Nz2QFVxQJKG9wVDfzoANqDG EoBuQQ45lXCdtcvJd8NjiOpEcWNIGrOgvQxhZtn3cB9W7Bg8B1qzsXVJZDGSO7y0VfYNvxuWDpl XEESiWscLDB6pJ2V8EAaVrH5lZw6T4HS1os4DFTxzq0p7RqA4DsNzSoW9lJAzVtpaXclvdwZFtc cE2pfBrNbLbdK3VAMk+Q0nJ+ZeA4KpPlt4z1pLK8bBwBuWszwgJOLwQa8qM1x1qB+SZ7cSrv+7c 0p9hYoEmIwxAkcT+a/CVesIvrY3h8jZOqmycYAX+4rLpv0XuRW7wQyCBwWGHscBfP9i4Z6AKhWh aaEZlV9VvL+XzbEeaHg== X-Authority-Analysis: v=2.4 cv=JI+uIMKb c=1 sm=1 tr=0 ts=6adbe690 cx=c_pps a=SvEPeNj+VMjHSW//kvnxuw==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=IkcTkHD0fZMA:10 a=660iZSQnnn4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=gowsoOTTUOVcmtlkKump:22 a=EUspDBNiAAAA:8 a=5rcnURY8GYM5_4O9xYQA:9 a=QEXdDO2ut3YA:10 a=Kq8ClHjjuc5pcCNDwlU0:22 X-Proofpoint-Spam-Info: AW1haW4tMjYxMDIzMDA5MCBTYWx0ZWRfX+WST/fCWpDTJ zAaYf4+8f5R2yWKKYwPAI30r5a9b7/IbXK62dpe7JhBZYwYngU6G7iUWp/5RMZFCnEa+0Hr68La uxvS5pfYplt4wg38yzNH9sZOtsMRUsI= X-Proofpoint-ORIG-GUID: 2HN-jce5MergpE4GAAUfxO4kWpnWxRRx X-Proofpoint-GUID: 2HN-jce5MergpE4GAAUfxO4kWpnWxRRx 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-23_06,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1015 spamscore=0 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 priorityscore=1501 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610230090 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.180.131; envelope-from=brian.cain@oss.qualcomm.com; helo=mx0b-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: 1792796344765158500 Add V6_vcvt2_{hf_ub,hf_b,ub_hf,b_hf}, which differ from vcvt only in element interleaving. Signed-off-by: Brian Cain Reviewed-by: Pierrick Bouvier --- target/hexagon/tag_rev_info.c.inc | 4 +++ target/hexagon/imported/mmvec/encode_ext.def | 4 +++ target/hexagon/imported/mmvec/ext.idef | 33 ++++++++++++++++++++ 3 files changed, 41 insertions(+) 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)) --=20 2.34.1 From nobody Mon Nov 23 04:34:23 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=1792796360; cv=none; d=zohomail.com; s=zohoarc; b=haLu2MTyveVsBKbVm3pPs9X8pNfXX2JTULJ8fOgoUER2LUOkqUSP7Go8Ch0IVaz/PEY8z42VVlkrpeQ2kGyrcyZFSpS2vHB0DxDokQgkNsyw7JUpjcAmOcvJtTa2M+P82HVHuzRJWAY3HIALDTsOehDfs02omguqjpgGG9hpmb4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792796360; 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=wnzQTbJjVCWODM+U7Joysygy4Nvczjnab/j51qgU19U=; b=UX995VgETzjzMzMXb8+odt4wBnySw1GpCcvxc8ApmqL2rUW3grA1W2Xk07jkpVJJKbiKwtPYEGZXHonFVEEyifIjfyjxB1phI+2MdNat05Knt6bnDLHoMG/DwBy8ibsI1iVwhv92zijGS+owDgkQt4wd7gJIvX4IhvGroeI4ycc= 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 1792796360050847.3668193186285; Fri, 23 Oct 2026 15:59:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xKODY-0002Xu-6o; Fri, 23 Oct 2026 18:58:32 -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 1xKODW-0002Xe-Lu for qemu-devel@nongnu.org; Fri, 23 Oct 2026 18:58:30 -0400 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xKODT-0004kI-Lr for qemu-devel@nongnu.org; Fri, 23 Oct 2026 18:58:30 -0400 Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 69NLv6ug3982748 for ; Fri, 23 Oct 2026 22:58:26 GMT Received: from mail-dl1-f72.google.com (mail-dl1-f72.google.com [74.125.82.72]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hgart1b4e-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 23 Oct 2026 22:58:26 +0000 (GMT) Received: by mail-dl1-f72.google.com with SMTP id a92af1059eb24-155a75f91e1so2473993c88.1 for ; Fri, 23 Oct 2026 15:58:26 -0700 (PDT) Received: from hu-bcain-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-198a32ff780sm1280380c88.22.2026.10.23.15.58.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Oct 2026 15:58:22 -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= wnzQTbJjVCWODM+U7Joysygy4Nvczjnab/j51qgU19U=; b=FlWwloLg9xyqIZyk OWvKZTj9auxc5rgxF4awPt3SvCamqkOLVZJRNoLflT5lVx/GjbGfPNjFGQW97Xv9 kFh/SjG1xoY/crQEJZ07b9SZwQFFJI4ovqT13F0ge2bpRsjxyr2+SsnATI6IE4Ed hNP2s2rUx5zxGhkBSGGYY8e3YOf3SsxBQZZ/Jb/f4ZtE0GFj4NW5s2c1vQrjBr0z 8b2bijQIabOy/XseqYQAhI3+eo+cFA66pkCbHJZkYQ+opYiQCN/a3e02I8XUitNU JkWY4N09q0NVdwz9/wCU1Zuo4pZh8pzdMJD+hWObgdE1FtlYil5tQJ9c/yMALoh+ l+Y1/g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1792796305; x=1793401105; 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=wnzQTbJjVCWODM+U7Joysygy4Nvczjnab/j51qgU19U=; b=Jmw/yQSvIHTrZRJM+dFJ1ZHXNI0ZVb5u48yQSOonM+eA4PHkKHZP/MSYmXek8Hx6tG dJzE3B3rQht8+Yy3aKlT5IUvf0FJqb86B/gKrYXstqhNklpluxXmQTZl+EukY6vv9LBu Htv/ihh0lGKYamvkpf5/mUyNQMuH7XHTOFv/sCmjrZjEMY8tBUxbiCfvauTmj94YHOaB zrsZPvqO10RdxJ8IuCCaMWfTYo4/VvRrciQr9vinUNXYtj1EY02nKCH3AMCEDpivA85R OXsKr5j5VOmsvXb/CRLkycjCeObJtPPWA76fe9bB0nT6U2L6VZGWTJrcmZTE/pfsebfb /ZTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792796305; x=1793401105; 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=wnzQTbJjVCWODM+U7Joysygy4Nvczjnab/j51qgU19U=; b=p9eK+DP63+4u+rB3sulxnPghqFHLUWxiSpQUoaCHaq6ExOP9p4pxc/TLTW7rJAmgLU 0732cZ+nxeYVudO4Q6pHvb3yo/UxaCL/Gt5moDvOpmCVOhjNsqjrMJWHT5DUWpgckEMd QB8c7Vmni9DbiPIUOp1pp24WhSzzkjrAzrd1fZdUf4+fntV86LLgro0O73uYWQ7LsaMB oBTwyXYStF909KqBbXqYlhb4416cQwmqiJjhwoBsXwqay8gulAwqs+F0kJu6+tBJJi2h c4YCtPqw0rRyXYOV/8QKe+syvl0rqv8732ynsDVcoKZRt4+i/jLRC+EE+w34ls4vxPMF yDjA== X-Gm-Message-State: AFq9FYKOmBHZdM53Cp+3vr1VRTiKRHhTs3QxxYoY6u0llQvUGEg8NwBT J3rtuvO/UphlUy2AVrNXQwTo6mlDvyxNrnHPeAH1l5mjnelXoXA+Lo6OgqKLrQxov+VGihGztC4 zA4v5ZV0dbWr34AeleBsKVZGTpUQUYQSK51pTozbxkGeOwSRRcEu2KoSWOv6CopHNQw== X-Gm-Gg: AYBFou31pObFQMYEMKeSlib8MoC2HgSOGqpR0HT7h1LoKCIeO4v+CGwd/VzKLJYtCXB 2A1rrjoV3fohl2nh2dBGMqoMEZaUj1aLmhlympFbfm7aKjkA+GSlveFoh0opplqkgZz8QOKzeXm Zs3l1Nivc0gFEOJF5v4TcSJLgtx7aFm0cG3i7aLcaPmNie2oKmMBPrl9g4N5QKd4dIw7Igbc+M+ 8LfjAEyxkwzc32qrVqV4VPo3IoOcsYE8uW2F/EA4TI9FNM/FOtBehDdQ2xyYKf3SQI2doDKMuM9 slfDpw7xA6fUh6GUPpuTV3u9/lT5lNS98fgs3hwP+JuZuzqgpIs6E/lv0C8QsMBco9YY3EyiqAq SR9rn7whFRSfhieiXCQzonFvw1AyhaZ5WChbl70bnTJO7vWI= X-Received: by 2002:a05:7023:906:b0:192:a481:361 with SMTP id a92af1059eb24-1994d8b9822mr552201c88.7.1792796304916; Fri, 23 Oct 2026 15:58:24 -0700 (PDT) X-Received: by 2002:a05:7023:906:b0:192:a481:361 with SMTP id a92af1059eb24-1994d8b9822mr552168c88.7.1792796304235; Fri, 23 Oct 2026 15:58:24 -0700 (PDT) From: Brian Cain To: qemu-devel@nongnu.org Cc: Marco Liebel , Brian Cain , Pierrick Bouvier Subject: [PATCH 2/4] target/hexagon: add v79 HVX FP8 instructions Date: Fri, 23 Oct 2026 15:58:18 -0700 Message-Id: <20261023225820.330905-3-brian.cain@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261023225820.330905-1-brian.cain@oss.qualcomm.com> References: <20261023225820.330905-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-Details-Enc: AW1haW4tMjYxMDIzMDA5MCBTYWx0ZWRfX4KMzS1ni1URz SipsQtseWtpdwsYhY5PDWubE+8tTZuxpNwUGNnrC3aPt3osSiriXPeJdyLqne29d+qUa9uQgXQe VqkV+y15bpJcwbsnFEpEwN4vLC60gzFPvRDhgGYJz6Hb5a2EEHTIJw9tL8mbng3hA0LvwF83WKl QZqnUpKrcvhLcZOyTEZNkqnGfC3W7Es/2dbKZUGLqbcKA7vbihgSISQK5dPSwnxtN12cvMojGO4 1TJrTUxIdyF+DWaNa9F/Mq+F0JFuRVq7hdlnvHH5ttUwEZ5JLZDfJ1aLhnfqlYDyWG/KWcwRpRm LreL9k7HQ5+s74Ucqt305vblS9g/UbJ0vnXoJZsXQOKoDZJvzjWyAWGjbU0ljlq9AlcHjfjJWzj QSZ8tBRCAJqLW7yMTMSg+G4Re3P5e1UrIb/Qzvu4UJiKkeO3xz7QO3Qm+71hjc9s1QEGbp7b1+T oNRMAjKiHmSWeVomRIw== X-Authority-Analysis: v=2.4 cv=JI+uIMKb c=1 sm=1 tr=0 ts=6adbe692 cx=c_pps a=bS7HVuBVfinNPG3f6cIo3Q==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=IkcTkHD0fZMA:10 a=660iZSQnnn4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=gowsoOTTUOVcmtlkKump:22 a=EUspDBNiAAAA:8 a=qIezscJ6J6ixo0ZvpbEA:9 a=QEXdDO2ut3YA:10 a=vBUdepa8ALXHeOFLBtFW:22 X-Proofpoint-Spam-Info: AW1haW4tMjYxMDIzMDA5MCBTYWx0ZWRfX/3ehd59kBiWW dWlrRi562RNWCr1a8qLbnuS+pZuU8dgPmhGUBkNBL2Nb+wgr5xbN0a5n6lyJd+HFnV2+AmgMyOo QvJEu9it55zqRV05UgKSyOmej+R891o= X-Proofpoint-ORIG-GUID: rbmk5NyAO_TtujynuBU5gllpjqBXDoCR X-Proofpoint-GUID: rbmk5NyAO_TtujynuBU5gllpjqBXDoCR 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-23_06,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1015 spamscore=0 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 priorityscore=1501 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610230090 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.180.131; envelope-from=brian.cain@oss.qualcomm.com; helo=mx0b-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: 1792796362788158500 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 +++++++++++++++++++ target/hexagon/tag_rev_info.c.inc | 12 ++ target/hexagon/imported/mmvec/encode_ext.def | 12 ++ target/hexagon/imported/mmvec/ext.idef | 78 +++++++++++ 9 files changed, 266 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/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:23 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=1792796356; cv=none; d=zohomail.com; s=zohoarc; b=MilsxYWop33r1jnrUiiLoTnaxOcdm/lG6wEIACbdAvWvKLciCr2Znphki8pkSGh2VNlEN7wlpKcwGHQmoRJebZhq0dxn9wBik3XYmYZ7BYyDHywJ7uZIA0d82ovZmrR05R/9DoqmXV969v0WYdxFfTxa8SlL9MT7B3XrC0JEVVk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792796356; 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=B6Y9pDKK+/a2CAj8Jsgwgfc78jlDBnEzxldS8EuLZTQ=; b=DpukR+u6HKiyw0T/7XIzGlYSaesWQU6pqB0zHGKvAaXeQbZ4htBKffMcsOzWnkn8XTCYgWPkeGIjrNsvZGdnxWjjYjUk65bHdo7Hn/6PcGg1SeC0slw5pNbGmiS5TtV6xwopMk2pX43s2DcKMKi7XKvmiIR3nqQmxRfCftLcWYY= 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 1792796356900706.8206043265792; Fri, 23 Oct 2026 15:59:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xKODY-0002Xz-J0; Fri, 23 Oct 2026 18:58:32 -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 1xKODW-0002Xg-PH for qemu-devel@nongnu.org; Fri, 23 Oct 2026 18:58:31 -0400 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xKODU-0004kb-Pq for qemu-devel@nongnu.org; Fri, 23 Oct 2026 18:58:30 -0400 Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 69NLv9Km4006312 for ; Fri, 23 Oct 2026 22:58:28 GMT Received: from mail-dl1-f70.google.com (mail-dl1-f70.google.com [74.125.82.70]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hg7cn248v-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 23 Oct 2026 22:58:27 +0000 (GMT) Received: by mail-dl1-f70.google.com with SMTP id a92af1059eb24-147be78cd56so5221036c88.1 for ; Fri, 23 Oct 2026 15:58:27 -0700 (PDT) Received: from hu-bcain-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-198a32ff780sm1280380c88.22.2026.10.23.15.58.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Oct 2026 15:58:24 -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= B6Y9pDKK+/a2CAj8Jsgwgfc78jlDBnEzxldS8EuLZTQ=; b=Meu4NKIh6+lfb4Al JSIoWB9pgI85hr40WkPGUEWtsQNr9YFfx4L4RMCfBu6SweIZJwPb/APZMFxUqhF2 tUmL59DCIc5uI0DeZoqmsm/HBopAj4hSXp8wEInots4R+5ANlT9mNOYURHLnsu3Q 10j4BGWR+g5b3YSBC4B8GI5Ry/20eSFFD8bAleAvyrvfNcRcI2kdANQm5RTcPBKt PpiChBFh1ZQji9qVdeaN5n1XsOZ8EP3K9vB8VDPD4gfDYwBu4FjMffydo1FbCFR9 qJ4bdqVXt2UyFjekNI6+h6c+x4Sp4z/xeTbG0hfNbOS2jwDVsCjjEmDmh2sSw61c 8qvQfQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1792796307; x=1793401107; 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=B6Y9pDKK+/a2CAj8Jsgwgfc78jlDBnEzxldS8EuLZTQ=; b=f10Ltoz+eUodUnCIycFotz8qwfK08HISvvISLdlNgtV1xgDhBf/OjDB6hXNE/i3Q9a sC6N2nACHg3yEyhwT3DmvQtrkOEL61Ulq9ulUN84cXa3tUC5LTvetKO5O38NxGTJQ60H FPK+gE8s1P4MkXuOQmDEmiqlcW2nBSvcU0Ly0pcARMEjyraDdj54OnDJnd7Gc6KwXgW5 BI4ZxrlzBVbt9VpPMXFu5aBAZitRd1zWlwCD089GjB1LdsuXQPgQHRXL9aBBD6+RcDBL 6aVp6xBfDPcnRc7tjCZJ3oiCRA03uRCDvdLXXzDmJ74Xhs8dosn2OcQeY5wBJG5cSn+J HRkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792796307; x=1793401107; 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=B6Y9pDKK+/a2CAj8Jsgwgfc78jlDBnEzxldS8EuLZTQ=; b=OEdevelxlFwScifHjJl5aA+hUFbEEpAvccDeRh5ug2bU8LccULXWbt7f0bsVtReriB 0csb/viwUXqrE+mbogVBXXzWtr5L7M915+/+oT96J94XV3Mm05s06ZxULh0LKD0N/ZHQ emKAtH8HMtjUTXw8JuBUpnHPFa4N2bu37nOo0qHvPC+UcxGaZPi+JwDa2RQ1XzkYv1O5 10UoL27CkjIq/HQh9zpZ7hoqjsO7P0F09AGf1JDQB70CzrAJ3Kzo4nxRjam+oIG0jppG WQacnX0U3rvYkAq63lGzjZK2PhCV28NvWjDtw0PSX0J4g4pQkqr+TknNpsyLnk+u3aaf +6/g== X-Gm-Message-State: AFq9FYIz8bNEpc8gYbL/hEmJhHmeXw2Nulz6GTrnd2SfNJRo14TQT0oa Dp/SaBWfPx3DaOzflrURz3kbmr0vEDhU0f7KgOhucPQR1bgsfji0GATA0Cb5NTMufS5Pz9Hd2l8 kootAq2nJOKyeiBvo4HfOnBP/fpInCmsXtWPX6yxBKQrRdb83ORtIcCCEJyU2DE2vdQ== X-Gm-Gg: AYBFou3Yu0RCSnFE3/mjK1iXkMFaT2WdYTpoN8i0gdO/rp2a16XNq7HqbgJhyqKYsHW LsTjdbFe+wi5PWHncVu1rLsb5xtcMx5PRgw54231PC4uZzU0Dof2hHN/QXnBNpN990a+FmTU4C3 b4GhM4FfCJLawxnHxICgvmqQI/SSRuAiYRj9nL4OUxHm9SgYFv/uPVcT9lEX4h8pGlGphABabkK 7sRr/e8MkiK12esfddzZTmiEPwPhY91KZEp18S0VJI4BMosEsFYqBNBulMb21xe+4V7aTHnTaG2 6UGJ980Z1OaZZVlrAlwkap6RUN5Jnfa1ws0zbNGSvsxs2s0hW6FzqMaPNQTFmgdAtvmQCiVX0ur zwYAmhnsW0lJtRPuVPUhaD5w2gcTAVZ8JoZFmrJkOac7UNFI= X-Received: by 2002:a05:7022:b055:10b0:195:5b0a:7abf with SMTP id a92af1059eb24-19936a6074cmr558351c88.7.1792796306546; Fri, 23 Oct 2026 15:58:26 -0700 (PDT) X-Received: by 2002:a05:7022:b055:10b0:195:5b0a:7abf with SMTP id a92af1059eb24-19936a6074cmr558330c88.7.1792796305937; Fri, 23 Oct 2026 15:58:25 -0700 (PDT) From: Brian Cain To: qemu-devel@nongnu.org Cc: Marco Liebel , Brian Cain , Pierrick Bouvier Subject: [PATCH 3/4] target/hexagon: add v81 HVX FP8 and qf16 conversions Date: Fri, 23 Oct 2026 15:58:19 -0700 Message-Id: <20261023225820.330905-4-brian.cain@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261023225820.330905-1-brian.cain@oss.qualcomm.com> References: <20261023225820.330905-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-Details-Enc: AW1haW4tMjYxMDIzMDA5MCBTYWx0ZWRfX9c1hRuDzkP7M I8PGnJkrcJbi26buHOCMTwfTRP6SmnoYNoVCKx30Z/+jjr9hSkkhzG7gIEpel3dCnDfzJ5lHVD9 fCuiQGc+VTFRi9qxpEwZA4AJ6m+Ix+7wgGw3nNJ2e6W2cNNEHYhdbl0oXisM/V5AFQhADL0DUjN wxpfSwxTlzTJjpCbANhlr81A7gxNN6SQ/urw9zwG5YN4f98m5MfMDKbFTLGUYKvsIqwNGy9gHdp e1iX5dfOJxhhl8ELDjpuS5OneHDo8E5+3r8SCa5rB/1s5raWZHPy9+jiJVmdNWOzwDBEfXhHbKu 7aQuCdsima8AcCDUaHfZ7obihFyAjCy8v83qdB+3RPQoUvqt/yF3iZepFN0fwUbbadH34iM/r+G h/z9yPUiYBIduLNJDBGvv22RQzx1yLStotEo+NdkoO60JTbr0L56NPLNjYRQ4fmRCTAwbwShcNe kdihGs7V4JI4K26zXbQ== X-Proofpoint-GUID: Rht_d0ARP0CKNqGryMjafAPBKWkLpqiO X-Authority-Analysis: v=2.4 cv=a9mlZkSF c=1 sm=1 tr=0 ts=6adbe693 cx=c_pps a=SvEPeNj+VMjHSW//kvnxuw==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=IkcTkHD0fZMA:10 a=660iZSQnnn4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=rJkE3RaqiGZ5pbrm-msn:22 a=EUspDBNiAAAA:8 a=lAlMAaeUuj354z6fHfAA:9 a=QEXdDO2ut3YA:10 a=Kq8ClHjjuc5pcCNDwlU0:22 X-Proofpoint-ORIG-GUID: Rht_d0ARP0CKNqGryMjafAPBKWkLpqiO X-Proofpoint-Spam-Info: AW1haW4tMjYxMDIzMDA5MCBTYWx0ZWRfX2DFNb4BQ6qlk Ewq/bXVyYULl/Pyx0O2S5wgTsbuw2CINWromqzQ7M5dbaHmp4KK25kmd/Z32QqWvYpMs1QNToCp 2AgUs7IKbQMRaTKYd1a4+CpoAWGlkGM= 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-23_06,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 impostorscore=0 clxscore=1015 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610230090 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.180.131; envelope-from=brian.cain@oss.qualcomm.com; helo=mx0b-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: 1792796358559158500 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 ++++++++++++++++++++ target/hexagon/tag_rev_info.c.inc | 2 ++ target/hexagon/imported/mmvec/encode_ext.def | 2 ++ target/hexagon/imported/mmvec/ext.idef | 6 +++++ 6 files changed, 66 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/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 From nobody Mon Nov 23 04:34:23 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=1792796341; cv=none; d=zohomail.com; s=zohoarc; b=aYWYRqnEhCs4waNTHkonFu0xCwkz2nq2o1ZHen+wMH0kIS7b1g24HtifwE8p+6MRu6rMWrWJjfidxxyd+SvCjhHJlxc3AkJ4YZ5XfeZozcYUQeLH/CjX5hbDX0VDEx7Gz7mm+mw09bYXsOPlrCZ+TFX7LwA6sbk/dKF8T9r4e50= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792796341; 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=GVRGzEnpSSI21HGpSGQGyiCbn3AfuAXardSXcQkLIpM=; b=EDk9PoFTvYoptSwn76UYv1gdPitxvrOMR4+s+crrFAFb7fmkqGqgLJeIyBKO79vRFgTHG8hioWOB68/x0axzw7Mv402v+vVD5T4JoLGsk1x0wiJLPT1/VxQdbeI5oCW/F+aQkn/8KC+kPzmqK9aw39TfPFngYVi0JJcamf3mdIM= 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 17927963414176.781617519512338; Fri, 23 Oct 2026 15:59:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xKODb-0002Yd-PT; Fri, 23 Oct 2026 18:58:35 -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 1xKODa-0002YV-73 for qemu-devel@nongnu.org; Fri, 23 Oct 2026 18:58:34 -0400 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xKODW-0004kj-W0 for qemu-devel@nongnu.org; Fri, 23 Oct 2026 18:58:33 -0400 Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 69NLv7qp3683556 for ; Fri, 23 Oct 2026 22:58:30 GMT Received: from mail-dy1-f198.google.com (mail-dy1-f198.google.com [74.125.82.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hgas6s9cf-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 23 Oct 2026 22:58:29 +0000 (GMT) Received: by mail-dy1-f198.google.com with SMTP id 5a478bee46e88-35c5aef2a74so5528657eec.0 for ; Fri, 23 Oct 2026 15:58:29 -0700 (PDT) Received: from hu-bcain-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-198a32ff780sm1280380c88.22.2026.10.23.15.58.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Oct 2026 15:58:26 -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= GVRGzEnpSSI21HGpSGQGyiCbn3AfuAXardSXcQkLIpM=; b=hrNKH02U5Z9mYoiT kPz8uBY/nZ7NAs55jjMNB0rlSqNUExLkv+ct2D0JJmgVt5L3sPJKjdityGhzpU5S X4EJyasOhE/YdVnt8LLM6nqTeOHPmqDRPF2xQouJ2ZVgHus5O/XGvvGRshJgreFS l7k1ttciDZb8edlj02htpNsnm9PtReJHaB3ZsC2khXYDRp3r1aeuxc5aMYjzHMar z0M4skLOwkXLv8Bgb4jlv7HtAbhnEY4W5uKKXEEHRIXDJkiTagqegtw7W3wzzE4u BJkDi6tvAYXbs7iumKge9pnxC7+AVQ+MDb7LTjXT2FI19zCPI7TL0OmEU9AO/n3I A43rjA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1792796309; x=1793401109; 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=GVRGzEnpSSI21HGpSGQGyiCbn3AfuAXardSXcQkLIpM=; b=grku6oChKZkB3AWskN6lo19d3Mn3qB4S1qwhDyZyZWDt8UvIx3iqgyUIRCqr6qBDtn P7h789dgncy8eq/J66336h4CGRNokJltEKKA0Za5V7IKIGmZ1T5RWyFO40fZmlNn5q+v 4Qip0JUjiBrBh9Oe2vFtiY0GVRL+81Z5z4YJwkmmbsaIEiAg+LOUwO2zb248Hj2JIcVH 0SUke5+j3s1Z4Q0NLesdmmXLaO86s/lgHPQyTBCEEP2HxvQgJFDofnYqvKnJueE0s5xL 1/19eCMqtVqbPV3XEq2Mpt7qpT6Zs2pSTbYS15Uo6rY2NB+tmIPXtTzFKgzRl0KyVNsR rFWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792796309; x=1793401109; 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=GVRGzEnpSSI21HGpSGQGyiCbn3AfuAXardSXcQkLIpM=; b=KdHaOT4uK0zusyCcBVR7FPwliRjv8hMa5T5r1CjLwS4vH3fpJ7ATyHYkOeQycP9VGc J+dK7u13VrPm88J7fXQZvFohqh35ucFryzWX32OEUkskVFFkalRvzs/y8cguqAV0zufP /uIVdKQnpXa0uuxEfy+wiFYmjvBXdo6SX6fX8sYC7xCCunUFdqAJLc0yML3f1kILKQQl TZTYcm6IWg2MElckD0kYqYGoGd9uWQdz8HN78o4mWRvciL+TFi3f/8jC0Ln5/408hF7I 6c6HrvdK0nBL0HYTCKa9hwy51dnYjeQ5NutObomWFDoRlCjqdGm/C1hsDq4L2op+GABE WlbQ== X-Gm-Message-State: AFq9FYIXt3LFd6+WXI3rvo5z0g66lXs5wYnvuCxjSQ/oDXX7gSPr/JbN dIlxAdvEeOe9NJ9XYd2VAAB4UN4mpWsBmJpikcAERAbDBIUsrjAPmS38M5iBA2wqhsk1+nSNCUO 2tafZudOaVPhyCGBZa5YFF8n5L83P6RsuzMUoJPkzHcO2bj/weZi4927+jgs6SmJ/gw== X-Gm-Gg: AYBFou0W1E2i3IEZMVXiMzPiZRKYqc5CShCaGMHTrGf2jXiaDCb58vWM//0zmHaML3M DRi5R31egZN86wNByqwqnrGmlNyraOONMsodMhadfIVP+17/FTz7x6xfPlygpsHK1kPXCi5uZt8 CBsyPub0yGnMFCubgJOCH3eGYp1IxKCDzf2fWKW5Aa/iVnimqDAGnLzyAI9KSNLEBGOICKePzYK D7tGjM4wrR22w/i3uWXqJU0Q42V8TlVrV9v0+hDF827Lk5i8XukM7nGmfphjTSxtTwWSGMYpWL0 6zDngV8eJUsxLuH6QMADT/OtsiDQ7KP+rQWzmgf3SzBYyzLrO9aczc29SIgK14lITRU3o6G0atg vlUcQE3+gqTmy8p20PN5YR43LwOPNqfI0HkrwYhyY3r7JeRU= X-Received: by 2002:a05:7023:885:b0:16e:6e3:9a9f with SMTP id a92af1059eb24-1993639e6efmr725831c88.34.1792796308330; Fri, 23 Oct 2026 15:58:28 -0700 (PDT) X-Received: by 2002:a05:7023:885:b0:16e:6e3:9a9f with SMTP id a92af1059eb24-1993639e6efmr725793c88.34.1792796307494; Fri, 23 Oct 2026 15:58:27 -0700 (PDT) From: Brian Cain To: qemu-devel@nongnu.org Cc: Marco Liebel , Brian Cain , Pierrick Bouvier Subject: [PATCH 4/4] tests/tcg/hexagon: tests for v{79,81} HVX vcvt2,fp8,qf16 Date: Fri, 23 Oct 2026 15:58:20 -0700 Message-Id: <20261023225820.330905-5-brian.cain@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261023225820.330905-1-brian.cain@oss.qualcomm.com> References: <20261023225820.330905-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-Details-Enc: AW1haW4tMjYxMDIzMDA5MCBTYWx0ZWRfX6mn/UzSL3tQq 8LctL40SqNlLL1FILSwBVV5KrN+EUrLaZT/n5chBFVo1J3uERUmCJRG9DmX3sRcD6aO0qP3bo80 O8xTNS6LJlgk8c0K7ES4noJVBgGznGWIEpsm3EVXW/MTaIKDyWNiXyb2tON8eeJhNtC858xJZTD 65GN/bgmGV1KEF+BLqs3aLfpxdxJ4/G0bj/LBCeNbio2iiFCgVpMX0XyScgckt/aZGrWQeQhU/c fhsYNWXaMnFx/YkEyqMHVbo5ULCUH4L16QNCORZAsAW7vPcpCiLztNcIES+Z/9HmDnDC9kQTO3G JdqsIDGxWTMLBNtX1Zi1gFvvgtm72UYWJaHQLHGPH0/HBH6GQttGrDsGqnSDg7rEyJMgWVOtYxa 7CyuGN/vfDJE3G12/thl3ohrdTwgG4nT1454jsb122jb8Wf6SFNBy5hguksF8qMURn2MaCo6j90 uM5cw3Wp16P4MvgDmIA== X-Authority-Analysis: v=2.4 cv=DK0acCNb c=1 sm=1 tr=0 ts=6adbe695 cx=c_pps a=wEP8DlPgTf/vqF+yE6f9lg==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=IkcTkHD0fZMA:10 a=660iZSQnnn4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=ZpdpYltYx_vBUK5n70dp:22 a=EUspDBNiAAAA:8 a=xr-y1N7-o2pEdV6oJ6kA:9 a=QEXdDO2ut3YA:10 a=bBxd6f-gb0O0v-kibOvt:22 X-Proofpoint-GUID: LPjrnDx1wEXPdBocAnrnYBi1gElADGye X-Proofpoint-ORIG-GUID: LPjrnDx1wEXPdBocAnrnYBi1gElADGye X-Proofpoint-Spam-Info: AW1haW4tMjYxMDIzMDA5MCBTYWx0ZWRfX+j2oFTgB9UT2 nCXwIpgjiGPiGnA7BBFsuYZ4yiN6xuXcvv6iJiOyScLoDEZuH6S+nwvvXrdrclnFIXauyvsSZLL 3zdGNUQy1Y8SfvPlYFtO+qThiUkTxW8= 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-23_06,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 spamscore=0 priorityscore=1501 adultscore=0 malwarescore=0 impostorscore=0 lowpriorityscore=0 bulkscore=0 phishscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610230090 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.180.131; envelope-from=brian.cain@oss.qualcomm.com; helo=mx0b-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: 1792796344789158500 Cover the V6_vcvt2_*, V6_*_f8, V6_vconv_qf16_f8, V6_vconv_f8_qf16 instructions with tests. Signed-off-by: Brian Cain --- tests/tcg/hexagon/check_rev_gating.c | 30 ++ tests/tcg/hexagon/fp_hvx_v79.c | 478 +++++++++++++++++++++++++++ tests/tcg/hexagon/qfloat_v81.c | 121 +++++++ tests/tcg/hexagon/meson.build | 2 + 4 files changed, 631 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..63c4a125a5d 100644 --- a/tests/tcg/hexagon/check_rev_gating.c +++ b/tests/tcg/hexagon/check_rev_gating.c @@ -124,9 +124,29 @@ 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") +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") +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) { @@ -167,8 +187,18 @@ 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); + 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); + 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/fp_hvx_v79.c b/tests/tcg/hexagon/fp_hvx_v79.c new file mode 100644 index 00000000000..084cced93c1 --- /dev/null +++ b/tests/tcg/hexagon/fp_hvx_v79.c @@ -0,0 +1,478 @@ +/* + * 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) + +/* + * 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(); + test_vcvt2_hf_b(); + test_vcvt2_ub_hf(); + test_vcvt2_b_hf(); + + 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/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/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