Lines Matching +full:low +full:- +full:pass
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* mpihelp-mul.c - MPI helper functions
18 #include "mpi-internal.h"
100 * Multiply the least significant (size - 1) limbs with a recursive in mul_n()
109 mpi_size_t esize = size - 1; /* even size */ in mul_n()
118 /* Anatolij Alekseevich Karatsuba's divide-and-conquer algorithm. in mul_n()
128 * UV = (B + B )U V + B (U -U )(V -V ) + (B + 1)U V in mul_n()
139 * Put result in upper part of PROD and pass low part of TSPACE in mul_n()
146 * |_(U1-U0)(V0-V1)_| in mul_n()
162 /* Read temporary operands from low part of PROD. in mul_n()
163 * Put result in low part of TSPACE using upper part of TSPACE in mul_n()
176 cy -= in mul_n()
186 * Read temporary operands from low part of PROD. in mul_n()
187 * Put result in low part of TSPACE using upper part of TSPACE in mul_n()
249 * Multiply the least significant (size - 1) limbs with a recursive in mpih_sqr_n()
258 mpi_size_t esize = size - 1; /* even size */ in mpih_sqr_n()
273 * Put result in upper part of PROD and pass low part of TSPACE in mpih_sqr_n()
279 * |_(U1-U0)(U0-U1)_| in mpih_sqr_n()
286 /* Read temporary operands from low part of PROD. in mpih_sqr_n()
287 * Put result in low part of TSPACE using upper part of TSPACE in mpih_sqr_n()
297 cy -= mpihelp_sub_n(prodp + hsize, prodp + hsize, tspace, size); in mpih_sqr_n()
301 * Read temporary operands from low part of PROD. in mpih_sqr_n()
302 * Put result in low part of TSPACE using upper part of TSPACE in mpih_sqr_n()
353 if (!ctx->tspace || ctx->tspace_size < vsize) { in mpihelp_mul_karatsuba_case()
354 if (ctx->tspace) in mpihelp_mul_karatsuba_case()
355 mpi_free_limb_space(ctx->tspace); in mpihelp_mul_karatsuba_case()
356 ctx->tspace = mpi_alloc_limb_space(2 * vsize); in mpihelp_mul_karatsuba_case()
357 if (!ctx->tspace) in mpihelp_mul_karatsuba_case()
358 return -ENOMEM; in mpihelp_mul_karatsuba_case()
359 ctx->tspace_size = vsize; in mpihelp_mul_karatsuba_case()
362 MPN_MUL_N_RECURSE(prodp, up, vp, vsize, ctx->tspace); in mpihelp_mul_karatsuba_case()
366 usize -= vsize; in mpihelp_mul_karatsuba_case()
368 if (!ctx->tp || ctx->tp_size < vsize) { in mpihelp_mul_karatsuba_case()
369 if (ctx->tp) in mpihelp_mul_karatsuba_case()
370 mpi_free_limb_space(ctx->tp); in mpihelp_mul_karatsuba_case()
371 ctx->tp = mpi_alloc_limb_space(2 * vsize); in mpihelp_mul_karatsuba_case()
372 if (!ctx->tp) { in mpihelp_mul_karatsuba_case()
373 if (ctx->tspace) in mpihelp_mul_karatsuba_case()
374 mpi_free_limb_space(ctx->tspace); in mpihelp_mul_karatsuba_case()
375 ctx->tspace = NULL; in mpihelp_mul_karatsuba_case()
376 return -ENOMEM; in mpihelp_mul_karatsuba_case()
378 ctx->tp_size = vsize; in mpihelp_mul_karatsuba_case()
382 MPN_MUL_N_RECURSE(ctx->tp, up, vp, vsize, ctx->tspace); in mpihelp_mul_karatsuba_case()
383 cy = mpihelp_add_n(prodp, prodp, ctx->tp, vsize); in mpihelp_mul_karatsuba_case()
384 mpihelp_add_1(prodp + vsize, ctx->tp + vsize, vsize, in mpihelp_mul_karatsuba_case()
388 usize -= vsize; in mpihelp_mul_karatsuba_case()
395 if (mpihelp_mul(ctx->tspace, vp, vsize, up, usize, &tmp) in mpihelp_mul_karatsuba_case()
397 return -ENOMEM; in mpihelp_mul_karatsuba_case()
399 if (!ctx->next) { in mpihelp_mul_karatsuba_case()
400 ctx->next = kzalloc(sizeof *ctx, GFP_KERNEL); in mpihelp_mul_karatsuba_case()
401 if (!ctx->next) in mpihelp_mul_karatsuba_case()
402 return -ENOMEM; in mpihelp_mul_karatsuba_case()
404 if (mpihelp_mul_karatsuba_case(ctx->tspace, in mpihelp_mul_karatsuba_case()
407 ctx->next) < 0) in mpihelp_mul_karatsuba_case()
408 return -ENOMEM; in mpihelp_mul_karatsuba_case()
411 cy = mpihelp_add_n(prodp, prodp, ctx->tspace, vsize); in mpihelp_mul_karatsuba_case()
412 mpihelp_add_1(prodp + vsize, ctx->tspace + vsize, usize, cy); in mpihelp_mul_karatsuba_case()
422 if (ctx->tp) in mpihelp_release_karatsuba_ctx()
423 mpi_free_limb_space(ctx->tp); in mpihelp_release_karatsuba_ctx()
424 if (ctx->tspace) in mpihelp_release_karatsuba_ctx()
425 mpi_free_limb_space(ctx->tspace); in mpihelp_release_karatsuba_ctx()
426 for (ctx = ctx->next; ctx; ctx = ctx2) { in mpihelp_release_karatsuba_ctx()
427 ctx2 = ctx->next; in mpihelp_release_karatsuba_ctx()
428 if (ctx->tp) in mpihelp_release_karatsuba_ctx()
429 mpi_free_limb_space(ctx->tp); in mpihelp_release_karatsuba_ctx()
430 if (ctx->tspace) in mpihelp_release_karatsuba_ctx()
431 mpi_free_limb_space(ctx->tspace); in mpihelp_release_karatsuba_ctx()
455 mpi_ptr_t prod_endp = prodp + usize + vsize - 1; in mpihelp_mul()
505 return -ENOMEM; in mpihelp_mul()