[goffice] GOQuad: keep one copy of constants only.



commit a8b37cad5b5f17341e684c1e4537cc32e048605a
Author: Morten Welinder <terra gnome org>
Date:   Sun Nov 10 18:28:58 2013 -0500

    GOQuad: keep one copy of constants only.

 ChangeLog              |    5 ++
 goffice/math/go-quad.c |  118 +++++++++++++++++++++++++-----------------------
 2 files changed, 66 insertions(+), 57 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6014dca..0505e18 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2013-11-10  Morten Welinder  <terra gnome org>
+
+       * goffice/math/go-quad.c (pi_hex_digits, ...): Keep one copy only,
+       not one per type.
+
 2013-11-04  Morten Welinder  <terra gnome org>
 
        * goffice/math/go-quad.c (go_quad_pow, go_quad_exp)
diff --git a/goffice/math/go-quad.c b/goffice/math/go-quad.c
index c461f9c..d16bd6f 100644
--- a/goffice/math/go-quad.c
+++ b/goffice/math/go-quad.c
@@ -42,6 +42,8 @@
 
 #ifndef DOUBLE
 
+#define DEFINE_COMMON
+
 #ifdef i386
 #ifdef HAVE_FPU_CONTROL_H
 #include <fpu_control.h>
@@ -68,6 +70,7 @@ typedef unsigned int fpu_control_t __attribute__ ((__mode__ (__HI__)));
 
 #ifdef GOFFICE_WITH_LONG_DOUBLE
 #include "go-quad.c"
+#undef DEFINE_COMMON
 #undef DOUBLE
 #undef SUFFIX
 #undef DOUBLE_MANT_DIG
@@ -102,6 +105,64 @@ static guint SUFFIX(go_quad_depth) = 0;
 
 static DOUBLE SUFFIX(CST);
 
