[Gmp-commit] /var/hg/gmp-6.2: (tabp): Combine several undefined tabp variable...

mercurial at gmplib.org mercurial at gmplib.org
Sat May 16 22:53:26 UTC 2020


details:   /var/hg/gmp-6.2/rev/54319c37cf1b
changeset: 18027:54319c37cf1b
user:      Torbjorn Granlund <tg at gmplib.org>
date:      Sat May 16 23:43:14 2020 +0200
description:
(tabp): Combine several undefined tabp variable definitions with a macro.

diffstat:

 mpn/generic/hgcd2.c |  19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)

diffs (40 lines):

diff -r aecf0a0b7209 -r 54319c37cf1b mpn/generic/hgcd2.c
--- a/mpn/generic/hgcd2.c	Sat May 16 18:57:43 2020 +0200
+++ b/mpn/generic/hgcd2.c	Sat May 16 23:43:14 2020 +0200
@@ -256,7 +256,15 @@
 #error No table for provided NBITS
 #endif
 
-static const unsigned char *tabp = tab - (1 << (NBITS - 1) << NBITS);
+/* Doing tabp with a #define makes compiler warnings about pointing outside an
+   object go away.  We used to define this as a variable.  It is not clear if
+   e.g.  (vector[100] - 10) + 10 is well- defined as per the C standard;
+   (vector[100] + 10) - 10 surely is and there is no sequence point so the
+   expressions should be equivalent.  To make this safe, we might want to
+   define tabp as a macro with the index as an argument.  Depending on the
+   platform, relocs might allow for assembly-time or linker-time resolution to
+   take place. */
+#define tabp (tab - (1 << (NBITS - 1) << NBITS))
 
 static inline mp_double_limb_t
 div1 (mp_limb_t n0, mp_limb_t d0)
@@ -340,11 +348,18 @@
 291,290,288,287,286,285,283,282,281,280,279,277,276,275,274,273,
 272,270,269,268,267,266,265,264,263,262,261,260,259,258,257,256
 };
-static const unsigned short *tabp = tab - (1 << (NBITS - 1));
 #else
 #error No table for provided NBITS
 #endif
 
+/* Doing tabp with a #define makes compiler warnings about pointing outside an
+   object go away.  We used to define this as a variable.  It is not clear if
+   e.g.  (vector[100] - 10) + 10 is well- defined as per the C standard;
+   (vector[100] + 10) - 10 surely is and there is no sequence point so the
+   expressions should be equivalent.  To make this safe, we might want to
+   define tabp as a macro with the index as an argument.  Depending on the
+   platform, relocs might allow for assembly-time or linker-time resolution to
+   take place. */
 #define tabp (tab - (1 << (NBITS - 1)))
 
 static inline mp_double_limb_t



More information about the gmp-commit mailing list