Bill Allombert on Sat, 20 Aug 2005 11:33:53 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
[patch] lower GMP kernel overhead |
Hello PARI developers, I would like to propose the patch below. This patch can potentially reduce the overhead of the GMP kernel over the native one. The issue is that the GMP kernel always allocate an extra word to store the carry in addii, even if no carry occurs. This patch avoid that when both integers are of one word (the worst case). I don't know if it has any positive (or negative) effect yet. If you have instances when the GMP kernel is slower than the normal kernel, they could be good canditate for a test. Cheers, Bill. (it is a -p1 patch) Index: pari/src/kernel/gmp/mp.c =================================================================== --- pari.orig/src/kernel/gmp/mp.c 2005-08-16 19:53:05.000000000 +0200 +++ pari/src/kernel/gmp/mp.c 2005-08-20 11:21:58.000000000 +0200 @@ -197,6 +197,17 @@ GEN zd; long lz; + if (nx == 1 && ny == 1) + { + ulong s=x[0]+y[0]; + if (s<(ulong)x[0]) + { + GEN y = cgeti(4); + y[1] = evalsigne(1)| evallgefint(4); y[2] = s; y[3]=1; + return y; + } + return utoipos(s); + } if (nx < ny) swapspec(x,y, nx,ny); if (ny == 1) return addsispec(*y,x,nx); lz = nx+3; zd = cgeti(lz);