This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] real.c IBM 128-bit extended format support
- From: David Edelsohn <dje at watson dot ibm dot com>
- To: Richard Henderson <rth at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 23 Sep 2002 14:49:33 -0400
- Subject: [PATCH] real.c IBM 128-bit extended format support
The appended patch is a first stab at adding IBM 128-bit extended
support to the new real.c infrastructure.
Thanks, David
* real.h (ibm_extended_format): Declare.
* real.c (encode_ibm_extended, decode_ibm_extended): New
functions.
Index: real.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/real.h,v
retrieving revision 1.52
diff -c -p -r1.52 real.h
*** real.h 21 Sep 2002 16:10:29 -0000 1.52
--- real.h 23 Sep 2002 18:47:05 -0000
*************** extern const struct real_format ieee_dou
*** 216,221 ****
--- 216,222 ----
extern const struct real_format ieee_extended_motorola_format;
extern const struct real_format ieee_extended_intel_96_format;
extern const struct real_format ieee_extended_intel_128_format;
+ extern const struct real_format ibm_extended_format;
extern const struct real_format ieee_quad_format;
extern const struct real_format vax_f_format;
extern const struct real_format vax_d_format;
Index: real.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/real.c,v
retrieving revision 1.91
diff -c -p -r1.91 real.c
*** real.c 23 Sep 2002 11:26:40 -0000 1.91
--- real.c 23 Sep 2002 18:47:05 -0000
*************** const struct real_format ieee_extended_i
*** 2951,2956 ****
--- 2951,3043 ----
};
+ /* IBM 128-bit extended precision format: a pair of IEEE double precision
+ numbers whose sum is equal to the extended precision value. The number
+ with greater magnitude is first. This format has the same magnitude
+ range as an IEEE double precision value, but effectively 106 bits of
+ significand precision. Infinity and NaN are represented by their IEEE
+ double precision value stored in the first number, the second number is
+ ignored. */
+
+ static void encode_ibm_extended PARAMS ((const struct real_format *fmt,
+ long *, const REAL_VALUE_TYPE *));
+ static void decode_ibm_extended PARAMS ((const struct real_format *,
+ REAL_VALUE_TYPE *, const long *));
+
+ static void
+ encode_ibm_extended (fmt, buf, r)
+ const struct real_format *fmt ATTRIBUTE_UNUSED;
+ long *buf;
+ const REAL_VALUE_TYPE *r;
+ {
+ REAL_VALUE_TYPE t, u, v;
+
+ switch (r->class)
+ {
+ case rvc_zero:
+ buf[0] = r->sign << 31;
+ buf[1] = 0;
+ buf[2] = r->sign << 31;
+ buf[3] = 0;
+ break;
+
+ case rvc_inf:
+ case rvc_nan:
+ encode_ieee_double (&ieee_double_format, &buf[0], r);
+ buf[2] = 0;
+ buf[3] = 0;
+ return;
+
+ case rvc_normal:
+ memcpy (&t, r, sizeof (*r));
+ memcpy (&u, r, sizeof (*r));
+ clear_significand_below (&t, SIGNIFICAND_BITS - 106);
+ clear_significand_below (&u, SIGNIFICAND_BITS - 53);
+ do_add (&v, &t, &u, 1);
+
+ encode_ieee_double (&ieee_double_format, &buf[0], &u);
+ encode_ieee_double (&ieee_double_format, &buf[2], &v);
+ break;
+
+ default:
+ abort ();
+ }
+ }
+
+ static void
+ decode_ibm_extended (fmt, r, buf)
+ const struct real_format *fmt ATTRIBUTE_UNUSED;
+ REAL_VALUE_TYPE *r;
+ const long *buf;
+ {
+ REAL_VALUE_TYPE u, v;
+
+ decode_ieee_double (&ieee_double_format, &u, &buf[0]);
+ decode_ieee_double (&ieee_double_format, &v, &buf[2]);
+
+ if (u.class == rvc_inf || u.class == rvc_nan)
+ memcpy (r, &u, sizeof (*r));
+ else
+ do_add (r, &u, &v, 0);
+ }
+
+ const struct real_format ibm_extended_format =
+ {
+ encode_ibm_extended,
+ decode_ibm_extended,
+ 2,
+ 1,
+ 106, /* 53 + 53 */
+ -1021,
+ 1024,
+ true,
+ true,
+ true,
+ true,
+ true
+ };
+
+
/* IEEE quad precision format. */
static void encode_ieee_quad PARAMS ((const struct real_format *fmt,