comparison tomsfastmath/src/bit/fp_div_2.c @ 643:a362b62d38b2 dropbear-tfm

Add tomsfastmath from git rev bfa4582842bc3bab42e4be4aed5703437049502a with Makefile.in renamed
author Matt Johnston <matt@ucc.asn.au>
date Wed, 23 Nov 2011 18:10:20 +0700
parents
children
comparison
equal deleted inserted replaced
642:33fd2f3499d2 643:a362b62d38b2
1 /* TomsFastMath, a fast ISO C bignum library.
2 *
3 * This project is meant to fill in where LibTomMath
4 * falls short. That is speed ;-)
5 *
6 * This project is public domain and free for all purposes.
7 *
8 * Tom St Denis, [email protected]
9 */
10 #include <tfm.h>
11
12 /* b = a/2 */
13 void fp_div_2(fp_int * a, fp_int * b)
14 {
15 int x, oldused;
16
17 oldused = b->used;
18 b->used = a->used;
19 {
20 register fp_digit r, rr, *tmpa, *tmpb;
21
22 /* source alias */
23 tmpa = a->dp + b->used - 1;
24
25 /* dest alias */
26 tmpb = b->dp + b->used - 1;
27
28 /* carry */
29 r = 0;
30 for (x = b->used - 1; x >= 0; x--) {
31 /* get the carry for the next iteration */
32 rr = *tmpa & 1;
33
34 /* shift the current digit, add in carry and store */
35 *tmpb-- = (*tmpa-- >> 1) | (r << (DIGIT_BIT - 1));
36
37 /* forward carry to next iteration */
38 r = rr;
39 }
40
41 /* zero excess digits */
42 tmpb = b->dp + b->used;
43 for (x = b->used; x < oldused; x++) {
44 *tmpb++ = 0;
45 }
46 }
47 b->sign = a->sign;
48 fp_clamp (b);
49 }
50
51 /* $Source$ */
52 /* $Revision$ */
53 /* $Date$ */