Page 236 - ARM 64 Bit Assembly Language
P. 236

224 Chapter 7


               489    else
               490      tmp->blks[i]=l->blks[i-chunks];
               491  }
               492  return tmp;
               493  }
               494
               495  /* Shift left the given about.  This will shift by chunks as much as
               496   it can, then finish off with a sub-chunk shift. */
               497  bigint bigint_shift_left(bigint l, int shamt) {
               498  bigint tmp;
               499  l = bigint_extend(l, l->size+1);
               500  int extra = shamt % BITSPERCHUNK;
               501  shamt = shamt / BITSPERCHUNK;
               502  if (shamt) {
               503    tmp=l;
               504    l = bigint_shift_left_chunk(l, shamt);
               505    bigint_free(tmp);
               506  }
               507  if (extra) {
               508    for (int i = l->size - 1; i > 0; i--) {
               509      l->blks[i] =
               510        (l->blks[i]<<extra) | (l->blks[i-1]>>(BITSPERCHUNK-extra));
               511    }
               512    l->blks[0] = (l->blks[0] << extra);
               513  }
               514  tmp = bigint_trim(l);
               515  bigint_free(l);
               516  return tmp;
               517  }
               518
               519  /* Arithmetic shift right the given about.  This will shift by
               520   chunks as much as it can, then finish off with a sub-chunk
               521   shift. */
               522  bigint bigint_shift_right(bigint l, int shamt) {
               523  bigint tmp;
               524  schunk tmpc;
               525  int extra = shamt % BITSPERCHUNK;
               526  shamt = shamt / BITSPERCHUNK;
               527  l = bigint_shift_right_chunk(l, shamt);
               528  if (extra) {
               529    for (int i = 0; i < l->size-1; i++) {
               530      l->blks[i] =
               531        (l->blks[i]>>extra) | (l->blks[i+1]<<(BITSPERCHUNK-extra));
               532    }
               533    /* do a signed shift of the top chunk */
               534    tmpc = l->blks[l->size - 1];
               535    tmpc >>= extra;
               536    l->blks[l->size - 1] = tmpc;
               537  }
   231   232   233   234   235   236   237   238   239   240   241