All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tom Musta <tommusta@gmail.com>
To: qemu-devel@nongnu.org
Cc: Tom Musta <tommusta@gmail.com>, qemu-ppc@nongnu.org
Subject: [Qemu-devel] [RFC 11/12] target-ppc: Introduce DFP Post Processor Utilities
Date: Thu, 13 Mar 2014 10:13:07 -0500	[thread overview]
Message-ID: <1394723588-6072-12-git-send-email-tommusta@gmail.com> (raw)
In-Reply-To: <1394723588-6072-1-git-send-email-tommusta@gmail.com>

This patch adds post-processing utilities to the PowerPC Decimal Floating
Point (DFP) helper code.  Post-processors are small routines that execute
after a preliminary DFP result is computed.  They are used, among other
things, to compute status bits.

This patch defines a function type for post processors as well as a
generic routine to run a list (array) of post-processors.  It also
adds several post processors that will be used in subsequent
instructions.

NOTE: This is not the complete set of post processors; it is the minimal
set required to demonstrate the two instructions implemented in this
patch series.

Signed-off-by: Tom Musta <tommusta@gmail.com>
---
 target-ppc/dfp_helper.c |  140 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 140 insertions(+), 0 deletions(-)

diff --git a/target-ppc/dfp_helper.c b/target-ppc/dfp_helper.c
index 3c5988a..a3381ef 100644
--- a/target-ppc/dfp_helper.c
+++ b/target-ppc/dfp_helper.c
@@ -103,9 +103,149 @@ static void ppc_dfp_prepare_decimal128_fra_frb(struct PPC_DFP *dfp, uint64_t *a,
     decimal128ToNumber((decimal128 *)dfp->b64, &dfp->b);
 }
 
+#define FP_FX       (1ull << FPSCR_FX)
+#define FP_FEX      (1ull << FPSCR_FEX)
+#define FP_OX       (1ull << FPSCR_OX)
+#define FP_OE       (1ull << FPSCR_OE)
+#define FP_UX       (1ull << FPSCR_UX)
+#define FP_UE       (1ull << FPSCR_UE)
+#define FP_XX       (1ull << FPSCR_XX)
+#define FP_XE       (1ull << FPSCR_XE)
+#define FP_VX       (1ull << FPSCR_VX)
+#define FP_VXSNAN   (1ull << FPSCR_VXSNAN)
+#define FP_VXISI    (1ull << FPSCR_VXISI)
+#define FP_VE       (1ull << FPSCR_VE)
+#define FP_FI       (1ull << FPSCR_FI)
+
+static void ppc_dfp_set_FPSCR_flag(struct PPC_DFP *dfp, uint64_t flag,
+                uint64_t enabled)
+{
+    dfp->env->fpscr |= (flag | FP_FX);
+    if (dfp->env->fpscr & enabled) {
+        dfp->env->fpscr |= FP_FEX;
+    }
+}
+
+typedef void (*PPC_DFP_PostProc)(struct PPC_DFP *);
+
+static void ppc_dfp_set_FPRF_from_FRT_with_context(struct PPC_DFP *dfp,
+                decContext *context)
+{
+    uint64_t fprf = 0;
+
+    /* construct FPRF */
+    switch (decNumberClass(&dfp->t, context)) {
+    case DEC_CLASS_SNAN:
+        fprf = 0x01;
+        break;
+    case DEC_CLASS_QNAN:
+        fprf = 0x11;
+        break;
+    case DEC_CLASS_NEG_INF:
+        fprf = 0x09;
+        break;
+    case DEC_CLASS_NEG_NORMAL:
+        fprf = 0x08;
+        break;
+    case DEC_CLASS_NEG_SUBNORMAL:
+        fprf = 0x18;
+        break;
+    case DEC_CLASS_NEG_ZERO:
+        fprf = 0x12;
+        break;
+    case DEC_CLASS_POS_ZERO:
+        fprf = 0x02;
+        break;
+    case DEC_CLASS_POS_SUBNORMAL:
+        fprf = 0x14;
+        break;
+    case DEC_CLASS_POS_NORMAL:
+        fprf = 0x04;
+        break;
+    case DEC_CLASS_POS_INF:
+        fprf = 0x05;
+        break;
+    default:
+        assert(0); /* should never get here */
+    }
+    dfp->env->fpscr &= ~(0x1F << 12);
+    dfp->env->fpscr |= (fprf << 12);
+}
+
+static void ppc_dfp_set_FPRF_from_FRT(struct PPC_DFP *dfp)
+{
+    ppc_dfp_set_FPRF_from_FRT_with_context(dfp, &dfp->context);
+}
+
+static void ppc_dfp_check_for_OX(struct PPC_DFP *dfp)
+{
+    if (dfp->context.status & DEC_Overflow) {
+        ppc_dfp_set_FPSCR_flag(dfp, FP_OX, FP_OE);
+    }
+}
+
+static void ppc_dfp_check_for_UX(struct PPC_DFP *dfp)
+{
+    if (dfp->context.status & DEC_Underflow) {
+        ppc_dfp_set_FPSCR_flag(dfp, FP_UX, FP_UE);
+    }
+}
+
+static void ppc_dfp_check_for_XX(struct PPC_DFP *dfp)
+{
+    if (dfp->context.status & DEC_Inexact) {
+        ppc_dfp_set_FPSCR_flag(dfp, FP_XX | FP_FI, FP_XE);
+    }
+}
+
+static void ppc_dfp_check_for_VXSNAN(struct PPC_DFP *dfp)
+{
+    if (dfp->context.status & DEC_Invalid_operation) {
+        if (decNumberIsSNaN(&dfp->a) || decNumberIsSNaN(&dfp->b)) {
+            ppc_dfp_set_FPSCR_flag(dfp, FP_VX | FP_VXSNAN, FP_VE);
+        }
+    }
+}
+
+static void ppc_dfp_check_for_VXISI(struct PPC_DFP *dfp, int testForSameSign)
+{
+    if (dfp->context.status & DEC_Invalid_operation) {
+        if (decNumberIsInfinite(&dfp->a) && decNumberIsInfinite(&dfp->b)) {
+            int same = decNumberClass(&dfp->a, &dfp->context) ==
+                       decNumberClass(&dfp->b, &dfp->context);
+            if ((same && testForSameSign) || (!same && !testForSameSign)) {
+                ppc_dfp_set_FPSCR_flag(dfp, FP_VX | FP_VXISI, FP_VE);
+            }
+        }
+    }
+}
+
+static void ppc_dfp_check_for_VXISI_add(struct PPC_DFP *dfp)
+{
+    ppc_dfp_check_for_VXISI(dfp, 0);
+}
+
+static void ppc_dfp_run_post_processors(struct PPC_DFP *dfp,
+                PPC_DFP_PostProc post_processors[], const size_t n)
+{
+    int i;
+
+    for (i = 0; i < n; i++) {
+        post_processors[i](dfp);
+    }
+}
+
+
 void *_TmpAvoidDefinedButNotUsedWarnings_[] = {
     (void *)ppc_dfp_prepare_decimal64_fra_frb,
     (void *)ppc_dfp_prepare_decimal128_fra_frb,
+    (void *)ppc_dfp_run_post_processors,
+    (void *)ppc_dfp_set_FPRF_from_FRT,
+    (void *)ppc_dfp_check_for_OX,
+    (void *)ppc_dfp_check_for_UX,
+    (void *)ppc_dfp_check_for_XX,
+    (void *)ppc_dfp_check_for_VXSNAN,
+    (void *)ppc_dfp_check_for_VXISI_add,
 };
 
 
