Go to the documentation of this file.
54 #define BN_ULONG unsigned long
61 #define mul_add(r,a,word,carry) do { \
62 register BN_ULONG high,low; \
64 : "=a"(low),"=d"(high) \
67 asm ("addq %2,%0; adcq %3,%1" \
68 : "+r"(carry),"+d"(high)\
71 asm ("addq %2,%0; adcq %3,%1" \
72 : "+m"(r),"+d"(high) \
78 #define mul(r,a,word,carry) do { \
79 register BN_ULONG high,low; \
81 : "=a"(low),"=d"(high) \
84 asm ("addq %2,%0; adcq %3,%1" \
85 : "+r"(carry),"+d"(high)\
88 (r)=carry, carry=high; \
91 #define sqr(r0,r1,a) \
101 if (num <= 0)
return(c1);
109 ap+=4; rp+=4; num-=4;
113 mul_add(rp[0],ap[0],w,c1);
if (--num==0)
return c1;
114 mul_add(rp[1],ap[1],w,c1);
if (--num==0)
return c1;
115 mul_add(rp[2],ap[2],w,c1);
return c1;
125 if (num <= 0)
return(c1);
129 mul(rp[0],ap[0],w,c1);
130 mul(rp[1],ap[1],w,c1);
131 mul(rp[2],ap[2],w,c1);
132 mul(rp[3],ap[3],w,c1);
133 ap+=4; rp+=4; num-=4;
137 mul(rp[0],ap[0],w,c1);
if (--num == 0)
return c1;
138 mul(rp[1],ap[1],w,c1);
if (--num == 0)
return c1;
139 mul(rp[2],ap[2],w,c1);
158 sqr(r[0],r[1],a[0]);
if (--n == 0)
return;
159 sqr(r[2],r[3],a[1]);
if (--n == 0)
return;
168 :
"=a"(ret),
"=d"(waste)
169 :
"a"(l),
"d"(h),
"g"(d)
178 if (n <= 0)
return 0;
183 "1: movq (%4,%2,8),%0 \n"
184 " adcq (%5,%2,8),%0 \n"
185 " movq %0,(%3,%2,8) \n"
189 :
"=&a"(ret),
"+c"(n),
"=&r"(i)
190 :
"r"(rp),
"r"(ap),
"r"(bp)
201 if (n <= 0)
return 0;
206 "1: movq (%4,%2,8),%0 \n"
207 " sbbq (%5,%2,8),%0 \n"
208 " movq %0,(%3,%2,8) \n"
212 :
"=&a"(ret),
"+c"(n),
"=&r"(i)
213 :
"r"(rp),
"r"(ap),
"r"(bp)
221 #define BN_MASK2 0xffffffffffffffffL
233 if (t1 != t2) c=(t1 < t2);
238 if (t1 != t2) c=(t1 < t2);
243 if (t1 != t2) c=(t1 < t2);
248 if (t1 != t2) c=(t1 < t2);
266 #define mul_add_c(a,b,c0,c1,c2) { \
267 BN_ULONG ta=(a),tb=(b); \
269 t2 = BN_UMULT_HIGH(ta,tb); \
270 c0 += t1; t2 += (c0<t1)?1:0; \
271 c1 += t2; c2 += (c1<t2)?1:0; \
274 #define mul_add_c2(a,b,c0,c1,c2) { \
275 BN_ULONG ta=(a),tb=(b),t0; \
276 t1 = BN_UMULT_HIGH(ta,tb); \
278 t2 = t1+t1; c2 += (t2<t1)?1:0; \
279 t1 = t0+t0; t2 += (t1<t0)?1:0; \
280 c0 += t1; t2 += (c0<t1)?1:0; \
281 c1 += t2; c2 += (c1<t2)?1:0; \
284 #define mul_add_c(a,b,c0,c1,c2) do { \
286 : "=a"(t1),"=d"(t2) \
289 asm ("addq %2,%0; adcq %3,%1" \
290 : "+r"(c0),"+d"(t2) \
293 asm ("addq %2,%0; adcq %3,%1" \
294 : "+r"(c1),"+r"(c2) \
299 #define sqr_add_c(a,i,c0,c1,c2) do { \
301 : "=a"(t1),"=d"(t2) \
304 asm ("addq %2,%0; adcq %3,%1" \
305 : "+r"(c0),"+d"(t2) \
308 asm ("addq %2,%0; adcq %3,%1" \
309 : "+r"(c1),"+r"(c2) \
314 #define mul_add_c2(a,b,c0,c1,c2) do { \
316 : "=a"(t1),"=d"(t2) \
319 asm ("addq %0,%0; adcq %2,%1" \
320 : "+d"(t2),"+r"(c2) \
323 asm ("addq %0,%0; adcq %2,%1" \
324 : "+a"(t1),"+d"(t2) \
327 asm ("addq %2,%0; adcq %3,%1" \
328 : "+r"(c0),"+d"(t2) \
331 asm ("addq %2,%0; adcq %3,%1" \
332 : "+r"(c1),"+r"(c2) \
338 #define sqr_add_c2(a,i,j,c0,c1,c2) \
339 mul_add_c2((a)[i],(a)[j],c0,c1,c2)