Page 233 - ARM 64 Bit Assembly Language
P. 233
Integer mathematics 221
342 rt = bigint_negate(rt);
343 bigint_free(tmp);
344 }
345 /* make sure the left operand is not negative */
346 if (l->blks[l->size-1] & ((bigchunk)1<<(BITSPERCHUNK-1))) {
347 negative ^= 1; /* track sign of result */
348 tmp = lt;
349 lt = bigint_negate(lt);
350 bigint_free(tmp);
351 }
352 /* do shift by chunks */
353 chunkshift = lt->size - rt->size;
354 if (chunkshift > 0) {
355 tmp = rt;
356 rt = bigint_shift_left_chunk(rt, chunkshift);
357 bigint_free(tmp);
358 }
359 /* do remaining shift bit-by-bit */
360 shift = 0;
361 while ((shift < (BITSPERCHUNK-1)) && bigint_lt(rt, lt)) {
362 shift++;
363 tmp = rt;
364 rt = bigint_shift_left(rt, 1);
365 bigint_free(tmp);
366 }
367 shift += (chunkshift * BITSPERCHUNK); /* Calculate total shift */
368 /* loop to shift right and subtract */
369 while (shift >= 0) {
370 tmp=q;
371 q = bigint_shift_left(q, 1);
372 bigint_free(tmp);
373 if (bigint_le(rt, lt)) {
374 /* perform subtraction */
375 tmp = lt;
376 lt = bigint_sub(lt,rt);
377 bigint_free(tmp);
378 /* change lsb from zero to one */
379 q->blks[0] |= 1;
380 }
381 tmp = rt;
382 rt = bigint_shift_right(rt,1);
383 bigint_free(tmp);
384 shift--;
385 }
386 /* correct the sign of the result */
387 if (negative) {
388 tmp = bigint_negate(q);
389 bigint_free(q);
390 q = tmp;