📄 mode1o.c
字号:
/* Alpha EV5 mpn_modexact_1c_odd -- mpn by limb exact style remainder. cycles/limb EV5: 30.0 EV6: 15.0*//*Copyright 2000, 2001, 2002 Free Software Foundation, Inc.This file is part of the GNU MP Library.The GNU MP Library is free software; you can redistribute it and/or modifyit under the terms of the GNU Lesser General Public License as published bythe Free Software Foundation; either version 2.1 of the License, or (at youroption) any later version.The GNU MP Library is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITYor FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General PublicLicense for more details.You should have received a copy of the GNU Lesser General Public Licensealong with the GNU MP Library; see the file COPYING.LIB. If not, write tothe Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,MA 02111-1307, USA.*/#include "gmp.h"#include "gmp-impl.h"#include "longlong.h"/* modlimb_invert is already faster than invert_limb or a "%", so the modexact style can be used even at size==1. The dependent chain is a subtract (1), mul1 (13) and umulh (15), which would suggest 29 is a lower bound, or maybe the measured 30 is already as good as possible, not sure. For reference, ev6 runs this code at 15 cycles, which is 1 faster than the generic loop at 16. But maybe something better is possible. */mp_limb_tmpn_modexact_1c_odd (mp_srcptr src, mp_size_t size, mp_limb_t d, mp_limb_t h){ mp_limb_t s, x, y, inverse, dummy; mp_limb_t c = 0; mp_size_t i; ASSERT (size >= 1); ASSERT (d & 1); modlimb_invert (inverse, d); i = 0; if (size == 1) { s = src[0]; goto last_step; } do { s = src[i]; x = s - c; c = (x > s); y = x - h; c += (y > x); y *= inverse; umul_ppmm (h, dummy, y, d); } while (++i < size-1); s = src[i]; if (s <= d) { /* With high<=d the final step can be a subtract and addback. If c+h==0 then the addback will restore to l>=0. If c+h==d then will get x==d if s==0, but that's ok per the function definition. */ c += h; x = c - s; if (x > c) x += d; ASSERT (x <= d); return x; } else { /* Can't skip a divide, just do the loop code once more. */ last_step: x = s - c; c = (x > s); y = x - h; c += (y > x); y *= inverse; umul_ppmm (h, dummy, y, d); c += h; ASSERT (c <= d); return c; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -