summaryrefslogtreecommitdiffstats
path: root/src/H5L.c
Commit message (Expand)AuthorAgeFilesLines
* [svn-r27133] - Add a new attribute function characterstic for format:Mohamad Chaarawi2015-06-011-17/+17
* [svn-r25500] fix HDFFV-8888 - H5Ldelete_by_idx fails on non-existent group name.Mohamad Chaarawi2014-07-311-1/+1
* [svn-r21923] Description:Quincey Koziol2012-02-101-2/+135
* [svn-r21919] Description:Quincey Koziol2012-02-091-51/+51
* [svn-r21133] Description:Quincey Koziol2011-07-201-5/+4
* [svn-r20061] Description:Quincey Koziol2011-02-081-12/+11
* [svn-r19587] Description:Quincey Koziol2010-10-131-2/+20
* [svn-r19461] Purpose: Fix bug 1864Neil Fortner2010-09-211-2/+6
* [svn-r19398] Descriptino:Quincey Koziol2010-09-161-2/+2
* [svn-r19363] When mandatory filter failed to write data chunks, the datasetRaymond Lu2010-09-091-2/+2
* [svn-r19005] Purpose:Mike McGreevy2010-06-151-2/+2
* [svn-r18702] Description:Quincey Koziol2010-05-051-0/+1
* [svn-r18037] Description:Quincey Koziol2009-12-191-1/+1
|\
| * [svn-r18035] Description:Quincey Koziol2009-12-191-1/+1
| * [svn-r18030] Description:Quincey Koziol2009-12-171-1/+1
* | [svn-r17860] Description:Quincey Koziol2009-11-101-3/+3
* | [svn-r16730] Purpose: Fix bug 1539bNeil Fortner2009-04-101-0/+3
* | [svn-r16694] Purpose: Fix bug 1526Neil Fortner2009-04-071-4/+11
* | [svn-r16279] Description:Quincey Koziol2009-01-081-4/+4
* | [svn-r15628] Description:Quincey Koziol2008-09-161-8/+8
* | [svn-r15510] Description:Quincey Koziol2008-08-211-1/+1
* | [svn-r15485] Purpose: Allow library to shut down properly when objects have r...Neil Fortner2008-08-191-5/+5
|/
* [svn-r14288] Maintenance for beta5 release: vesrion number was changed to 1.8...hdf5-1_8_0-beta5Elena Pourmal2007-11-261-0/+2
* [svn-r14285] Description:Quincey Koziol2007-11-241-0/+58
* [svn-r14284] Description:Quincey Koziol2007-11-241-6/+66
* [svn-r14238] Bug fix: It's reported by the CGNS people. When an external lin...Raymond Lu2007-11-051-2/+1
* [svn-r14234] Description:Quincey Koziol2007-11-011-3/+3
* [svn-r14228] Description:Quincey Koziol2007-11-011-56/+1
* [svn-r14224] Description:Quincey Koziol2007-10-301-4/+72
* [svn-r14175] Description:Quincey Koziol2007-10-021-1/+1
* [svn-r14154] Description:Quincey Koziol2007-09-251-29/+15
* [svn-r14117] Description:Quincey Koziol2007-08-281-12/+12
* [svn-r13773] Description:Quincey Koziol2007-05-201-9/+8
* [svn-r13636] Description:Quincey Koziol2007-04-111-45/+112
* [svn-r13588] A support of files bigger than 2GB for STDIO driver. Configure ...Raymond Lu2007-04-041-0/+1
* [svn-r13580] Description:Quincey Koziol2007-04-031-40/+24
* [svn-r13520] Description:Quincey Koziol2007-03-161-2/+112
* [svn-r13475] There's a configure issue linking szip's shared libraries when r...Mike McGreevy2007-03-081-15/+15
* [svn-r13287] Description:Quincey Koziol2007-02-131-202/+57
* [svn-r13272] Description:Quincey Koziol2007-02-081-16/+16
* [svn-r13253] Updated all C and C++ style source code files with the THG copyr...Albert Cheng2007-02-071-2/+3
* [svn-r13128] Description:Quincey Koziol2007-01-091-2/+1
* [svn-r13068] Ran bin/reconfigure. Some of the scripts have been changed or h...James Laird2006-12-181-19/+19
* [svn-r13045] Description:Quincey Koziol2006-12-121-22/+22
* [svn-r13015] Description:Quincey Koziol2006-12-041-3/+3
* [svn-r12963] Description:Quincey Koziol2006-11-211-2/+8
* [svn-r12954] Description:Quincey Koziol2006-11-211-8/+8
* [svn-r12952] Description:Quincey Koziol2006-11-201-1/+0
* [svn-r12940] Description:Quincey Koziol2006-11-171-0/+9
* [svn-r12932] Description:Quincey Koziol2006-11-171-74/+73
lue='private'>private Tcl is a high-level, general-purpose, interpreted, dynamic programming language. It was designed with the goal of being very simple but powerful.
summaryrefslogtreecommitdiffstats
path: root/libtommath/bn_mp_toom_sqr.c
blob: 0a38192ae05a1da7eda399744207d6495795ebcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#include <tommath_private.h>
#ifdef BN_MP_TOOM_SQR_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
 *
 * LibTomMath is a library that provides multiple-precision
 * integer arithmetic as well as number theoretic functionality.
 *
 * The library was designed directly after the MPI library by
 * Michael Fromberger but has been written from scratch with
 * additional optimizations in place.
 *
 * The library is free for all purposes without any express
 * guarantee it works.
 *
 * Tom St Denis, tstdenis82@gmail.com, http://libtom.org
 */

