~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to libclamav/tomsfastmath/mul/fp_mul.c

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman
  • Date: 2014-02-01 11:06:17 UTC
  • mfrom: (0.35.37 sid)
  • Revision ID: package-import@ubuntu.com-20140201110617-33h2xxk09dep0ui4
Tags: 0.98.1+dfsg-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Drop build-dep on electric-fence (in Universe)
  - Add apparmor profiles for clamd and freshclam along with maintainer
    script changes
  - Add autopkgtest

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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, tomstdenis@gmail.com
 
9
 */
 
10
#include "bignum_fast.h"
 
11
 
 
12
/* c = a * b */
 
13
void fp_mul(fp_int *A, fp_int *B, fp_int *C)
 
14
{
 
15
    int   y, yy;
 
16
 
 
17
    /* call generic if we're out of range */
 
18
    if (A->used + B->used > FP_SIZE) {
 
19
       fp_mul_comba(A, B, C);
 
20
       return ;
 
21
    }
 
22
 
 
23
     y  = MAX(A->used, B->used);
 
24
     yy = MIN(A->used, B->used);
 
25
    /* pick a comba (unrolled 4/8/16/32 x or rolled) based on the size
 
26
       of the largest input.  We also want to avoid doing excess mults if the 
 
27
       inputs are not close to the next power of two.  That is, for example,
 
28
       if say y=17 then we would do (32-17)^2 = 225 unneeded multiplications 
 
29
    */
 
30
 
 
31
#ifdef TFM_MUL3
 
32
        if (y <= 3) {
 
33
           fp_mul_comba3(A,B,C);
 
34
           return;
 
35
        }
 
36
#endif
 
37
#ifdef TFM_MUL4
 
38
        if (y == 4) {
 
39
           fp_mul_comba4(A,B,C);
 
40
           return;
 
41
        }
 
42
#endif
 
43
#ifdef TFM_MUL6
 
44
        if (y <= 6) {
 
45
           fp_mul_comba6(A,B,C);
 
46
           return;
 
47
        }
 
48
#endif
 
49
#ifdef TFM_MUL7
 
50
        if (y == 7) {
 
51
           fp_mul_comba7(A,B,C);
 
52
           return;
 
53
        }
 
54
#endif
 
55
#ifdef TFM_MUL8
 
56
        if (y == 8) {
 
57
           fp_mul_comba8(A,B,C);
 
58
           return;
 
59
        }
 
60
#endif
 
61
#ifdef TFM_MUL9
 
62
        if (y == 9) {
 
63
           fp_mul_comba9(A,B,C);
 
64
           return;
 
65
        }
 
66
#endif
 
67
#ifdef TFM_MUL12
 
68
        if (y <= 12) {
 
69
           fp_mul_comba12(A,B,C);
 
70
           return;
 
71
        }
 
72
#endif
 
73
#ifdef TFM_MUL17
 
74
        if (y <= 17) {
 
75
           fp_mul_comba17(A,B,C);
 
76
           return;
 
77
        }
 
78
#endif
 
79
 
 
80
#ifdef TFM_SMALL_SET
 
81
        if (y <= 16) {
 
82
           fp_mul_comba_small(A,B,C);
 
83
           return;
 
84
        }
 
85
#endif        
 
86
#if defined(TFM_MUL20)
 
87
        if (y <= 20) {
 
88
           fp_mul_comba20(A,B,C);
 
89
           return;
 
90
        }
 
91
#endif
 
92
#if defined(TFM_MUL24)
 
93
        if (yy >= 16 && y <= 24) {
 
94
           fp_mul_comba24(A,B,C);
 
95
           return;
 
96
        }
 
97
#endif
 
98
#if defined(TFM_MUL28)
 
99
        if (yy >= 20 && y <= 28) {
 
100
           fp_mul_comba28(A,B,C);
 
101
           return;
 
102
        }
 
103
#endif
 
104
#if defined(TFM_MUL32)
 
105
        if (yy >= 24 && y <= 32) {
 
106
           fp_mul_comba32(A,B,C);
 
107
           return;
 
108
        }
 
109
#endif
 
110
#if defined(TFM_MUL48)
 
111
        if (yy >= 40 && y <= 48) {
 
112
           fp_mul_comba48(A,B,C);
 
113
           return;
 
114
        }
 
115
#endif        
 
116
#if defined(TFM_MUL64)
 
117
        if (yy >= 56 && y <= 64) {
 
118
           fp_mul_comba64(A,B,C);
 
119
           return;
 
120
        }
 
121
#endif
 
122
        fp_mul_comba(A,B,C);
 
123
}
 
124
 
 
125
 
 
126
/* $Source: /cvs/libtom/tomsfastmath/src/mul/fp_mul.c,v $ */
 
127
/* $Revision: 1.1 $ */
 
128
/* $Date: 2006/12/31 21:25:53 $ */