-- 
1.7.1

  parent reply	other threads:[~2014-03-13 15:14 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-13 15:12 [Qemu-devel] [RFC 00/12] target-ppc: Decimal Floating Point Tom Musta
2014-03-13 15:12 ` [Qemu-devel] [RFC 01/12] target-ppc: Introduce libdecnumber Code Tom Musta
2014-03-13 15:12 ` [Qemu-devel] [RFC 02/12] target-ppc: Prepare libdecnumber for QEMU include structure Tom Musta
2014-03-13 15:12 ` [Qemu-devel] [RFC 03/12] target-ppc: Modify dconfig.h to Integrate with QEMU Tom Musta
2014-03-13 15:13 ` [Qemu-devel] [RFC 04/12] target-ppc: Change gstdint.h to stdint.h Tom Musta
2014-03-13 15:13 ` [Qemu-devel] [RFC 05/12] target-ppc: Eliminate redundant declarations Tom Musta
2014-03-13 15:13 ` [Qemu-devel] [RFC 06/12] target-ppc: Eliminate Unused Variable in decSetSubnormal Tom Musta
2014-03-13 15:13 ` [Qemu-devel] [RFC 07/12] target-ppc: Enable Building of libdecnumber Tom Musta
2014-03-13 15:13 ` [Qemu-devel] [RFC 08/12] target-ppc: Define FPR Pointer Type for Helpers Tom Musta
2014-03-13 15:13 ` [Qemu-devel] [RFC 09/12] target-ppc: Introduce Translation Macros for DFP Arithmetic Forms Tom Musta
2014-03-13 15:13 ` [Qemu-devel] [RFC 10/12] target-ppc: Introduce DFP Helper Utilities Tom Musta
2014-03-13 15:13 ` Tom Musta [this message]
2014-03-13 15:13 ` [Qemu-devel] [RFC 12/12] target-ppc: Introduce DFP Add Tom Musta
2014-04-11 15:31 ` [Qemu-devel] [Qemu-ppc] [RFC 00/12] target-ppc: Decimal Floating Point Alexander Graf
2014-04-11 16:12   ` Tom Musta
2014-04-11 16:16     ` Alexander Graf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1394723588-6072-12-git-send-email-tommusta@gmail.com \
    --to=tommusta@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.