request for bit-level manipulation

luc bruant non.deterministic.finite.organism at
Wed Nov 11 00:00:12 CET 2009


I'm using GMP as the basic building block of a small experiment of mine
where genetic algorithms are used to converge to the solution of an
arithmetic problem.
The issue I'm facing is that GMP does not offer easy way to alter a
mp_limb_t* at bit-level. The most important things I would need are :
 * set/reset/flip a single bit (I can do that with some assumptions on
internal data representation but that might be screwed by nails or
endianness so it's not satisfying)
 * insert/remove a signle bit (I can do that with ugly combinations of
shifts and bitmasking but with the same drawbacks as above and an even worse

So I would be extremely grateful if such bit-level manipulation was added to
the low-level interface of GMP in a future release.

Another function that would prove useful in my use case (and possibly in a
lot of others) : "reverse" bit scan. mpn_scan0 and mpn_scan1 start from the
least significant
bits whereas I would need the opposite traversal and am forced to emulate it
using a loop which induces size and time overhead.


Luc Bruant

More information about the gmp-discuss mailing list