Left rotate:

Code:

int __alu_rol( alu_t *alu, int num, size_t by )
{
alu_reg_t *N, *T;
alu_bit_t n = {0}, v;
int ret = _alu_check1( alu, num ), tmp = -1;
if ( ret != 0 )
{
alu_error( ret );
return ret;
}
ret = alu_get_reg( alu, &tmp );
if ( ret != 0 )
{
alu_error( ret );
return ret;
}
N = alu->regv + num;
T = alu->regv + tmp;
memcpy( T->part, N->part, alu->buff.perN );
memset( N->part, 0, alu->buff.perN );
T->upto = alu_bit_set_bit( T->part, N->upto.b );
T->last = alu_bit_set_bit( T->part, N->last.b );
T->init = alu_bit_set_bit( T->part, N->init.b );
n = N->upto;
by %= n.b;
v = alu_bit_set_bit( T->part, n.b - by );
while ( v.b > N->init.b )
{
v = alu_bit_dec( v );
n = alu_bit_dec( n );
if ( *(v.S) & v.B )
*(n.S) |= n.B;
}
v = T->upto;
while ( n.b > N->init.b )
{
v = alu_bit_dec( v );
n = alu_bit_dec( n );
if ( *(v.S) & v.B )
*(n.S) |= n.B;
}
(void)alu_rem_reg( alu, tmp );
return 0;
}