/* squaring using Toom-Cook 3-way algorithm */
int
mp_toom_sqr(mp_int *a, mp_int *b)
{
    mp_int w0, w1, w2, w3, w4, tmp1, a0, a1, a2;
    int res, B;

    /* init temps */
    if ((res = mp_init_multi(&w0, &w1, &w2, &w3, &w4, &a0, &a1, &a2, &tmp1, NULL)) != MP_OKAY) {
       return res;
    }

    /* B */
    B = a->used / 3;

    /* a = a2 * B**2 + a1 * B + a0 */
    if ((res = mp_mod_2d(a, DIGIT_BIT * B, &a0)) != MP_OKAY) {
       goto ERR;
    }

    if ((res = mp_copy(a, &a1)) != MP_OKAY) {
       goto ERR;
    }
    mp_rshd(&a1, B);
    if ((res = mp_mod_2d(&a1, DIGIT_BIT * B, &a1)) != MP_OKAY) {
       goto ERR;
    }

    if ((res = mp_copy(a, &a2)) != MP_OKAY) {
       goto ERR;
    }
    mp_rshd(&a2, B*2);

    /* w0 = a0*a0 */
    if ((res = mp_sqr(&a0, &w0)) != MP_OKAY) {
       goto ERR;
    }

    /* w4 = a2 * a2 */
    if ((res = mp_sqr(&a2, &w4)) != MP_OKAY) {
       goto ERR;
    }

    /* w1 = (a2 + 2(a1 + 2a0))**2 */
    if ((res = mp_mul_2(&a0, &tmp1)) != MP_OKAY) {
       goto ERR;
    }
    if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) {
       goto ERR;
    }
    if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) {
       goto ERR;
    }
    if ((res = mp_add(&tmp1, &a2, &tmp1)) != MP_OKAY) {
       goto ERR;
    }

    if ((res = mp_sqr(&tmp1, &w1)) != MP_OKAY) {
       goto ERR;
    }

    /* w3 = (a0 + 2(a1 + 2a2))**2 */
    if ((res = mp_mul_2(&a2, &tmp1)) != MP_OKAY) {
       goto ERR;
    }
    if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) {
       goto ERR;
    }
    if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) {
       goto ERR;
    }
    if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) {
       goto ERR;
    }

    if ((res = mp_sqr(&tmp1, &w3)) != MP_OKAY) {
       goto ERR;
    }


    /* w2 = (a2 + a1 + a0)**2 */
    if ((res = mp_add(&a2, &a1, &tmp1)) != MP_OKAY) {
       goto ERR;
    }
    if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) {
       goto ERR;
    }
    if ((res = mp_sqr(&tmp1, &w2)) != MP_OKAY) {
       goto ERR;
    }

    /* now solve the matrix

       0  0  0  0  1
       1  2  4  8  16
       1  1  1  1  1
       16 8  4  2  1
       1  0  0  0  0

       using 12 subtractions, 4 shifts, 2 small divisions and 1 small multiplication.
     */

    /* r1 - r4 */
    if ((res = mp_sub(&w1, &w4, &w1)) != MP_OKAY) {
       goto ERR;
    }
    /* r3 - r0 */
    if ((res = mp_sub(&w3, &w0, &w3)) != MP_OKAY) {
       goto ERR;
    }
    /* r1/2 */
    if ((res = mp_div_2(&w1, &w1)) != MP_OKAY) {
       goto ERR;
    }
    /* r3/2 */
    if ((res = mp_div_2(&w3, &w3)) != MP_OKAY) {
       goto ERR;
    }
    /* r2 - r0 - r4 */
    if ((res = mp_sub(&w2, &w0, &w2)) != MP_OKAY) {
       goto ERR;
    }
    if ((res = mp_sub(&w2, &w4, &w2)) != MP_OKAY) {
       goto ERR;
    }
    /* r1 - r2 */
    if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) {
       goto ERR;
    }
    /* r3 - r2 */
    if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) {
       goto ERR;
    }
    /* r1 - 8r0 */
    if ((res = mp_mul_2d(&w0, 3, &tmp1)) != MP_OKAY) {
       goto ERR;
    }
    if ((res = mp_sub(&w1, &tmp1, &w1)) != MP_OKAY) {
       goto ERR;
    }
    /* r3 - 8r4 */
    if ((res = mp_mul_2d(&w4, 3, &tmp1)) != MP_OKAY) {
       goto ERR;
    }
    if ((res = mp_sub(&w3, &tmp1, &w3)) != MP_OKAY) {
       goto ERR;
    }
    /* 3r2 - r1 - r3 */
    if ((res = mp_mul_d(&w2, 3, &w2)) != MP_OKAY) {
       goto ERR;
    }
    if ((res = mp_sub(&w2, &w1, &w2)) != MP_OKAY) {
       goto ERR;
    }
    if ((res = mp_sub(&w2, &w3, &w2)) != MP_OKAY) {
       goto ERR;
    }
    /* r1 - r2 */
    if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) {
       goto ERR;
    }
    /* r3 - r2 */
    if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) {
       goto ERR;
    }
    /* r1/3 */
    if ((res = mp_div_3(&w1, &w1, NULL)) != MP_OKAY) {
       goto ERR;
    }
    /* r3/3 */
    if ((res = mp_div_3(&w3, &w3, NULL)) != MP_OKAY) {
       goto ERR;
    }

    /* at this point shift W[n] by B*n */
    if ((res = mp_lshd(&w1, 1*B)) != MP_OKAY) {
       goto ERR;
    }
    if ((res = mp_lshd(&w2, 2*B)) != MP_OKAY) {
       goto ERR;
    }
    if ((res = mp_lshd(&w3, 3*B)) != MP_OKAY) {
       goto ERR;
    }
    if ((res = mp_lshd(&w4, 4*B)) != MP_OKAY) {
       goto ERR;
    }

    if ((res = mp_add(&w0, &w1, b)) != MP_OKAY) {
       goto ERR;
    }
    if ((res = mp_add(&w2, &w3, &tmp1)) != MP_OKAY) {
       goto ERR;
    }
    if ((res = mp_add(&w4, &tmp1, &tmp1)) != MP_OKAY) {
       goto ERR;
    }
    if ((res = mp_add(&tmp1, b, b)) != MP_OKAY) {
       goto ERR;
    }

ERR:
    mp_clear_multi(&w0, &w1, &w2, &w3, &w4, &a0, &a1, &a2, &tmp1, NULL);
    return res;
}

#endif

/* ref:         $Format:%D$ */
/* git commit:  $Format:%H$ */
/* commit time: $Format:%ai$ */