Marco Bodrato <bodr...@mail.dm.unipi.it> writes: > static mp_size_t > mpn_set_str_bits (mp_ptr rp, const unsigned char *sp, size_t sn, > unsigned bits) > { > mp_size_t rn; > mp_limb_t limb; > unsigned shift; > > for (limb = 0, rn = 0, shift = 0; sn-- > 0; ) > { > limb |= (mp_limb_t) sp[sn] << shift; > shift += bits; > if (shift >= GMP_LIMB_BITS) > { > shift -= GMP_LIMB_BITS; > rp[rn++] = limb; > /* Next line is correct also if shift == 0, > bits == 8, and mp_limb_t == unsigned char. */ > limb = (unsigned int) sp[sn] >> (bits - shift); > } > } > if (limb != 0) > rp[rn++] = limb; > else > rn = mpn_normalized_size (rp, rn); > return rn; > } > > It seems simple enough. Any further comment?
Looks nice! Regards, /Niels -- Niels Möller. PGP-encrypted email is preferred. Keyid 368C6677. Internet email is subject to wholesale government surveillance. _______________________________________________ gmp-devel mailing list gmp-devel@gmplib.org https://gmplib.org/mailman/listinfo/gmp-devel