how smart is the bit shifting?

Torbjorn Granlund
31 Mar 2003 23:40:48 +0200

David Fu <> writes:

  I'm in a situation where I would like to set various limbs in mpz_t
  objects.  However, such access is not exposed in the manual, and
  experiments have been fussy (confirming that it is indeed a "nono" to be
  mucking about directly with _mp_d, _mp_size, and _mp_alloc).
  So, the next best thing would be to use shifts and masks etc. In my case,
  asll such shifts would be multiples of the limbsize (32). So my question
  is the ff:

The limbsize may be 32, or 28, or 64, or whatever.  In particular in
future versions, it will vary with the exact platform.

  if the bitshift is a multiple of the limbsize, does gmp do this smartly?
  I.e., does it do "word/limb-sized" shifts if it can. I.e., why shift 32
  times when pointers to limbs can be changed once?
Shifting by a count that is a multiple of the limb size will be
somewhat faster on many platforms.

  If the answer is "no", then is there a way other than manipulating the
  fields of an mpz_t directly?
No.  But perhaps mpz_import would be useful for your application?