From patchwork Tue May 23 20:25:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 685015 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1918304wrt; Tue, 23 May 2023 13:26:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6tYBRIPh5dpr8plRMvp/dRpvLrs9h1QqDPaHs+wFcAH1bPd1/0o2V9X5zPk4/u7yD+jngZ X-Received: by 2002:a05:622a:51:b0:3f6:c202:b011 with SMTP id y17-20020a05622a005100b003f6c202b011mr1115092qtw.3.1684873598600; Tue, 23 May 2023 13:26:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684873598; cv=none; d=google.com; s=arc-20160816; b=MOkIaYQ0scS/Gzslf4tQ9FbcP2Z/9xfMpBjN54rrMykvm/osoMshBO2nHPRuHERUAc m86K1LXKgF041/XO2CY/r/d8Ce3auUHVpoNPuSPCyba1telV1ZAfe54ECh2lm6e/gJlv em4yJGPms1mVlXoXoSMR3WECs6NSDGIsZQXecwsplRWBnlxdiqffBOiqYCnvd8jeDGQg yMSZUEsZeQK7pjrpm1w3NyCZ7W7I9wBtvllwD4Cxgtrj4uFbwvh8XQXfYyBRXIwVfTQ6 U1BKQ1YCSXMoqr0VYv4euFZWnFPq/EulVZRY1WX1U8+h/cbmwxlBQN0z9d6nFaeH2EoU M2Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=ueDoFO4GnmkKV3sF4IOXhhoY9okOdTr1M6goooR55Vo=; b=gkfkNlyn45d8sBBgZJYtOF30yFmK94L0H0vr44APusx1b4mn609V/Dl9MmGl4wAdoi t9es4jKaq/Si6gxohXuU65lnMP1tlj4L5cUfYW5hSCFztShq9DWkpFsWhD8VaKykJsEC kttXUmFkCQnPkGRM7olycW6eiwCEfWQrBABOxa6/DJFS8w2HLOltfdFWTUsX0Yhc5s8+ z/BMkJMpbIABz0OBnSP9lQQGQyeB7JOIg7GLTxqqT9sdDu3LF7GJRWzz5/dvi2bUWrcg M4yXhEe+jUoxJGApQtDUk4XbaE5xMbrPDylb2iydj+AmHxx5iUpnl8eQELm1uZEek8ud Bk/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hj+07bsN; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l13-20020a05622a174d00b003f4f522dd90si5714000qtk.457.2023.05.23.13.26.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 May 2023 13:26:38 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hj+07bsN; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q1YZK-000157-A6; Tue, 23 May 2023 16:25:18 -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 1q1YZI-00014G-4e for qemu-devel@nongnu.org; Tue, 23 May 2023 16:25:16 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q1YZD-00037c-RW for qemu-devel@nongnu.org; Tue, 23 May 2023 16:25:15 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-64d57cd373fso2457122b3a.1 for ; Tue, 23 May 2023 13:25:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684873509; x=1687465509; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ueDoFO4GnmkKV3sF4IOXhhoY9okOdTr1M6goooR55Vo=; b=hj+07bsNcZnjPlEUe9tbjHF4sI4BICMvFcSHS2IsN6IQ90tOSMEi1E+8rwS95D6lqC SvXe91tTUFLthf+pKqB8hpgQ7cCiIp0krJKkd0h1hlnHBP7B3ZKwx2uKLis0yp+ioqDJ ONzPiy3BQ4yN6v+VYOOuCJlLKsr4QW4xiDv/z/CaQMRenTcLa3nrSSFqBClIchUSI6d/ yUfGHdyi0qe6W7yoAEarhD16NcHHUu62blTem7nqQxT1rhwnrVcpnHPLkPwAi9D+3e3W LyMhmVgXAM+akxoH8l36IFv3Fpzqa+zhEA0gdR2/o2P5Xqo7/fOLAbInGstHCDWr4ueG uirw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684873509; x=1687465509; 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=ueDoFO4GnmkKV3sF4IOXhhoY9okOdTr1M6goooR55Vo=; b=GngPEcrr+mGWR3N2ISrBxU41mLh6u6OXHZQlfbaAZkKJOMZlcl47FllmNfe7M4m5p0 eHyM+rDfpwYAPMNYcKU8blm2WMNyi/8heQZOGcAkvwF86At159AId8YnWT/swLptDE8e i/CJ5V8d9452a9aTUKCms7nxuC0PWENM1BQVX5FESICFglccfsN8+X2bQArgV9Myu40K ADy//1dbK4Uc1YRuEfvcuIz5vLklxXwMJV/+BvVIDwGczQs1zsYF5X931rAjjwgQIL4s +5SGY2tHVvbflJG+QN8hL9lAVfkvsBNLjS7X5HYS1J6GhbFZGbQ5eRb++O0ij86+3nTk Vnpg== X-Gm-Message-State: AC+VfDxDnvUINR4080OJbOW6rSQOAQGfUrbn4oG8JOTwIBDz5Z5UiIHE TSjfPd5/Mn6MwZAZIys0Gn5ZX/ji1oTpNlsnO2w= X-Received: by 2002:a05:6a20:12d3:b0:103:3885:3738 with SMTP id v19-20020a056a2012d300b0010338853738mr16777796pzg.19.1684873508964; Tue, 23 May 2023 13:25:08 -0700 (PDT) Received: from stoup.. ([2602:ae:1598:4c01:c13a:d73:4f88:3654]) by smtp.gmail.com with ESMTPSA id u24-20020aa78498000000b0064dbf805ff7sm3178508pfn.72.2023.05.23.13.25.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 13:25:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, qemu-ppc@nongnu.org, balaton@eik.bme.hu Subject: [PATCH] target/ppc: Merge COMPUTE_CLASS and COMPUTE_FPRF Date: Tue, 23 May 2023 13:25:07 -0700 Message-Id: <20230523202507.688859-1-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.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, T_SCC_BODY_TEXT_LINE=-0.01 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Instead of computing an artifical "class" bitmask then converting that to the fprf value, compute the final value from the start. Reorder the tests to check the most likely cases first. Signed-off-by: Richard Henderson Tested-by: Alex Bennée Reviewed-by: Alex Bennée --- target/ppc/fpu_helper.c | 78 ++++++++++++----------------------------- 1 file changed, 22 insertions(+), 56 deletions(-) diff --git a/target/ppc/fpu_helper.c b/target/ppc/fpu_helper.c index a66e16c212..03150a0f10 100644 --- a/target/ppc/fpu_helper.c +++ b/target/ppc/fpu_helper.c @@ -141,62 +141,28 @@ static inline int ppc_float64_get_unbiased_exp(float64 f) return ((f >> 52) & 0x7FF) - 1023; } -/* Classify a floating-point number. */ -enum { - is_normal = 1, - is_zero = 2, - is_denormal = 4, - is_inf = 8, - is_qnan = 16, - is_snan = 32, - is_neg = 64, -}; - -#define COMPUTE_CLASS(tp) \ -static int tp##_classify(tp arg) \ -{ \ - int ret = tp##_is_neg(arg) * is_neg; \ - if (unlikely(tp##_is_any_nan(arg))) { \ - float_status dummy = { }; /* snan_bit_is_one = 0 */ \ - ret |= (tp##_is_signaling_nan(arg, &dummy) \ - ? is_snan : is_qnan); \ - } else if (unlikely(tp##_is_infinity(arg))) { \ - ret |= is_inf; \ - } else if (tp##_is_zero(arg)) { \ - ret |= is_zero; \ - } else if (tp##_is_zero_or_denormal(arg)) { \ - ret |= is_denormal; \ - } else { \ - ret |= is_normal; \ - } \ - return ret; \ -} - -COMPUTE_CLASS(float16) -COMPUTE_CLASS(float32) -COMPUTE_CLASS(float64) -COMPUTE_CLASS(float128) - -static void set_fprf_from_class(CPUPPCState *env, int class) -{ - static const uint8_t fprf[6][2] = { - { 0x04, 0x08 }, /* normalized */ - { 0x02, 0x12 }, /* zero */ - { 0x14, 0x18 }, /* denormalized */ - { 0x05, 0x09 }, /* infinity */ - { 0x11, 0x11 }, /* qnan */ - { 0x00, 0x00 }, /* snan -- flags are undefined */ - }; - bool isneg = class & is_neg; - - env->fpscr &= ~FP_FPRF; - env->fpscr |= fprf[ctz32(class)][isneg] << FPSCR_FPRF; -} - -#define COMPUTE_FPRF(tp) \ -void helper_compute_fprf_##tp(CPUPPCState *env, tp arg) \ -{ \ - set_fprf_from_class(env, tp##_classify(arg)); \ +#define COMPUTE_FPRF(tp) \ +void helper_compute_fprf_##tp(CPUPPCState *env, tp arg) \ +{ \ + bool neg = tp##_is_neg(arg); \ + target_ulong fprf; \ + if (likely(tp##_is_normal(arg))) { \ + fprf = neg ? 0x08 << FPSCR_FPRF : 0x04 << FPSCR_FPRF; \ + } else if (tp##_is_zero(arg)) { \ + fprf = neg ? 0x12 << FPSCR_FPRF : 0x02 << FPSCR_FPRF; \ + } else if (tp##_is_zero_or_denormal(arg)) { \ + fprf = neg ? 0x18 << FPSCR_FPRF : 0x14 << FPSCR_FPRF; \ + } else if (tp##_is_infinity(arg)) { \ + fprf = neg ? 0x09 << FPSCR_FPRF : 0x05 << FPSCR_FPRF; \ + } else { \ + float_status dummy = { }; /* snan_bit_is_one = 0 */ \ + if (tp##_is_signaling_nan(arg, &dummy)) { \ + fprf = 0x00 << FPSCR_FPRF; \ + } else { \ + fprf = 0x11 << FPSCR_FPRF; \ + } \ + } \ + env->fpscr = (env->fpscr & ~FP_FPRF) | fprf; \ } COMPUTE_FPRF(float16)