From nobody Sat Nov 15 22:26:28 2025 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=quarantine dis=none) header.from=tenstorrent.com ARC-Seal: i=1; a=rsa-sha256; t=1746099851; cv=none; d=zohomail.com; s=zohoarc; b=UKp/eAjOmyAJvlUsMZXwb/L23uGpo2zAEfHflw+VhBfVM+Yq2NGtM8m3RJV7OkHf1bZs1kkrsgjFliYhfmcyibd262+0SV7IN0CiGuZM0SDOjMV47raxoio6bM+Ikf3ZhmnqOlQWLhVTXfAAHSfobobPYHfihYez5s7UiAcmZGk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1746099851; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From: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=Vt0jVrSyerxshL5eCuQqtXgeeRWNi9BNM7IDf17MV90=; b=EMqnCB63+D146bo5CKdvfjRSFNR5Vsnlw8SXNtLmN7vAbmvGouaUq0zMoHXOZGkG43CS+sLx9KexIpwbzJ9osTV8UOomXspiekon73ry7IXK2go9JpvphVbCjNZoSVgK7mnk0PfTU89wdYF72B/2X/RI2Rl3Al2DIcEv8bAkBNw= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1746099851879867.5513645308275; Thu, 1 May 2025 04:44:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uASK6-0001Fh-4t; Thu, 01 May 2025 07:43:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uASK3-0001F6-LQ for qemu-devel@nongnu.org; Thu, 01 May 2025 07:43:23 -0400 Received: from mail-ot1-x333.google.com ([2607:f8b0:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uASK2-0003pY-0C for qemu-devel@nongnu.org; Thu, 01 May 2025 07:43:23 -0400 Received: by mail-ot1-x333.google.com with SMTP id 46e09a7af769-72c40235c34so226576a34.3 for ; Thu, 01 May 2025 04:43:20 -0700 (PDT) Received: from ausc-rvsw-c-01-anton.tenstorrent.com ([38.104.49.66]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-731d31cb976sm62964a34.28.2025.05.01.04.43.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 May 2025 04:43:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tenstorrent.com; s=google; t=1746099800; x=1746704600; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Vt0jVrSyerxshL5eCuQqtXgeeRWNi9BNM7IDf17MV90=; b=O6DHIf40nvjl4R0m0kbWhg1GerCRGC/qnTCNzrh1osBgSF6UuZlkHkPrTpMZF/PEC7 cF+J9H57bTBBUMbkiIH8RzRqMPQk2Xt2avLHK5B6CKJD9iGFh5WUxl46mbqFuKb6AFPM TWuIqHkIBqjzQJeYCkDjLGZCJaRJvwvi7s8LehOF6l7DobDjBPhdVxaJLJoqLJRF/rhf AvyVV58VLJ00y9XdGJLd2yhxtXdj5wo1heXJYcFgtjzaMuKyMZWGOWcjH6vEMbFpqyzu QQgnaJn0/pgPM16GVaH6Lu4GNKN8bQgJFLkUN+7sh6GAggVPwedNQIPWLAasjL3eJDfv gedQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746099800; x=1746704600; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Vt0jVrSyerxshL5eCuQqtXgeeRWNi9BNM7IDf17MV90=; b=WFyJMLNrwQxzraU5++PJnUy+OmzeImJbi5j7aGq0TrDwnsfW+a4pECpY1BLd3q9uC2 9LXHzp45lTT/JdPHhHY1YrliKcrdgcYqb7rvkoIm0gHx1288twjSlleJ4uGx7Ft2TAXA TFIuBqMvoJRzH3DrADSjM/TO2GSqPPWVJqHgKa2XvIPjteEiDHX/wfuKUNG/GIEAEpCA mIp2Ll9duqNgckAUfyR2keHXB6e7RO3FXlC9t3xK0U8Ax4L64UDJPUqWT3fwb5qfUkL7 FV2hxJe0mlTMbQ0uD+24HlCSeTcMJOHUjYJSkA1S8rYGpfPFReduBiD1TfnugTPkLIhV 7pQw== X-Forwarded-Encrypted: i=1; AJvYcCU97r0REDtaF6e8fWGz0Qe6Y/LE4ZaYVCB8iQ2gfoWrD+f8wBtag8v2bdycK5qqFRUwXqObqBncdpKP@nongnu.org X-Gm-Message-State: AOJu0YwHZA+A2BZQs7hZ583y+NxjcZXWwDI1+4myQyryuGkqjjITjQcw +q93dv7QO4awdmbE+ZkFGPUkzvM7egFNxMkW7+csHziAtSSQQOFgN+7WUClBx04= X-Gm-Gg: ASbGncvH9DOzkdHikDnT/1H3RjDez7UYWxqC5u53Oi3tp3Fz1saLQ0PsAh5j1ZgsvEf kgpLn3WitH5fs27Quivv26DVkwDe7N+nWqfyxr3GLOF8O5LSKnbsEr8FzdldedDctOksu8LXf/j DFhKAk8vgHaAjoD5+2V11WSb21TG0a6+FfEGhQzyV8ETl8XtoQTQuRA58IzSZpcjdy6beOzz8Sy 2HyInSdv31TpNUXPOsdE/sxBithHRAfHZkuhXECGDV2Oru6BPbIFBD0fS3rl6Qzli8NrGSZKtLs efxSAFlS0W3DqopIyFZeFnLPHxPjJdPUtXcOYHgokzJ2UfhB2cdGZhGiQchCLgvePiM5nZqHEYU = X-Google-Smtp-Source: AGHT+IELqpAryeCKVABW5WXiDDONm9PRkn8Yyo1JcI2yisPFUnKadySjl8th6sSglcz6avqsSLVU1A== X-Received: by 2002:a05:6830:670f:b0:72b:a020:a2c0 with SMTP id 46e09a7af769-731ccc8d4c7mr1580942a34.17.1746099799749; Thu, 01 May 2025 04:43:19 -0700 (PDT) From: Anton Blanchard To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: Anton Blanchard , Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei Subject: [PATCH v2] target/riscv: Fix fcvt.s.bf16 NaN box checking Date: Thu, 1 May 2025 11:42:53 +0000 Message-Id: <20250501114253.594887-1-antonb@tenstorrent.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::333; envelope-from=antonb@tenstorrent.com; helo=mail-ot1-x333.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @tenstorrent.com) X-ZM-MESSAGEID: 1746099853888019100 Content-Type: text/plain; charset="utf-8" fcvt.s.bf16 uses the FP16 check_nanbox_h() which returns an FP16 quiet NaN. Add check_nanbox_bf16() which returns a BF16 quiet NaN. Signed-off-by: Anton Blanchard Acked-by: Alistair Francis --- target/riscv/fpu_helper.c | 2 +- target/riscv/internals.h | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/target/riscv/fpu_helper.c b/target/riscv/fpu_helper.c index 91b1a56d10..31c17399fc 100644 --- a/target/riscv/fpu_helper.c +++ b/target/riscv/fpu_helper.c @@ -756,6 +756,6 @@ uint64_t helper_fcvt_bf16_s(CPURISCVState *env, uint64_= t rs1) =20 uint64_t helper_fcvt_s_bf16(CPURISCVState *env, uint64_t rs1) { - float16 frs1 =3D check_nanbox_h(env, rs1); + float16 frs1 =3D check_nanbox_bf16(env, rs1); return nanbox_s(env, bfloat16_to_float32(frs1, &env->fp_status)); } diff --git a/target/riscv/internals.h b/target/riscv/internals.h index 213aff31d8..794c81bf7c 100644 --- a/target/riscv/internals.h +++ b/target/riscv/internals.h @@ -142,6 +142,22 @@ static inline float16 check_nanbox_h(CPURISCVState *en= v, uint64_t f) } } =20 +static inline float16 check_nanbox_bf16(CPURISCVState *env, uint64_t f) +{ + /* Disable nanbox check when enable zfinx */ + if (env_archcpu(env)->cfg.ext_zfinx) { + return (uint16_t)f; + } + + uint64_t mask =3D MAKE_64BIT_MASK(16, 48); + + if (likely((f & mask) =3D=3D mask)) { + return (uint16_t)f; + } else { + return 0x7FC0u; /* default qnan */ + } +} + #ifndef CONFIG_USER_ONLY /* Our implementation of SysemuCPUOps::has_work */ bool riscv_cpu_has_work(CPUState *cs); --=20 2.34.1