diff options
| author | Philipp Stephani | 2019-12-23 15:37:49 +0100 |
|---|---|---|
| committer | Philipp Stephani | 2019-12-23 15:37:49 +0100 |
| commit | f8e83d73a259e1809020d47e920a96a1f5803f7a (patch) | |
| tree | ae5f8b17390a1090253025d69672f0eca52c5f28 /src | |
| parent | 0abdb01be6c1adee1f179b1d5f7a9fb4ee670109 (diff) | |
| download | emacs-f8e83d73a259e1809020d47e920a96a1f5803f7a.tar.gz emacs-f8e83d73a259e1809020d47e920a96a1f5803f7a.zip | |
Document and verify that emacs_limb_t doesn’t have padding bits.
This is a useful property when doing further bit-twiddling with the
magnitude array before/after calling extract_big_integer or
make_big_integer. For example, constructing an emacs_limb_t object
using repeated shift-and-add should work as expected, but relies on
the type not having padding bits. Since the C standard already
guarantees that unsigned integers use a pure binary representation,
not having padding bits is enough to guarantee that the type has
unique object representations in the sense of C++’s
std::has_unique_object_representations.
* doc/lispref/internals.texi (Module Values): Document that
emacs_limb_t doesn’t have padding bits.
* src/emacs-module.c: Verify that emacs_limb_t doesn’t have padding
bits.
Diffstat (limited to 'src')
| -rw-r--r-- | src/emacs-module.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c index f372a153ccf..f2e3f627756 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c | |||
| @@ -827,6 +827,13 @@ enum | |||
| 827 | module_bignum_count_max = min (SIZE_MAX, PTRDIFF_MAX) / sizeof (emacs_limb_t) | 827 | module_bignum_count_max = min (SIZE_MAX, PTRDIFF_MAX) / sizeof (emacs_limb_t) |
| 828 | }; | 828 | }; |
| 829 | 829 | ||
| 830 | /* Verify that emacs_limb_t indeed has unique object | ||
| 831 | representations. */ | ||
| 832 | verify (CHAR_BIT == 8); | ||
| 833 | verify ((sizeof (emacs_limb_t) == 4 && EMACS_LIMB_MAX == 0xFFFFFFFF) | ||
| 834 | || (sizeof (emacs_limb_t) == 8 | ||
| 835 | && EMACS_LIMB_MAX == 0xFFFFFFFFFFFFFFFF)); | ||
| 836 | |||
| 830 | static bool | 837 | static bool |
| 831 | module_extract_big_integer (emacs_env *env, emacs_value arg, int *sign, | 838 | module_extract_big_integer (emacs_env *env, emacs_value arg, int *sign, |
| 832 | ptrdiff_t *count, emacs_limb_t *magnitude) | 839 | ptrdiff_t *count, emacs_limb_t *magnitude) |