Doing fast leftshift

Hans Aberg haberg at math.su.se
Sun Nov 13 13:57:00 CET 2005


On 11 Nov 2005, at 17:29, Décio Luiz Gazzoni Filho wrote:

> Apparently you're trying to do a rotation (i.e. multiplication  
> modulo 2^128 - 1). In that case you can perform a left shift by the  
> desired value (call it r), a logical right shift (i.e. unsigned  
> division) by (128 - r) which is saved in a temporary value, then  
> the bitwise OR of both.

This similar question came up in the context of Haskell:

The traditional C integral types would be better to be replaced by a  
type "binary(k)", which includes modulo 2^k arithmetic, as well as  
different types of binary operations, Boolean, and shifts/rotations.

I do not know if GMP would benefit from adding that. (Somebody must  
want to not only add it, but to maintain it.)

   Hans Aberg




More information about the gmp-discuss mailing list