Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
src/sage/symbolic/ginac/utils.h, pynac-config.h: Eliminate use of PYN…
Browse files Browse the repository at this point in the history
…AC_SIZEOF_LONG, PYNAC_SIZEOF_LONG_LONG
  • Loading branch information
Matthias Koeppe committed Aug 16, 2021
1 parent 0581bac commit 496102d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 25 deletions.
6 changes: 0 additions & 6 deletions src/sage/symbolic/ginac/pynac-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,5 @@
/* Define if you have libgiac */
/* #undef PYNAC_HAVE_LIBGIAC */

/* The size of `long', as computed by sizeof. */
#define PYNAC_SIZEOF_LONG sizeof(long)

/* The size of `long long', as computed by sizeof. */
#define PYNAC_SIZEOF_LONG_LONG sizeof(long long)

/* once: _PYNAC_CONFIG_H */
#endif
21 changes: 2 additions & 19 deletions src/sage/symbolic/ginac/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <cstdint>
#include <string>
#include <functional>
#include <cinttypes>

#include "assertion.h"

Expand Down Expand Up @@ -62,26 +63,8 @@ inline int compare_pointers(const T * a, const T * b)
/** Truncated multiplication with golden ratio, for computing hash values. */
inline unsigned golden_ratio_hash(intptr_t n)
{
// This function works much better when fast arithmetic with at
// least 64 significant bits is available.
#if PYNAC_SIZEOF_LONG >= 8
// So 'long' has 64 bits. Excellent! We prefer it because it might be
// more efficient than 'long long'.
unsigned long l = n * 0x4f1bbcddUL;
uint64_t l = n * UINT64_C(0x4f1bbcddUL);
return (unsigned)l;
#elif PYNAC_SIZEOF_LONG_LONG >= 8
// This requires 'long long' (or an equivalent 64 bit type)---which is,
// unfortunately, not ANSI-C++-compliant.
// (Yet C99 demands it, which is reason for hope.)
unsigned long long l = n * 0x4f1bbcddULL;
return (unsigned)l;
#else
// Without a type with 64 significant bits do the multiplication manually
// by splitting n up into the lower and upper two bytes.
const unsigned n0 = (n & 0x0000ffffU);
const unsigned n1 = (n & 0xffff0000U) >> 16;
return (n0 * 0x0000bcddU) + ((n1 * 0x0000bcddU + n0 * 0x00004f1bU) << 16);
#endif
}

/* Compute the sign of a permutation of a container, with and without an
Expand Down

0 comments on commit 496102d

Please sign in to comment.