* sll now works for all arguments.

This commit is contained in:
Abdulaziz Ghuloum 2007-09-13 00:47:41 -04:00
parent 3247c0641d
commit 6b1860af65
2 changed files with 37 additions and 2 deletions

Binary file not shown.

View File

@ -1148,6 +1148,19 @@ copy_bits_shifting_right(unsigned int* src, unsigned int* dst, int n, int m){
dst[n-1] = carry;
}
static void
copy_bits_shifting_left(unsigned int* src, unsigned int* dst, int n, int m){
unsigned int carry = 0;
int i;
for(i=0; i<n; i++){
unsigned int b = src[i];
dst[i] = (b << m) | carry;
carry = b >> (32-m);
}
dst[n] = carry;
}
@ -1246,8 +1259,30 @@ ikrt_fixnum_shift_left(ikp x, ikp y, ikpcb* pcb){
ikp
ikrt_bignum_shift_left(ikp x, ikp y, ikpcb* pcb){
fprintf(stderr, "bignum_shift_left is not supported yet\n");
exit(-1);
int m = unfix(y);
ikp fst = ref(x, -vector_tag);
int n = ((unsigned int) fst) >> bignum_length_shift;
int whole_limb_shift = m >> 5; /* FIXME: 5 are the bits in 32-bit num */
int bit_shift = m & 31;
if(bit_shift == 0){
int limb_count = n + whole_limb_shift;
ikp r = ik_alloc(pcb, align(disp_bignum_data + limb_count * wordsize));
unsigned int* s = (unsigned int*)(r+disp_bignum_data);
bzero(s, whole_limb_shift*wordsize);
memcpy(s+whole_limb_shift, x+off_bignum_data, n*wordsize);
return normalize_bignum(limb_count, (unsigned int)fst & bignum_sign_mask, r);
} else {
int limb_count = n + whole_limb_shift + 1;
ikp r = ik_alloc(pcb, align(disp_bignum_data + limb_count * wordsize));
unsigned int* s = (unsigned int*)(r+disp_bignum_data);
bzero(s, whole_limb_shift*wordsize);
copy_bits_shifting_left(
(unsigned int*)(x+off_bignum_data),
s+whole_limb_shift,
n,
bit_shift);
return normalize_bignum(limb_count, (unsigned int)fst & bignum_sign_mask, r);
}
}