+#ifdef DEFINE_COMMON
+/*
+ * Store constants in a way doesn't depend on the layout of DOUBLE.  We use
+ * ~400 bits of data in the tables below -- that's way more than needed even
+ * for sunos' long double.
+ */
+
+static const guint8 pi_hex_digits[] = {
+       0x03, 0x24, 0x3f, 0x6a, 0x88, 0x85, 0xa3, 0x08,
+       0xd3, 0x13, 0x19, 0x8a, 0x2e, 0x03, 0x70, 0x73,
+       0x44, 0xa4, 0x09, 0x38, 0x22, 0x29, 0x9f, 0x31,
+       0xd0, 0x08, 0x2e, 0xfa, 0x98, 0xec, 0x4e, 0x6c,
+       0x89, 0x45, 0x28, 0x21, 0xe6, 0x38, 0xd0, 0x13,
+       0x77, 0xbe, 0x54, 0x66, 0xcf, 0x34, 0xe9, 0x0c,
+       0x6c, 0xc0, 0xac
+};
+
+static const guint8 e_hex_digits[] = {
+       0x02, 0xb7, 0xe1, 0x51, 0x62, 0x8a, 0xed, 0x2a,
+       0x6a, 0xbf, 0x71, 0x58, 0x80, 0x9c, 0xf4, 0xf3,
+       0xc7, 0x62, 0xe7, 0x16, 0x0f, 0x38, 0xb4, 0xda,
+       0x56, 0xa7, 0x84, 0xd9, 0x04, 0x51, 0x90, 0xcf,
+       0xef, 0x32, 0x4e, 0x77, 0x38, 0x92, 0x6c, 0xfb,
+       0xe5, 0xf4, 0xbf, 0x8d, 0x8d, 0x8c, 0x31, 0xd7,
+       0x63, 0xda, 0x06
+};
+
+static const guint8 ln2_hex_digits[] = {
+       0xb1, 0x72, 0x17, 0xf7, 0xd1, 0xcf, 0x79, 0xab,
+       0xc9, 0xe3, 0xb3, 0x98, 0x03, 0xf2, 0xf6, 0xaf,
+       0x40, 0xf3, 0x43, 0x26, 0x72, 0x98, 0xb6, 0x2d,
+       0x8a, 0x0d, 0x17, 0x5b, 0x8b, 0xaa, 0xfa, 0x2b,
+       0xe7, 0xb8, 0x76, 0x20, 0x6d, 0xeb, 0xac, 0x98,
+       0x55, 0x95, 0x52, 0xfb, 0x4a, 0xfa, 0x1b, 0x10,
+       0xed, 0x2e
+};
+
+static const guint8 sqrt2_hex_digits[] = {
+       0x01, 0x6a, 0x09, 0xe6, 0x67, 0xf3, 0xbc, 0xc9,
+       0x08, 0xb2, 0xfb, 0x13, 0x66, 0xea, 0x95, 0x7d,
+       0x3e, 0x3a, 0xde, 0xc1, 0x75, 0x12, 0x77, 0x50,
+       0x99, 0xda, 0x2f, 0x59, 0x0b, 0x06, 0x67, 0x32,
+       0x2a, 0x95, 0xf9, 0x06, 0x08, 0x75, 0x71, 0x45,
+       0x87, 0x51, 0x63, 0xfc, 0xdf, 0xb9, 0x07, 0xb6,
+       0x72, 0x1e, 0xe9
+};
+
+static const guint8 euler_hex_digits[] = {
+       0x93, 0xc4, 0x67, 0xe3, 0x7d, 0xb0, 0xc7, 0xa4,
+       0xd1, 0xbe, 0x3f, 0x81, 0x01, 0x52, 0xcb, 0x56,
+       0xa1, 0xce, 0xcc, 0x3a, 0xf6, 0x5c, 0xc0, 0x19,
+       0x0c, 0x03, 0xdf, 0x34, 0x70, 0x9a, 0xff, 0xbd,
+       0x8e, 0x4b, 0x59, 0xfa, 0x03, 0xa9, 0xf0, 0xee,
+       0xd0, 0x64, 0x9c, 0xcb, 0x62, 0x10, 0x57, 0xd1,
+       0x10, 0x56
+};
+#endif
+
 /**
  * go_quad_start: (skip)
  *
@@ -146,63 +207,6 @@ SUFFIX(go_quad_start) (void)
 #endif
 
        if (first) {
-               /*
-                * Calculate constants in a way doesn't depend on the
-                * layout of DOUBLE.  We use ~400 bits of data in the
-                * tables below -- that's way more than needed even
-                * for sunos' long double.
-                */
-
-               static const guint8 pi_hex_digits[] = {
-                       0x03, 0x24, 0x3f, 0x6a, 0x88, 0x85, 0xa3, 0x08,
-                       0xd3, 0x13, 0x19, 0x8a, 0x2e, 0x03, 0x70, 0x73,
-                       0x44, 0xa4, 0x09, 0x38, 0x22, 0x29, 0x9f, 0x31,
-                       0xd0, 0x08, 0x2e, 0xfa, 0x98, 0xec, 0x4e, 0x6c,
-                       0x89, 0x45, 0x28, 0x21, 0xe6, 0x38, 0xd0, 0x13,
-                       0x77, 0xbe, 0x54, 0x66, 0xcf, 0x34, 0xe9, 0x0c,
-                       0x6c, 0xc0, 0xac
-               };
-
-               static const guint8 e_hex_digits[] = {
-                       0x02, 0xb7, 0xe1, 0x51, 0x62, 0x8a, 0xed, 0x2a,
-                       0x6a, 0xbf, 0x71, 0x58, 0x80, 0x9c, 0xf4, 0xf3,
-                       0xc7, 0x62, 0xe7, 0x16, 0x0f, 0x38, 0xb4, 0xda,
-                       0x56, 0xa7, 0x84, 0xd9, 0x04, 0x51, 0x90, 0xcf,
-                       0xef, 0x32, 0x4e, 0x77, 0x38, 0x92, 0x6c, 0xfb,
-                       0xe5, 0xf4, 0xbf, 0x8d, 0x8d, 0x8c, 0x31, 0xd7,
-                       0x63, 0xda, 0x06
-               };
-
-               static const guint8 ln2_hex_digits[] = {
-                       0xb1, 0x72, 0x17, 0xf7, 0xd1, 0xcf, 0x79, 0xab,
-                       0xc9, 0xe3, 0xb3, 0x98, 0x03, 0xf2, 0xf6, 0xaf,
-                       0x40, 0xf3, 0x43, 0x26, 0x72, 0x98, 0xb6, 0x2d,
-                       0x8a, 0x0d, 0x17, 0x5b, 0x8b, 0xaa, 0xfa, 0x2b,
-                       0xe7, 0xb8, 0x76, 0x20, 0x6d, 0xeb, 0xac, 0x98,
-                       0x55, 0x95, 0x52, 0xfb, 0x4a, 0xfa, 0x1b, 0x10,
-                       0xed, 0x2e
-               };
-
-               static const guint8 sqrt2_hex_digits[] = {
-                       0x01, 0x6a, 0x09, 0xe6, 0x67, 0xf3, 0xbc, 0xc9,
-                       0x08, 0xb2, 0xfb, 0x13, 0x66, 0xea, 0x95, 0x7d,
-                       0x3e, 0x3a, 0xde, 0xc1, 0x75, 0x12, 0x77, 0x50,
-                       0x99, 0xda, 0x2f, 0x59, 0x0b, 0x06, 0x67, 0x32,
-                       0x2a, 0x95, 0xf9, 0x06, 0x08, 0x75, 0x71, 0x45,
-                       0x87, 0x51, 0x63, 0xfc, 0xdf, 0xb9, 0x07, 0xb6,
-                       0x72, 0x1e, 0xe9
-               };
-
-               static const guint8 euler_hex_digits[] = {
-                       0x93, 0xc4, 0x67, 0xe3, 0x7d, 0xb0, 0xc7, 0xa4,
-                       0xd1, 0xbe, 0x3f, 0x81, 0x01, 0x52, 0xcb, 0x56,
-                       0xa1, 0xce, 0xcc, 0x3a, 0xf6, 0x5c, 0xc0, 0x19,
-                       0x0c, 0x03, 0xdf, 0x34, 0x70, 0x9a, 0xff, 0xbd,
-                       0x8e, 0x4b, 0x59, 0xfa, 0x03, 0xa9, 0xf0, 0xee,
-                       0xd0, 0x64, 0x9c, 0xcb, 0x62, 0x10, 0x57, 0xd1,
-                       0x10, 0x56
-               };
-
                first = FALSE;
                SUFFIX(CST) = 1 + SUFFIX(ldexp) (1.0, (DOUBLE_MANT_DIG + 1) / 2);
                SUFFIX(go_quad_constant8) ((QUAD *)&SUFFIX(go_quad_pi),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]